Package org.apache.mahout.math

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


                                 boolean isSymmetric) {
    for (int i = 0; i < numEigensToCheck; i++) {
      Vector e = eigens.getRow(i);
      if (e.getLengthSquared() == 0) continue;
      Vector afterMultiply = isSymmetric ? corpus.times(e) : corpus.timesSquared(e);
      double dot = afterMultiply.dot(e);
      double afterNorm = afterMultiply.getLengthSquared();
      double error = 1 - dot / Math.sqrt(afterNorm * e.getLengthSquared());
      log.info("Eigenvalue({}) = {}", i, Math.sqrt(afterNorm/e.getLengthSquared()));
      assertTrue("Error margin: {" + error + " too high! (for eigen " + i + ")", Math.abs(error) < errorMargin);
    }
View Full Code Here


      state.getHelperVector().set(i, 0);
    }
    if (debug && currentPseudoEigen.norm(2) > 0) {
      for (int i = 0; i < state.getNumEigensProcessed(); i++) {
        Vector previousEigen = previousEigens.getRow(i);
        log.info("dot with previous: {}", (previousEigen.dot(currentPseudoEigen)) / currentPseudoEigen.norm(2));
      }
    }
    /*
     * Step 3: verify how eigen-like the prospective eigen is.  This is potentially asynchronous.
     */
 
View Full Code Here

 
  @Override
  public double pdf(VectorWritable v) {
    Vector x = v.get();
    double sd2 = stdDev * stdDev;
    double exp = -(x.dot(x) - 2 * x.dot(mean) + mean.dot(mean)) / (2 * sd2);
    double ex = Math.exp(exp);
    return ex / (stdDev * sqrt2pi);
  }
 
  @Override
View Full Code Here

 
  @Override
  public double pdf(VectorWritable v) {
    Vector x = v.get();
    double sd2 = stdDev * stdDev;
    double exp = -(x.dot(x) - 2 * x.dot(mean) + mean.dot(mean)) / (2 * sd2);
    double ex = Math.exp(exp);
    return ex / (stdDev * sqrt2pi);
  }
 
  @Override
View Full Code Here

    w.addToVector("and", v3);
    w.addToVector("more", v3);
    assertEquals(0, v3.minus(v2).norm(1), 0);

    // moreover, the locations set in the unweighted case should be the same as in the weighted case
    assertEquals(v3.zSum(), v3.dot(v1), 0);
  }

  @Test
  public void testAsString() {
    Locale.setDefault(Locale.ENGLISH);
View Full Code Here

    protected void map(IntWritable key, VectorWritable value, Context context)
      throws IOException, InterruptedException {
      Vector qRow = value.get();
      for (int i = 0; i < k; i++) {
        vRow.setQuick(i,
                      qRow.dot(uHat.viewColumn(i)) / sValues.getQuick(i));
      }
      context.write(key, vRowWritable); // U inherits original A row labels.
    }

    @Override
View Full Code Here

      throws IOException, InterruptedException {
      Vector qRow = value.get();
      if (sValues != null) {
        for (int i = 0; i < k; i++) {
          uRow.setQuick(i,
                        qRow.dot(uHat.viewColumn(i)) * sValues.getQuick(i));
        }
      } else {
        for (int i = 0; i < k; i++) {
          uRow.setQuick(i, qRow.dot(uHat.viewColumn(i)));
        }
View Full Code Here

          uRow.setQuick(i,
                        qRow.dot(uHat.viewColumn(i)) * sValues.getQuick(i));
        }
      } else {
        for (int i = 0; i < k; i++) {
          uRow.setQuick(i, qRow.dot(uHat.viewColumn(i)));
        }
      }

      context.write(key, uRowWritable); // U inherits original A row labels.
    }
View Full Code Here

    w.addToVector("and", v3);
    w.addToVector("more", v3);
    assertEquals(0, v3.minus(v2).norm(1), 0);

    // moreover, the locations set in the unweighted case should be the same as in the weighted case
    assertEquals(v3.zSum(), v3.dot(v1), 0);
  }

  @Test
  public void testAsString() {
    Locale.setDefault(Locale.ENGLISH);
View Full Code Here

      boolean isSymmetric) {
    if (e.getLengthSquared() == 0) {
      return;
    }
    Vector afterMultiply = isSymmetric ? corpus.times(e) : corpus.timesSquared(e);
    double dot = afterMultiply.dot(e);
    double afterNorm = afterMultiply.getLengthSquared();
    double error = 1 - Math.abs(dot / Math.sqrt(afterNorm * e.getLengthSquared()));
    log.info("the eigen-error: {} for eigen {}", error, i);
    assertTrue("Error: {" + error + " too high! (for eigen " + i + ')', Math.abs(error) < errorMargin);
  }
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.