Package org.apache.mahout.math

Examples of org.apache.mahout.math.RandomAccessSparseVector


   
    @Override
    protected void reduce(Text row, Iterable<VertexWritable> entries,
        Context context) throws IOException, InterruptedException {
      // now to assemble the vectors
      RandomAccessSparseVector output = new RandomAccessSparseVector(
          context.getConfiguration().getInt(EigencutsKeys.AFFINITY_DIMENSIONS, Integer.MAX_VALUE), 100);
      int rownum = Integer.parseInt(row.toString());
      for (VertexWritable e : entries) {
        // first, are we setting a diagonal?
        if (e.getCol() == rownum) {
          // add to what's already present
          output.setQuick(e.getCol(), output.getQuick(e.getCol()) + e.getValue());
        } else {
          // simply set the value
          output.setQuick(e.getCol(), e.getValue());
        }
      }
      context.write(new IntWritable(rownum), new VectorWritable(output));
    }
View Full Code Here


  @Override
  protected void reduce(IntWritable key, Iterable<EigencutsSensitivityNode> arr, Context context)
    throws IOException, InterruptedException {
    Configuration conf = context.getConfiguration();
    Vector v = new RandomAccessSparseVector(conf.getInt(EigencutsKeys.AFFINITY_DIMENSIONS, Integer.MAX_VALUE), 100);
    double threshold = Double.parseDouble(conf.get(EigencutsKeys.TAU)) /
      Double.parseDouble(conf.get(EigencutsKeys.DELTA));
   
    for (EigencutsSensitivityNode n : arr) {
      if (n.getSensitivity() < threshold && n.getSensitivity() < v.getQuick(n.getColumn())) {
        v.setQuick(n.getColumn(), n.getSensitivity());
      }
    }
    context.write(key, new VectorWritable(v));
  }
View Full Code Here

  protected AbstractCluster() {
  }

  protected AbstractCluster(Vector point, int id2) {
    this.numPoints = 0;
    this.center = new RandomAccessSparseVector(point);
    this.radius = point.like();
    this.id = id2;
  }
View Full Code Here

    this.id = id2;
  }

  protected AbstractCluster(Vector center2, Vector radius2, int id2) {
    this.numPoints = 0;
    this.center = new RandomAccessSparseVector(center2);
    this.radius = new RandomAccessSparseVector(radius2);
    this.id = id2;
  }
View Full Code Here

 
  @Override
  protected void reduce(IntWritable rowIndex, Iterable<DistributedRowMatrix.MatrixEntryWritable> values, Context ctx)
      throws IOException, InterruptedException {

    Vector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    for (DistributedRowMatrix.MatrixEntryWritable entry : values) {
      vector.setQuick(entry.getCol(), entry.getVal());
    }
    VectorWritable vectorWritable = new VectorWritable(vector);
    vectorWritable.setWritesLaxPrecision(true);
    ctx.write(rowIndex, vectorWritable);
  }
View Full Code Here

  @Override
  protected void reduce(IntWritable row, Iterable<DistributedRowMatrix.MatrixEntryWritable> values, Context context)
    throws IOException, InterruptedException {
    int size = context.getConfiguration().getInt(EigencutsKeys.AFFINITY_DIMENSIONS, Integer.MAX_VALUE);
    RandomAccessSparseVector out = new RandomAccessSparseVector(size, 100);

    for (DistributedRowMatrix.MatrixEntryWritable element : values) {
      out.setQuick(element.getCol(), element.getVal());
      if (log.isDebugEnabled()) {
        log.debug("(DEBUG - REDUCE) Row[{}], Column[{}], Value[{}]",
                  new Object[] {row.get(), element.getCol(), element.getVal()});
      }
    }
View Full Code Here

    context.write(new EntityEntityWritable(34L, 56L), new DoubleWritable(0.9));

    EasyMock.replay(context);

    Vector vector = new RandomAccessSparseVector(Integer.MAX_VALUE);
    vector.set(12, 0.2);
    vector.set(34, 1.0);
    vector.set(56, 0.9);

    MostSimilarItemPairsMapper mapper = new MostSimilarItemPairsMapper();
    setField(mapper, "indexItemIDMap", indexItemIDMap);
    setField(mapper, "maxSimilarItemsPerItem", 1);
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 RandomAccessSparseVector generateRandomDoc(int numWords, double sparsity) throws MathException {
    RandomAccessSparseVector v = new RandomAccessSparseVector(numWords,(int)(numWords * sparsity));
    IntegerDistribution 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

  public void testMapper() throws Exception {
    LDAState state = generateRandomState(100,NUM_TOPICS);
    LDAMapper mapper = new LDAMapper();
    mapper.configure(state);
    for(int i = 0; i < NUM_TESTS; ++i) {
      RandomAccessSparseVector v = generateRandomDoc(100,0.3);
      int myNumWords = numNonZero(v);
      LDAMapper.Context mock = EasyMock.createMock(LDAMapper.Context.class);

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

    extends Reducer<VarLongWritable,VarLongWritable,VarIntWritable,VectorAndPrefsWritable> {
  @Override
  protected void reduce(VarLongWritable itemID, Iterable<VarLongWritable> values, Context ctx)
      throws IOException, InterruptedException {
    int itemIDIndex = TasteHadoopUtils.idToIndex(itemID.get());
    Vector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 1);
    /* artificial NaN summand to exclude this item from the recommendations for all users specified in userIDs */
    vector.set(itemIDIndex, Double.NaN);

    List<Long> userIDs = new ArrayList<Long>();
    List<Float> prefValues = new ArrayList<Float>();
    for (VarLongWritable userID : values) {
      userIDs.add(userID.get());
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.RandomAccessSparseVector

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.