Package org.apache.mahout.math

Examples of org.apache.mahout.math.Vector.iterateNonZero()


    @Override
    protected void map(IntWritable userOrItemID, VectorWritable ratingsWritable, Context ctx)
        throws IOException, InterruptedException {
      Vector ratings = new SequentialAccessSparseVector(ratingsWritable.get());
      List<Vector> featureVectors = Lists.newArrayList();
      Iterator<Vector.Element> interactions = ratings.iterateNonZero();
      while (interactions.hasNext()) {
        int index = interactions.next().index();
        featureVectors.add(UorM.get(index));
      }
View Full Code Here


   */
  @Override
  public double distance(Vector v1, Vector v2) {
    Vector distVector = v1.minus(v2);
    double sum = 0.0;
    Iterator<Element> it = distVector.iterateNonZero();
    while (it.hasNext()) {
      Element e = it.next();
      sum += Math.pow(Math.abs(e.get()), exponent);
    }
    return Math.pow(sum, 1.0 / exponent);
View Full Code Here

  @Override
  protected void map(WritableComparable<?> key, VectorWritable value, Context context) throws IOException,
      InterruptedException {
    Vector probabilities = classifier.classify(value.get());
    Vector selections = policy.select(probabilities);
    for (Iterator<Element> it = selections.iterateNonZero(); it.hasNext();) {
      Element el = it.next();
      classifier.train(el.index(), value.get(), el.get());
    }
  }
 
View Full Code Here

        // classification yields probabilities
        Vector probabilities = classifier.classify(vector);
        // policy selects weights for models given those probabilities
        Vector weights = policy.select(probabilities);
        // training causes all models to observe data
        for (Iterator<Vector.Element> it = weights.iterateNonZero(); it.hasNext();) {
          int index = it.next().index();
          classifier.train(index, vector, weights.get(index));
        }
      }
      // compute the posterior models
View Full Code Here

        // classification yields probabilities
        Vector probabilities = classifier.classify(vector);
        // policy selects weights for models given those probabilities
        Vector weights = classifier.getPolicy().select(probabilities);
        // training causes all models to observe data
        for (Iterator<Vector.Element> it = weights.iterateNonZero(); it.hasNext();) {
          int index = it.next().index();
          classifier.train(index, vector, weights.get(index));
        }
      }
      // compute the posterior models
View Full Code Here

  protected void update(double label, Vector dataPoint, LinearModel model) {
    if (label > 0) {
      // case one
      Vector updateVector = dataPoint.times(1 / this.promotionStep);
      log.info("Winnow update positive: {}", updateVector);
      Iterator<Vector.Element> iter = updateVector.iterateNonZero();
      while (iter.hasNext()) {
        Vector.Element element = iter.next();
        if (element.get() != 0) {
          model.timesDelta(element.index(), element.get());
        }
View Full Code Here

      }
    } else {
      // case two
      Vector updateVector = dataPoint.times(1 / this.promotionStep);
      log.info("Winnow update negative: {}", updateVector);
      Iterator<Vector.Element> iter = updateVector.iterateNonZero();
      while (iter.hasNext()) {
        Vector.Element element = iter.next();
        if (element.get() != 0) {
          model.timesDelta(element.index(), element.get());
        }
View Full Code Here

    Iterator<VectorWritable> it = values.iterator();
    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;
View Full Code Here

      Vector rowVector = similarity.normalize(vectorWritable.get());

      int numNonZeroEntries = 0;
      double maxValue = Double.MIN_VALUE;

      Iterator<Vector.Element> nonZeroElements = rowVector.iterateNonZero();
      while (nonZeroElements.hasNext()) {
        Vector.Element element = nonZeroElements.next();
        RandomAccessSparseVector partialColumnVector = new RandomAccessSparseVector(Integer.MAX_VALUE);
        partialColumnVector.setQuick(row.get(), element.get());
        ctx.write(new IntWritable(element.index()), new VectorWritable(partialColumnVector));
View Full Code Here

        throws IOException, InterruptedException {
      Iterator<VectorWritable> partialDotsIterator = partialDots.iterator();
      Vector dots = partialDotsIterator.next().get();
      while (partialDotsIterator.hasNext()) {
        Vector toAdd = partialDotsIterator.next().get();
        Iterator<Vector.Element> nonZeroElements = toAdd.iterateNonZero();
        while (nonZeroElements.hasNext()) {
          Vector.Element nonZeroElement = nonZeroElements.next();
          dots.setQuick(nonZeroElement.index(), dots.getQuick(nonZeroElement.index()) + nonZeroElement.get());
        }
      }
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.