Package org.apache.mahout.math.Vector

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


    while (it.hasNext()) {  // hasNext is called more often than next
      if (i % 2 == 0) {
        element = it.next();
      }
      //noinspection ConstantConditions
      assertEquals(element.index(), 2* (i/2));
      assertEquals(element.get(), vector.get(2* (i/2)), 0);
      ++i;
    }
    assertEquals(7, i)// Last element is print only once.

View Full Code Here


    while (it.hasNext()) { // hasNext is called more often than next
      if (i % 2 == 0) {
        element = it.next();
      }
      //noinspection ConstantConditions
      assertEquals(element.index(), i/2);
      assertEquals(element.get(), vector.get(i/2), 0);
      ++i;
    }
    assertEquals(197, i)// Last element is print only once.
  }
View Full Code Here

    // Test all iterator.
    it = vector.all().iterator();
    i = 0;
    while (it.hasNext()) { // hasNext is called more often than next
      Element element = it.next();
      assertEquals(i, element.index());
      ++i;
    }
    assertFalse(it.hasNext());
    assertEquals(99, i)// Last element is print only once.
  }
View Full Code Here

    // Test non zero iterator.
    Iterator<Element> it = vector.nonZeroes().iterator();
    int i = 0;
    while (it.hasNext()) {
      Element e = it.next();
      assertTrue(expected.contains(e.index()));
      assertTrue(expectedValue.contains(e.get()));
      ++i;
    }
    assertEquals(8, i);
View Full Code Here

    // Set one element to 0.
    it = vector.nonZeroes().iterator();
    i = 0;
    while (it.hasNext()) {
      Element e = it.next();
      if (e.index() == 5) {
        e.set(0.0);
      }
      ++i;
    }
    assertEquals(8, i);
View Full Code Here

    // Remove one element
    it = vector.nonZeroes().iterator();
    i = 0;
    while (it.hasNext()) {
      Element e = it.next();
      if (e.index() == 5) {
        vector.set(5, 0.0);
      }
      ++i;
    }
    assertEquals(7, i); // This just got messed up.
View Full Code Here

    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

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

    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

      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

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.