Package org.apache.mahout.math

Examples of org.apache.mahout.math.RandomAccessSparseVector


  @Override
  protected void map(IntWritable index, VectorWritable value, Context ctx) throws IOException, InterruptedException {
    Vector instance = value.get();
    if (weightsPerFeature == null) {
      weightsPerFeature = new RandomAccessSparseVector(instance.size(), instance.getNumNondefaultElements());
    }

    int label = index.get();
//    instance.addTo(weightsPerFeature);
    weightsPerFeature.assign(instance, Functions.PLUS);
View Full Code Here


      }
    } finally {
      Closeables.closeQuietly(reader);
    }

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

  }


  @Override
  public Vector toVector() {
    final Vector vector = new RandomAccessSparseVector(cardinality());
    elements.forEachPair(new IntDoubleProcedure() {
      @Override
      public boolean apply(int i, double v) {
        vector.setQuick(i, v);
        return true;
      }
    });
    return vector;
  }
View Full Code Here

        new Function<Integer, Vector>() {
          private final Random random = RandomUtils.getRandom();
          @Override
          public Vector apply(Integer dummy) {
            Vector result =
                type == VectorType.SPARSE ? new RandomAccessSparseVector(numItems) : new DenseVector(numItems);
            result.assign(new DoubleFunction(){
              @Override
              public double apply(double ignored) {
                return random.nextDouble();
              }
View Full Code Here

 
  @Override
  protected void reduce(WritableComparable<?> key, Iterable<VectorWritable> values, Context context) throws IOException,
      InterruptedException {

    Vector vector = new RandomAccessSparseVector(dimension, 10);
    for (VectorWritable value : values) {
      value.get().addTo(vector);
    }
    if (normPower != PartialVectorMerger.NO_NORMALIZING) {
      if (logNormalize) {
        vector = vector.logNormalize(normPower);
      } else {
        vector = vector.normalize(normPower);
      }
    }
    if (sequentialAccess) {
      vector = new SequentialAccessSparseVector(vector);
    }
View Full Code Here

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

      }
      Vector result;
      if (line.startsWith(ARFFModel.ARFF_SPARSE)) {
        line = line.substring(1, line.length() - 1);
        String[] splits = ARFFVectorIterable.COMMA_PATTERN.split(line);
        result = new RandomAccessSparseVector(model.getLabelSize());
        for (String split : splits) {
          String[] data = ARFFVectorIterable.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

   
    stats = new TimingStatistics();
    for (int l = 0; l < loop; l++) {
      for (int i = 0; i < numVectors; i++) {
        TimingStatistics.Call call = stats.newCall();
        vectors[1][i] = new RandomAccessSparseVector(randomVectors.get(i));
        call.end();
      }
    }
    printStats(stats, "Create (copy)", "RandSparseVector");
   
View Full Code Here

    printStats(stats, "Create (incrementally)", "DenseVector");

    stats = new TimingStatistics();
    for (int l = 0; l < loop; l++) {
      for (int i = 0; i < numVectors; i++) {
        vectors[1][i] = new RandomAccessSparseVector(cardinality);
        buildVectorIncrementally(stats, i, vectors[1][i], false);
      }
    }
    printStats(stats, "Create (incrementally)", "RandSparseVector");
View Full Code Here

  private FileSystem fs;

  private static List<VectorWritable> getPointsWritable() {
    List<VectorWritable> points = new ArrayList<VectorWritable>();
    for (double[] fr : RAW) {
      Vector vec = new RandomAccessSparseVector(fr.length);
      vec.assign(fr);
      points.add(new VectorWritable(vec));
    }
    return points;
  }
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.