Package org.apache.mahout.math

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


  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

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

    int iteration = 0;
   
    boolean converged = false;
    double oldLL = 1;
    while (!converged && (iteration < MAX_ITER)) {
      nextGamma.assign(state.getTopicSmoothing()); // nG := alpha, for all topics
     
      int mapping = 0;
      for (Iterator<Vector.Element> iter = wordCounts.iterateNonZero(); iter.hasNext();) {
        Vector.Element e = iter.next();
        int word = e.index();
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

      int i = 0;
      Vector pdfs = new DenseVector(models.size());
      for (Cluster 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

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

    int iteration = 0;
   
    boolean converged = false;
    double oldLL = 1.0;
    while (!converged && iteration < MAX_ITER) {
      nextGamma.assign(state.getTopicSmoothing()); // nG := alpha, for all topics
     
      int mapping = 0;
      for (Iterator<Vector.Element> iter = wordCounts.iterateNonZero(); iter.hasNext();) {
        Vector.Element e = iter.next();
        int word = e.index();
View Full Code Here

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

   * For the distributed case, the best guess at a useful initialization state for Lanczos we'll chose to be
   * uniform over all input dimensions, L_2 normalized.
   */
  public Vector getInitialVector(VectorIterable corpus) {
    Vector initialVector = new DenseVector(corpus.numCols());
    initialVector.assign(1.0 / Math.sqrt(corpus.numCols()));
    return initialVector;
  }

  public LanczosState runJob(Configuration originalConfig,
                             LanczosState state,
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.