Package org.apache.mahout.math

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


    assertEquals(1.0, v1.maxValue(), 0);

    v1 = new DenseVector(200);
    enc.addToVector("", v1);
    enc.flush(1, v1);
    assertEquals(0.0, v1.norm(1), 0);
    assertEquals(0.0, v1.maxValue(), 0);

    v1 = new DenseVector(200);
    StringBuilder builder = new StringBuilder(5000);
    for (int i = 0; i < 1000; i++){//lucene's internal buffer length request is 4096, so let's make sure we can handle larger size
View Full Code Here


      builder.append("token_").append(i).append(' ');
    }
    enc.addToVector(builder.toString(), v1);
    enc.flush(1, v1);
    //System.out.println(v1);
    assertEquals(2000.0, v1.norm(1), 0);
    assertEquals(19.0, v1.maxValue(), 0);
  }
}
View Full Code Here

    List<String> nonOrthogonals = Lists.newArrayList();
    for (int i = 0; i < currentEigens.numRows(); i++) {
      Vector ei = currentEigens.viewRow(i);
      for (int j = 0; j <= i; j++) {
        Vector ej = currentEigens.viewRow(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.0 - dot) < errorMargin);
View Full Code Here

    List<String> nonOrthogonals = Lists.newArrayList();
    for (int i = 0; i < state.getIterationNumber(); i++) {
      Vector ei = state.getRightSingularVector(i);
      for (int j = 0; j <= i; j++) {
        Vector ej = state.getRightSingularVector(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.0 - dot) < errorMargin);
View Full Code Here

      Vector v = new DenseVector(numCols);
      for(int col = 0; col < numCols; col++) {
        double val = r.nextGaussian();
        v.set(col, val);
      }
      v.assign(Functions.MULT, 1/((row + 1) * v.norm(2)));
      matrix.assignRow(row, v);
    }
    if(symmetric) {
      return matrix.times(matrix.transpose());
    }
View Full Code Here

      double e = eigenvalues.get(eigenvalues.size() - i - 1);
      log.info("{} : L = {}, E = {}", new Object[] {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).toVector();
      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

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

public class SimpleEigenVerifier implements SingularVectorVerifier {

  public EigenStatus verify(VectorIterable corpus, Vector vector) {
    Vector resultantVector = corpus.timesSquared(vector);
    double newNorm = resultantVector.norm(2);
    double oldNorm = vector.norm(2);
    double eigenValue = (newNorm > 0 && oldNorm > 0) ? newNorm / oldNorm : 1;
    double cosAngle = (newNorm > 0 && oldNorm > 0) ? resultantVector.dot(vector) / (newNorm * oldNorm) : 0;
    return new EigenStatus(eigenValue, cosAngle, false);
  }
View Full Code Here

  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

      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;
      }
      nextVector.assign(new Scale(1 / beta));
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.