Package org.apache.mahout.math.Vector

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


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


  }

  public SequentialAccessSparseVector(Vector other) {
    this(other.getName(), other.size(), other.getNumNondefaultElements());
    Iterator<Element> it = other.iterateNonZero();
    Element e;
    while(it.hasNext() && (e = it.next()) != null) {
      set(e.index(), e.get());
    }
  }
View Full Code Here

    double result = 0;
    if (x instanceof SequentialAccessSparseVector) {
      // For sparse SeqAccVectors. do dot product without lookup in a linear fashion
      Iterator<Element> myIter = iterateNonZero();
      Iterator<Element> otherIter = x.iterateNonZero();
      Element myCurrent = null;
      Element otherCurrent = null;
      while (myIter.hasNext() && otherIter.hasNext()) {
        if (myCurrent == null) myCurrent = myIter.next();
        if (otherCurrent == null) otherCurrent = otherIter.next();
       
        int myIndex = myCurrent.index();
        int otherIndex = otherCurrent.index();
       
        if (myIndex < otherIndex) {
          // due to the sparseness skipping occurs more hence checked before equality
          myCurrent = null;
        } else if (myIndex > otherIndex){
          otherCurrent = null;
        } else { // both are equal
          result += myCurrent.get() * otherCurrent.get();
          myCurrent = null;
          otherCurrent = null;
        }
      }
      return result;
    } else { // seq.rand. seq.dense
      Iterator<Element> iter = iterateNonZero();
      while (iter.hasNext()) {
        Element element = iter.next();
        result += element.get() * x.getQuick(element.index());
      }
      return result;
    }
  }
View Full Code Here

                  Reporter reporter) throws IOException {
    Vector vector = value.get();
    Iterator<Element> it = vector.iterateNonZero();
   
    while (it.hasNext()) {
      Element e = it.next();
      output.collect(new IntWritable(e.index()), ONE);
    }
    output.collect(TOTAL_COUNT, ONE);
  }
View Full Code Here

    Vector value = values.next().get();
    Iterator<Element> it = value.iterateNonZero();
    Vector vector = new RandomAccessSparseVector(key.toString(), (int) featureCount, value
        .getNumNondefaultElements());
    while (it.hasNext()) {
      Element e = it.next();
      if (!dictionary.containsKey(e.index())) {
        continue;
      }
      long df = dictionary.get(e.index());
      if (df / vectorCount > maxDfPercent) {
        continue;
      }
      if (df < minDf) {
        df = minDf;
      }
      vector.setQuick(e.index(), tfidf.calculate((int) e.get(), (int) df, (int) featureCount,
        (int) vectorCount));
    }
    if (sequentialAccess) {
      vector = new SequentialAccessSparseVector(vector);
    }
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

      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 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

    Vector vector = value.get();
    int label = key.get();
    double sigmaK = labelSum.get(label);
    Iterator<Element> it = vector.iterateNonZero();
    while (it.hasNext()) {
      Element e = it.next();
      double numerator = featureSum.get(e.index()) - e.get() + alphaI;
      double denominator = totalSum - sigmaK + vocabCount;
      double weight = Math.log(numerator / denominator);
      perLabelThetaNormalizer.set(label, perLabelThetaNormalizer.get(label) + weight);
    }
  }
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.