Package org.apache.mahout.math

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


    }
    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.viewColumn(i);

      double norm = ei.norm(2);

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

    for (int m = low + 1; m <= high - 1; m++) {

      // Scale column.

      Vector hColumn = hessenBerg.viewColumn(m - 1).viewPart(m, high - m + 1);
      double scale = hColumn.norm(1);

      if (scale != 0.0) {
        // Compute Householder transformation.

        ort.viewPart(m, high - m + 1).assign(hColumn, Functions.plusMult(1 / scale));
View Full Code Here

    log.debug("   compatible   LS      norm A   cond A");

    Matrix transposedA = A.transpose();
    Vector u = b;

    double beta = u.norm(2);
    if (beta > 0) {
      u = u.divide(beta);
    }

    Vector v = transposedA.times(u);
View Full Code Here

        "Mahout version {}", getClass().getPackage().getImplementationVersion());
      log.debug(String.format("The matrix A has %d rows  and %d cols, lambda = %.4g, atol = %g, btol = %g",
        m, n, lambda, aTolerance, bTolerance));
    }

    double alpha = v.norm(2);
    if (alpha > 0) {
      v.assign(Functions.div(alpha));
    }

View Full Code Here

      // Test for convergence.

      // Compute norms for convergence testing.
      normalEquationResidual = Math.abs(zetabar);
      xNorm = x.norm(2);

      // Now use these norms to estimate certain other quantities,
      // some of which will be small near a solution.

      double test1 = residualNorm / normb;
View Full Code Here

    totalCorpusWeight = 0;
    int numNonZero = 0;
    for (int i = 0; i < numDocuments; i++) {
      Vector v = corpusWeights.viewRow(i);
      double norm;
      if (v != null && (norm = v.norm(1)) != 0) {
        numNonZero += v.getNumNondefaultElements();
        totalCorpusWeight += norm;
      }
    }
    String s = "Initializing corpus with %d docs, %d terms, %d nonzero entries, total termWeight %f";
View Full Code Here

        // Return the sum of three discrepancy measures.
        return Math.abs(f.minValue()) + Math.abs(f.maxValue() - 6) + Math.abs(f.norm(1) - 6);
      }
    });
    // Verify all errors are nearly zero.
    assertEquals(0, columnNorms.norm(1) / columnNorms.size(), 0.1);

    // Verify that the centroids are a permutation of the original ones.
    SingularValueDecomposition svd = new SingularValueDecomposition(x);
    Vector s = svd.getS().viewDiagonal().assign(Functions.div(6));
    assertEquals(5, s.getLengthSquared(), 0.05);
View Full Code Here

    // Verify that the centroids are a permutation of the original ones.
    SingularValueDecomposition svd = new SingularValueDecomposition(x);
    Vector s = svd.getS().viewDiagonal().assign(Functions.div(6));
    assertEquals(5, s.getLengthSquared(), 0.05);
    assertEquals(5, s.norm(1), 0.05);
  }

  private static List<? extends WeightedVector> cubishTestData(double radius) {
    List<WeightedVector> data = Lists.newArrayListWithCapacity(K1 + 5000);
    int row = 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.