Package org.apache.mahout.matrix

Examples of org.apache.mahout.matrix.SparseVector$AllIterator


  }

  @Override
  public void setExpectations(String field, int numTerms, boolean storeOffsets, boolean storePositions) {
    this.field = field;
    vector = new SparseVector(termInfo.totalTerms(field));
    this.numTerms = numTerms;
  }
View Full Code Here


   * Generate random document vector
   * @param numWords int number of words in the vocabulary
   * @param numWords E[count] for each word
   */
  private SparseVector generateRandomDoc(int numWords, double sparsity) throws MathException {
    SparseVector v = new SparseVector(numWords,(int)(numWords * sparsity));
    PoissonDistribution dist = new PoissonDistributionImpl(sparsity);
    for (int i = 0; i < numWords; i++) {
      // random integer
      v.set(i,dist.inverseCumulativeProbability(random.nextDouble()) + 1);
    }
    return v;
  }
View Full Code Here

    LDAState state = generateRandomState(100,NUM_TOPICS);
    LDAMapper mapper = new LDAMapper();
    mapper.configure(state);

    for(int i = 0; i < NUM_TESTS; ++i) {
      SparseVector v = generateRandomDoc(100,0.3);
      int myNumWords = numNonZero(v);
      LDAMapper.Context mock = createMock(LDAMapper.Context.class);

      mock.write(isA(IntPairWritable.class),isA(DoubleWritable.class));
      expectLastCall().times(myNumWords * NUM_TOPICS + NUM_TOPICS + 1);
View Full Code Here

  public static List<Vector> getPoints(double[][] raw) {
    List<Vector> points = new ArrayList<Vector>();
    for (int i = 0; i < raw.length; i++) {
      double[] fr = raw[i];
      Vector vec = new SparseVector(String.valueOf(i), fr.length);
      vec.assign(fr);
      points.add(vec);
    }
    return points;
  }
View Full Code Here

      }
      Vector result;
      if (line.startsWith(ARFFModel.ARFF_SPARSE)) {
        line = line.substring(1, line.length() - 1);
        String[] splits = COMMA_PATTERN.split(line);
        result = new SparseVector(model.getLabelSize());
        for (String split : splits) {
          String[] data = SPACE_PATTERN.split(split); // first is index, second is
          int idx = Integer.parseInt(data[0]);
          result.setQuick(idx, model.getValue(data[1], idx));
        }
View Full Code Here

TOP

Related Classes of org.apache.mahout.matrix.SparseVector$AllIterator

Copyright © 2018 www.massapicom. 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.