Package org.apache.mahout.math

Examples of org.apache.mahout.math.Vector.assign()


    for (Model<VectorWritable>[] models : result) {
      g2.setStroke(new BasicStroke(i == 0 ? 3 : 1));
      g2.setColor(colors[Math.min(DisplayDirichlet.colors.length - 1, i--)]);
      for (Model<VectorWritable> m : models) {
        NormalModel mm = (NormalModel) m;
        dv.assign(mm.getStdDev() * 3);
        if (DisplayDirichlet.isSignificant(mm)) {
          DisplayDirichlet.plotEllipse(g2, mm.getMean(), dv);
        }
      }
    }
View Full Code Here


    plotRectangle(g2, new DenseVector(2).assign(2), dv);
    plotRectangle(g2, new DenseVector(2).assign(-2), dv);
   
    // plot the sample data
    g2.setColor(Color.DARK_GRAY);
    dv.assign(0.03);
    for (VectorWritable v : sampleData) {
      plotRectangle(g2, v.get(), dv);
    }
  }
 
View Full Code Here

    assertEquals(m, mtt, 1.0e-9);
  }

  public void testMatrixTimesVector() throws Exception {
    Vector v = new RandomAccessSparseVector(50);
    v.assign(1.0);
    Matrix m = SolverTest.randomSequentialAccessSparseMatrix(100, 90, 50, 20, 1.0);
    DistributedRowMatrix dm = randomDistributedMatrix(100, 90, 50, 20, 1.0, false);

    Vector expected = m.times(v);
    Vector actual = dm.times(v);
View Full Code Here

    assertEquals(0.0, expected.getDistanceSquared(actual), 1.0e-9);
  }

  public void testMatrixTimesSquaredVector() throws Exception {
    Vector v = new RandomAccessSparseVector(50);
    v.assign(1.0);
    Matrix m = SolverTest.randomSequentialAccessSparseMatrix(100, 90, 50, 20, 1.0);
    DistributedRowMatrix dm = randomDistributedMatrix(100, 90, 50, 20, 1.0, false);

    Vector expected = m.timesSquared(v);
    Vector actual = dm.timesSquared(v);
View Full Code Here

      double[] m = new double[card];
      for (int j = 0; j < card; j++) {
        m[j] = UncommonDistributions.rNorm(0, 1);
      }
      Vector mean = prototype.like();
      mean.assign(m);
      result[i] = new SampledNormalModel(mean, 1);
    }
    return result;
  }
 
View Full Code Here

    double docTotal = wordCounts.zSum();
    int docLength = wordCounts.size(); // cardinality of document vectors
   
    // initialize variational approximation to p(z|doc)
    Vector gamma = new DenseVector(state.numTopics);
    gamma.assign(state.topicSmoothing + docTotal / state.numTopics);
    Vector nextGamma = new DenseVector(state.numTopics);
    createPhiMatrix(docLength);
   
    Vector digammaGamma = digammaGamma(gamma);
   
View Full Code Here

    return phi;
  }
 
  private static Vector digamma(Vector v) {
    Vector digammaGamma = new DenseVector(v.size());
    digammaGamma.assign(v, new BinaryFunction() {
      @Override
      public double apply(double unused, double g) {
        return digamma(g);
      }
    });
View Full Code Here

      if (max < p) {
        max = p;
      }
    }
    // normalize the probabilities by largest observed value
    pi.assign(new TimesFunction(), 1.0 / max);
    return pi;
  }
}
View Full Code Here

  static List<Vector> generateBasis(int numDimensions, int numProjections) {
    final DoubleFunction random = Functions.random();
    List<Vector> basisVectors = Lists.newArrayList();
    for (int i = 0; i < numProjections; ++i) {
      Vector basisVector = new DenseVector(numDimensions);
      basisVector.assign(random);
      basisVector.normalize();
      basisVectors.add(basisVector);
    }
    return  basisVectors;
  }
View Full Code Here

    } else {
      int i = 0;
      for (Model<VectorWritable> model : models) {
        pdfs.set(i++, model.pdf(new VectorWritable(instance)));
      }
      return pdfs.assign(new TimesFunction(), 1.0 / pdfs.zSum());
    }
  }

  @Override
  public double classifyScalar(Vector instance) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.