Package org.apache.mahout.math.Vector

Examples of org.apache.mahout.math.Vector.Element.index()


    public Vector assign(Vector x, Vector y, DoubleDoubleFunction f) {
      Iterator<Vector.Element> xi = x.all().iterator();
      Iterator<Vector.Element> yi = y.all().iterator();
      while (xi.hasNext() && yi.hasNext()) {
        Element xe = xi.next();
        x.setQuick(xe.index(), f.apply(xe.get(), yi.next().get()));
      }
      return x;
    }
  }
View Full Code Here


    Vector sample = new RandomAccessSparseVector(original.size(), sampleSize);
    Iterator<Element> sampledElements =
        new FixedSizeSamplingIterator<Vector.Element>(sampleSize, original.nonZeroes().iterator());
    while (sampledElements.hasNext()) {
      Element elem = sampledElements.next();
      sample.setQuick(elem.index(), elem.get());
    }
    return sample;
  }

  public static Vector topKElements(int k, Vector original) {
View Full Code Here

        accumDots(j, aRow.getQuick(j), yRow);
      }
    } else {
      for (Iterator<Element> iter = aRow.iterateNonZero(); iter.hasNext();) {
        Element el = iter.next();
        accumDots(el.index(), el.get(), yRow);
      }
    }
  }

  /**
 
View Full Code Here

        accumDots(j, aRow.getQuick(j), yRowOut);
      }
    } else {
      for (Iterator<Element> iter = aRow.iterateNonZero(); iter.hasNext();) {
        Element el = iter.next();
        accumDots(el.index(), el.get(), yRowOut);
      }
    }
  }

  /*
 
View Full Code Here

      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());
    }
  }
 
  /*
   * (non-Javadoc)
 
View Full Code Here

    Iterator<Element> iterateNonZero = pdfPerCluster.iterateNonZero();
    while (iterateNonZero.hasNext()) {
      Element pdf = iterateNonZero.next();
      if (pdf.get() >= clusterClassificationThreshold) {
        WeightedVectorWritable wvw = new WeightedVectorWritable(pdf.get(), vw.get());
        int clusterIndex = pdf.index();
        write(clusterModels, writer, wvw, clusterIndex);
      }
    }
  }
 
View Full Code Here

      Vector pdfPerCluster) throws IOException, InterruptedException {
    Iterator<Element> iterateNonZero = pdfPerCluster.iterateNonZero();
    while (iterateNonZero.hasNext()) {
      Element pdf = iterateNonZero.next();
      if (pdf.get() >= threshold) {
        int clusterIndex = pdf.index();
        write(vw, context, clusterIndex);
      }
    }
  }
 
View Full Code Here

  protected double getScoreForLabelInstance(int label, Vector instance) {
    double result = 0.0;
    Iterator<Element> elements = instance.iterateNonZero();
    while (elements.hasNext()) {
      Element e = elements.next();
      result += e.get() * getScoreForLabelFeature(label, e.index());
    }
    return result;
  }
 
  @Override
View Full Code Here

   */
  private double sumXminusCdivRsquared(Vector x) {
    double result = 0;
    for (Iterator<Element> it = getRadius().iterateNonZero(); it.hasNext();) {
      Element radiusElem = it.next();
      int index = radiusElem.index();
      double quotient = (x.get(index) - getCenter().get(index))
          / radiusElem.get();
      result += quotient * quotient;
    }
    return result;
View Full Code Here

    expectedIndices = Sets.newHashSet(expectedIndices);
    Iterator<Element> allIterator = vector.all().iterator();
    int index = 0;
    while (allIterator.hasNext()) {
      Element element = allIterator.next();
      assertEquals(index, element.index());
      if (expectedIndices.contains(index)) {
        assertEquals((double) index * 2, element.get(), EPSILON);
      } else {
        assertEquals(0.0, element.get(), EPSILON);
      }
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.