Package org.apache.mahout.math

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


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


    List<String> nonOrthogonals = new ArrayList<String>();
    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

    List<String> nonOrthogonals = new ArrayList<String>();
    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 - 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

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

        assertEquals(lr.getModel().currentLearningRate(), model.currentLearningRate(), 1e-10);
        in.close();

        // with that many data points, model should point in the same direction as the original vector
        Vector v = model.getBeta().viewRow(0);
        double z = n.dot(v) / (n.norm(2) * v.norm(2));
        assertEquals(1.0, z, 1e-2);

        // just for grins, we should check whether the model actually computes the correct values
        List<String> categories = ImmutableList.of("0", "1");
        for (Tuple example : examples) {
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

      double e = eigenvalues.get(i);
      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(i);
      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

    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

      endTime(TimingSection.ITERATE);
      startTime(TimingSection.ORTHOGANLIZE);
      orthoganalizeAgainstAllButLast(nextVector, state);
      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;
      }
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.