Package org.apache.mahout.math

Examples of org.apache.mahout.math.RandomAccessSparseVector$NonDefaultIterator$NonDefaultElement


    Multiset<String> counts = parse(f);
    return vectorize(counts, w, normalize, dimension);
  }

  static Vector vectorize(Multiset<String> doc, CorpusWeighting w, boolean normalize, int dimension) {
    Vector v = new RandomAccessSparseVector(dimension);
    FeatureVectorEncoder encoder = new StaticWordValueEncoder("text");
    for (String word : doc.elementSet()) {
      encoder.addToVector(word, w.weight(word, doc.count(word)), v);
    }
    if (normalize) {
      return v.assign(Functions.div(v.norm(2)));
    } else {
      return v;
    }
  }
View Full Code Here


    Reducer<IntWritable, IntWritable, IntWritable, VectorWritable> {

  public void reduce(IntWritable itemIndex1,
      Iterable<IntWritable> itemIndex2s, Context context)
      throws IOException, InterruptedException {
    Vector cooccurrenceRow = new RandomAccessSparseVector(
        Integer.MAX_VALUE, 100);
    for (IntWritable intWritable : itemIndex2s) {
      int itemIndex2 = intWritable.get();
      cooccurrenceRow.set(itemIndex2,
          cooccurrenceRow.get(itemIndex2) + 1.0);
    }
    context.write(itemIndex1, new VectorWritable(cooccurrenceRow));
  }
View Full Code Here

  public Ops() {
  }

  @Override
  public List<Double> classify(String text) throws TException {
    Vector features = new RandomAccessSparseVector(FEATURES);
    enc.addText(text.toLowerCase());
    enc.flush(1, features);
    bias.addToVector((byte[]) null, 1, features);
    Vector r = model.classifyFull(features);
    List<Double> rx = Lists.newArrayList();
View Full Code Here

    Reducer<VarLongWritable, VarLongWritable, VarLongWritable, VectorWritable> {

  public void reduce(VarLongWritable userID,
      Iterable<VarLongWritable> itemPrefs, Context context)
      throws IOException, InterruptedException {
    Vector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
    for (VarLongWritable itemPref : itemPrefs) {
      userVector.set((int) itemPref.get(), 1.0f);
    }
    context.write(userID, new VectorWritable(userVector));
  }
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 RandomAccessSparseVector(fr.length);
      vec.assign(fr);
      points.add(vec);
    }
    return points;
  }
View Full Code Here

    StringReader in = new StringReader("text to magically vectorize");
    TokenStream ts = analyzer.tokenStream("body", in);
    TermAttribute termAtt = ts.addAttribute(TermAttribute.class);

    Vector v1 = new RandomAccessSparseVector(100);                  
    while (ts.incrementToken()) {
      char[] termBuffer = termAtt.termBuffer();
      int termLen = termAtt.termLength();
      String w = new String(termBuffer, 0, termLen);                
      encoder.addToVector(w, 1, v1);                                
View Full Code Here

      }
    } finally {
      reader.close();
    }

    Vector v = new RandomAccessSparseVector(FEATURES);
    bias.addToVector((byte[]) null, 1, v);
    encoder.flush(1, v);
    return v;
  }
View Full Code Here

  private Map<Long, Double> interactionCache = Maps.newHashMap();

  private FeatureEncoder encoder = new FeatureEncoder();

  public List<ScoredItem> topItems(User u, int limit) {
    Vector userVector = new RandomAccessSparseVector(model.numFeatures());
    encoder.addUserFeatures(u, userVector);
    double userScore = model.classifyScalarNoLink(userVector);

    PriorityQueue<ScoredItem> r = new PriorityQueue<ScoredItem>();
    for (Item item : items) {
      Double itemScore = itemCache.get(item);
      if (itemScore == null) {
        Vector v = new RandomAccessSparseVector(model.numFeatures());
        encoder.addItemFeatures(item, v);
        itemScore = model.classifyScalarNoLink(v);
        itemCache.put(item, itemScore);
      }

      long code = encoder.interactionHash(u, item);
      Double interactionScore = interactionCache.get(code);
      if (interactionScore == null) {
        Vector v = new RandomAccessSparseVector(model.numFeatures());
        encoder.addInteractions(u, item, v);
        interactionScore = model.classifyScalarNoLink(v);
        interactionCache.put(code, interactionScore);
      }
      double score = userScore + itemScore + interactionScore;
View Full Code Here

    @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

    @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

TOP

Related Classes of org.apache.mahout.math.RandomAccessSparseVector$NonDefaultIterator$NonDefaultElement

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.