Package org.apache.mahout.math

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


    enc.addInteractionToVector("a","1.0",1.0,v2);
    wv.addToVector("a", v2);
    cv.addToVector("1.0", v2);
    k = enc.getProbes();
    //this assumes no hash collision
    assertEquals((float) (k + wv.getProbes()+cv.getProbes()), v2.norm(1), 1.0e-3);
  }

  @Test
  public void testAddToVectorUsesProductOfWeights() {
    WordValueEncoder wv = new StaticWordValueEncoder("word");
View Full Code Here


    InteractionValueEncoder enc = new InteractionValueEncoder("interactions", wv, cv);
    Vector v1 = new DenseVector(200);
    enc.addInteractionToVector("a","0.9",0.5, v1);
    int k = enc.getProbes();
    // should set k distinct locations to 0.9*0.5
    assertEquals((float) k*0.5*0.9, v1.norm(1), 0);
    assertEquals(0.5*0.9, v1.maxValue(), 0);
  }

  @Test
  public void testAddToVectorWithTextValueEncoder() {
View Full Code Here

    InteractionValueEncoder enc = new InteractionValueEncoder("interactions", wv, tv);
    Vector v1 = new DenseVector(200);
    enc.addInteractionToVector("a","some text here",1.0, v1);
    int k = enc.getProbes();
    // should interact "a" with each of "some","text" and "here"
    assertEquals((float) k*3, v1.norm(1), 0);
  }

}
View Full Code Here

    // then normalize to turn it into a probability distribution
    p1.assign(Functions.div(p1.norm(1)));

    // likewise normalize p2
    p2.assign(Functions.div(p2.norm(1)));

    // sample 100 times from p1
    Multiset<Integer> w1 = HashMultiset.create();
    for (int i = 0; i < 100; i++) {
      w1.add(sample(p1, rand));
View Full Code Here

      double e = eigenvalues.get(eigenvalues.size() - i - 1);
      log.info("{} : L = {}, E = {}", i, s, e);
      assertTrue("Singular value differs from eigenvalue", Math.abs((s-e)/e) < ERROR_TOLERANCE);
      Vector v = state.getRightSingularVector(i);
      Vector v2 = decomposition.getV().viewColumn(eigenvalues.size() - i - 1);
      double error = 1 - Math.abs(v.dot(v2)/(v.norm(2) * v2.norm(2)));
      log.info("error: {}", error);
      assertTrue(i + ": 1 - cosAngle = " + error, error < ERROR_TOLERANCE);
    }
  }

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

    }
    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

    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

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.