Package org.apache.mahout.math.Vector

Examples of org.apache.mahout.math.Vector.Element


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


  public int maxIndex(Vector instance) {
    Iterator<Element> it = instance.iterator();
    int maxIndex = -1;
    double val = Integer.MIN_VALUE;
    while (it.hasNext()) {
      Element e = it.next();
      if (val <= e.get()) {
        maxIndex = e.index();
        val = e.get();
      }
    }
    return maxIndex;
  }
View Full Code Here

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

    @Override
    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;
  }
View Full Code Here

      for (int j = 0; j < n; j++) {
        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

      for (int j = 0; j < n; j++) {
        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

  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

  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

 
  private static void writeAllAboveThreshold(List<Cluster> clusterModels, Double clusterClassificationThreshold,
      SequenceFile.Writer writer, VectorWritable vw, Vector pdfPerCluster) throws IOException {
    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

TOP

Related Classes of org.apache.mahout.math.Vector.Element

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.