Package org.apache.mahout.math

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


    Vector v;
    do {
      double r = rng.nextDouble();
      index = (int) (r * corpus.numRows());
      v = corpus.getRow(index);
    } while (v == null || v.norm(2) == 0 || v.getNumNondefaultElements() < 5);
    return index;
  }

  /**
   * Uses the {@link SingularVectorVerifier } to check for convergence
View Full Code Here


    }
    for(Map.Entry<Integer, Vector> entry : mMap.entrySet()) {
      Integer key = entry.getKey();
      Vector value = entry.getValue();
      if(value == null || mttMap.get(key) == null) {
        assertTrue(value == null || value.norm(2) == 0);
        assertTrue(mttMap.get(key) == null || mttMap.get(key).norm(2) == 0);
      } else {
        assertTrue(
            value.getDistanceSquared(mttMap.get(key)) < errorTolerance);
      }
View Full Code Here

    int n = mtx.columnSize();
    int rank = 0;
    for (int i = 0; i < n; i++) {
      Vector ei = mtx.getColumn(i);

      double norm = ei.norm(2);

      if (Math.abs(1 - norm) < epsilon) {
        rank++;
      } else {
        Assert.assertTrue(Math.abs(norm) < epsilon);
View Full Code Here

    FeatureVectorEncoder enc = new ContinuousValueEncoder("foo");
    Vector v1 = new DenseVector(20);
    enc.addToVector("-123", v1);
    assertEquals(-123, v1.minValue(), 0);
    assertEquals(0, v1.maxValue(), 0);
    assertEquals(123, v1.norm(1), 0);

    v1 = new DenseVector(20);
    enc.addToVector("123", v1);
    assertEquals(123, v1.maxValue(), 0);
    assertEquals(0, v1.minValue(), 0);
View Full Code Here

    v1 = new DenseVector(20);
    enc.addToVector("123", v1);
    assertEquals(123, v1.maxValue(), 0);
    assertEquals(0, v1.minValue(), 0);
    assertEquals(123, v1.norm(1), 0);

    Vector v2 = new DenseVector(20);
    enc.setProbes(2);
    enc.addToVector("123", v2);
    assertEquals(123, v2.maxValue(), 0);
View Full Code Here

    Vector v2 = new DenseVector(20);
    enc.setProbes(2);
    enc.addToVector("123", v2);
    assertEquals(123, v2.maxValue(), 0);
    assertEquals(2 * 123, v2.norm(1), 0);

    // v1 has one probe, v2 has two.  The first probe in v2 should be in the same
    // place as the only probe in v1
    v1 = v2.minus(v1);
    assertEquals(123, v1.maxValue(), 0);
View Full Code Here

    FeatureVectorEncoder enc = new ConstantValueEncoder("foo");
    Vector v1 = new DenseVector(20);
    enc.addToVector((byte[]) null, -123, v1);
    assertEquals(-123, v1.minValue(), 0);
    assertEquals(0, v1.maxValue(), 0);
    assertEquals(123, v1.norm(1), 0);

    v1 = new DenseVector(20);
    enc.addToVector((byte[]) null, 123, v1);
    assertEquals(123, v1.maxValue(), 0);
    assertEquals(0, v1.minValue(), 0);
View Full Code Here

    v1 = new DenseVector(20);
    enc.addToVector((byte[]) null, 123, v1);
    assertEquals(123, v1.maxValue(), 0);
    assertEquals(0, v1.minValue(), 0);
    assertEquals(123, v1.norm(1), 0);

    Vector v2 = new DenseVector(20);
    enc.setProbes(2);
    enc.addToVector((byte[]) null, 123, v2);
    assertEquals(123, v2.maxValue(), 0);
View Full Code Here

    Vector v2 = new DenseVector(20);
    enc.setProbes(2);
    enc.addToVector((byte[]) null, 123, v2);
    assertEquals(123, v2.maxValue(), 0);
    assertEquals(2 * 123, v2.norm(1), 0);

    // v1 has one probe, v2 has two.  The first probe in v2 should be in the same
    // place as the only probe in v1
    v1 = v2.minus(v1);
    assertEquals(123, v1.maxValue(), 0);
View Full Code Here

    int n = qt.length;
    int rank = 0;
    for (int i = 0; i < n; i++) {
      Vector ei = new DenseVector(qt[i], true);

      double norm = ei.norm(2);

      if (Math.abs(1.0 - norm) < epsilon) {
        rank++;
      } else if (Math.abs(norm) > epsilon) {
        return false; // not a rank deficiency, either
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.