Examples of norm()


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

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

    // adding same interaction again should increment weights
    enc.addInteractionToVector("a","1.0",1.0,v1);
    assertEquals((float) k*2, v1.norm(1), 0);
View Full Code Here

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

    assertEquals((float) k, v1.norm(1), 0);
    assertEquals(1.0, v1.maxValue(), 0);

    // adding same interaction again should increment weights
    enc.addInteractionToVector("a","1.0",1.0,v1);
    assertEquals((float) k*2, v1.norm(1), 0);
    assertEquals(2.0, v1.maxValue(), 0);

    Vector v2 = new DenseVector(20000);
    enc.addInteractionToVector("a","1.0",1.0,v2);
    wv.addToVector("a", v2);
View Full Code Here

Examples of org.apache.mahout.math.DenseVector.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

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

    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

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

    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

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

    FeatureVectorEncoder encoder = new StaticWordValueEncoder("text");
    for (String word : doc.elementSet()) {
      encoder.addToVector(word, w.weight(word, doc.count(word)), v);
    }
    if (normalize) {
      return v.assign(Functions.div(v.norm(2)));
    } else {
      return v;
    }
  }
View Full Code Here

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

    FeatureVectorEncoder encoder = new StaticWordValueEncoder("text");
    for (String word : doc.elementSet()) {
      encoder.addToVector(word, w.weight(word, doc.count(word)), v);
    }
    if (normalize) {
      return v.assign(Functions.div(v.norm(2)));
    } else {
      return v;
    }
  }
View Full Code Here

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

  public static void assertOrthonormal(Matrix currentEigens, double errorMargin) {
    for (int i = 0; i < currentEigens.numRows(); i++) {
      Vector ei = currentEigens.getRow(i);
      for (int j = 0; j <= i; j++) {
        Vector ej = currentEigens.getRow(j);
        if (ei.norm(2) == 0 || ej.norm(2) == 0) {
          continue;
        }
        double dot = ei.dot(ej);
        if (i == j) {
          assertTrue("not norm 1 : " + dot + " (eigen #" + i + ')', (Math.abs(1 - dot) < errorMargin));
View Full Code Here

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

      endTime(TimingSection.ITERATE);
      startTime(TimingSection.ORTHOGANLIZE);
      orthoganalizeAgainstAllButLast(nextVector, basis);
      endTime(TimingSection.ORTHOGANLIZE);
      // and normalize
      beta = nextVector.norm(2);
      if (outOfRange(beta) || outOfRange(alpha)) {
        log.warn("Lanczos parameters out of range: alpha = {}, beta = {}.  Bailing out early!", alpha, beta);
        break;
      }
      final double b = beta;
View Full Code Here

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

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