Package org.apache.mahout.math

Examples of org.apache.mahout.math.RandomAccessSparseVector


    @Override
    public void reduce(IntWritable outRow,
                       Iterator<DistributedRowMatrix.MatrixEntryWritable> it,
                       OutputCollector<IntWritable, VectorWritable> out,
                       Reporter reporter) throws IOException {
      RandomAccessSparseVector tmp = new RandomAccessSparseVector(newNumCols, 100);
      while (it.hasNext()) {
        DistributedRowMatrix.MatrixEntryWritable e = it.next();
        tmp.setQuick(e.getCol(), e.getVal());
      }
      SequentialAccessSparseVector outVector = new SequentialAccessSparseVector(tmp);
      out.collect(outRow, new VectorWritable(outVector));
    }
View Full Code Here


                       OutputCollector<IntWritable,VectorWritable> out,
                       Reporter reporter) throws IOException {
      if (!it.hasNext()) {
        return;
      }
      Vector accumulator = new RandomAccessSparseVector(it.next().get());
      while (it.hasNext()) {
        Vector row = it.next().get();
        row.addTo(accumulator);
      }
      out.collect(rowNum, new VectorWritable(new SequentialAccessSparseVector(accumulator)));
View Full Code Here

 
  @Override
  protected void reduce(VarLongWritable userID,
                        Iterable<VarLongWritable> itemPrefs,
                        Context context) throws IOException, InterruptedException {
    Vector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    for (VarLongWritable itemPref : itemPrefs) {
      int index = TasteHadoopUtils.idToIndex(itemPref.get());
      float value = itemPref instanceof EntityPrefWritable ? ((EntityPrefWritable) itemPref).getPrefValue() : 1.0f;
      userVector.set(index, value);
    }

    VectorWritable vw = new VectorWritable(userVector);
    vw.setWritesLaxPrecision(true);
    context.write(userID, vw);
View Full Code Here

        if (!(inputVector instanceof SequentialAccessSparseVector || inputVector instanceof DenseVector)) {
          inputVector = new SequentialAccessSparseVector(inputVector);
        }
        int outDim = conf.getInt(OUTPUT_VECTOR_DIMENSION, Integer.MAX_VALUE);
        outputVector = conf.getBoolean(IS_SPARSE_OUTPUT, false)
                     ? new RandomAccessSparseVector(outDim, 10)
                     : new DenseVector(outDim);
      } catch (IOException ioe) {
        throw new IllegalStateException(ioe);
      }
    }
View Full Code Here

    @Override
    public void configure(JobConf conf) {
      int outputDimension = conf.getInt(OUTPUT_VECTOR_DIMENSION, Integer.MAX_VALUE);
      outputVector = conf.getBoolean(IS_SPARSE_OUTPUT, false)
                   ? new RandomAccessSparseVector(outputDimension, 10)
                   : new DenseVector(outputDimension);
    }
View Full Code Here

    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

  @Override
  protected void map(IntWritable key, VectorWritable value, Context context)
      throws IOException, InterruptedException {
    Vector vector = value.get();
    if (featureSum == null) {
      featureSum = new RandomAccessSparseVector(vector.size(), vector.getNumNondefaultElements());
      labelSum = new RandomAccessSparseVector(labelMap.size())
    }
   
    int label = key.get();
    vector.addTo(featureSum);
    labelSum.set(label, labelSum.get(label) + vector.zSum());
View Full Code Here

      }
    } finally {
      reader.close();
    }

    Vector v = new RandomAccessSparseVector(FEATURES);
    bias.addToVector("", 1, v);
    for (String word : words.elementSet()) {
      encoder.addToVector(word, Math.log(1 + words.count(word)), v);
    }
View Full Code Here

        csv.firstLine(in.readLine());

        String line = in.readLine();
        while (line != null) {
          // for each new line, get target and predictors
          Vector input = new RandomAccessSparseVector(lmp.getNumFeatures());
          int targetValue = csv.processLine(line, input);

          // check performance while this is still news
          double logP = lr.logLikelihood(targetValue, input);
          if (!Double.isInfinite(logP)) {
View Full Code Here

    if (!it.hasNext()) {
      return;
    }
    Vector value = it.next().get();
    Iterator<Vector.Element> it1 = value.iterateNonZero();
    Vector vector = new RandomAccessSparseVector((int) featureCount, value.getNumNondefaultElements());
    while (it1.hasNext()) {
      Vector.Element e = it1.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

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.