Examples of RandomAccessSparseVector


Examples of org.apache.mahout.math.RandomAccessSparseVector

    DistributedRowMatrix mtt = mt.transpose();
    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

Examples of org.apache.mahout.math.RandomAccessSparseVector

    Vector actual = dm.times(v);
    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

Examples of org.apache.mahout.math.RandomAccessSparseVector

    compare(distanceMeasure, vectors);

    vectors = new Vector[4];
   
    vectors[0] = new RandomAccessSparseVector(5);
    vectors[0].setQuick(0, 1);
    vectors[0].setQuick(3, 1);
    vectors[0].setQuick(4, 1);

    vectors[1] = new RandomAccessSparseVector(5);
    vectors[1].setQuick(0, 2);
    vectors[1].setQuick(3, 2);
    vectors[1].setQuick(4, 2);

    vectors[2] = new RandomAccessSparseVector(5);
    vectors[2].setQuick(0, 6);
    vectors[2].setQuick(3, 6);
    vectors[2].setQuick(4, 6);
   
    vectors[3] = new RandomAccessSparseVector(5);

    compare(distanceMeasure, vectors);
  }
View Full Code Here

Examples of org.apache.mahout.math.RandomAccessSparseVector

   * Generate random document vector
   * @param numWords int number of words in the vocabulary
   * @param numWords E[count] for each word
   */
  private RandomAccessSparseVector generateRandomDoc(int numWords, double sparsity) throws MathException {
    RandomAccessSparseVector v = new RandomAccessSparseVector(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

Examples of org.apache.mahout.math.RandomAccessSparseVector

    LDAState state = generateRandomState(100,NUM_TOPICS);
    LDAMapper mapper = new LDAMapper();
    mapper.configure(state);
    VectorWritable vw = new VectorWritable();
    for(int i = 0; i < NUM_TESTS; ++i) {
      RandomAccessSparseVector 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

Examples of org.apache.mahout.math.RandomAccessSparseVector

    if (!values.hasNext()) {
      return;
    }
    Vector value = values.next().get();
    Iterator<Element> it = value.iterateNonZero();
    Vector vector = new RandomAccessSparseVector(key.toString(), (int) featureCount, value
        .getNumNondefaultElements());
    while (it.hasNext()) {
      Element e = it.next();
      if (!dictionary.containsKey(e.index())) {
        continue;
      }
      long df = dictionary.get(e.index());
      if (df / vectorCount > maxDfPercent) {
        continue;
      }
      if (df < minDf) {
        df = minDf;
      }
      vector.setQuick(e.index(), tfidf.calculate((int) e.get(), (int) df, (int) featureCount,
        (int) vectorCount));
    }
    if (sequentialAccess) {
      vector = new SequentialAccessSparseVector(vector);
    }
View Full Code Here

Examples of org.apache.mahout.math.RandomAccessSparseVector

   *
   * @param center
   *          the center point
   */
  public SoftCluster(Vector center) {
    setCenter(new RandomAccessSparseVector(center));
    this.pointProbSum = 0;
    this.weightedPointTotal = getCenter().like();
  }
View Full Code Here

Examples of org.apache.mahout.math.RandomAccessSparseVector

  public void readFields(DataInput in) throws IOException {
    this.setId(in.readInt());
    converged = in.readBoolean();
    VectorWritable temp = new VectorWritable();
    temp.readFields(in);
    this.setCenter(new RandomAccessSparseVector(temp.get()));
    this.pointProbSum = 0;
    this.weightedPointTotal = getCenter().like();
  }
View Full Code Here

Examples of org.apache.mahout.math.RandomAccessSparseVector

public class MaybePruneRowsMapperTest extends TasteTestCase {

  @Test
  public void testPruning() throws Exception {
    Vector v1 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    v1.set(1, 1);
    v1.set(3, 1);

    Vector v2 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    v2.set(1, 1);
    v2.set(7, 1);

    Vector v3 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    v3.set(1, 1);
    v3.set(5, 1);
    v3.set(9, 1);

    MaybePruneRowsMapper mapper = new MaybePruneRowsMapper();
    setField(mapper, "maxCooccurrences", 2);

    Mapper<VarLongWritable,VectorWritable, IntWritable, DistributedRowMatrix.MatrixEntryWritable>.Context ctx =
View Full Code Here

Examples of org.apache.mahout.math.RandomAccessSparseVector

    @Override
    public Vector next() {
      if (!hasNext()) {
        throw new NoSuchElementException();
      }
      Vector result = type == VectorType.SPARSE ? new RandomAccessSparseVector(numItems) : new DenseVector(numItems);
      result.assign(new UnaryFunction(){
        @Override
        public double apply(double arg1) {
          return random.nextDouble();
        }
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.