Package org.apache.mahout.math

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


  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


      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());
      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

  public double pdf(VectorWritable v) {
    Vector x = v.get();
    // small prior on std to avoid numeric instability when std==0
    double std = stdDev + 0.000001;
    double sd2 = std * std;
    double exp = -(x.dot(x) - 2 * x.dot(mean) + mean.dot(mean)) / (2 * sd2);
    double ex = Math.exp(exp);
    return ex / (std * SQRT2PI);
  }

  @Override
View Full Code Here

  public double pdf(VectorWritable v) {
    Vector x = v.get();
    // small prior on std to avoid numeric instability when std==0
    double std = stdDev + 0.000001;
    double sd2 = std * std;
    double exp = -(x.dot(x) - 2 * x.dot(mean) + mean.dot(mean)) / (2 * sd2);
    double ex = Math.exp(exp);
    return ex / (std * SQRT2PI);
  }

  @Override
View Full Code Here

    for (Vector.Element element : data) {
      element.set(gen.nextDouble() < 0.3 ? 1 : 0);
    }

    double p = 1 / (1 + Math.exp(1.5 - data.dot(beta)));
    int target = 0;
    if (gen.nextDouble() < p) {
      target = 1;
    }
    return new AdaptiveLogisticRegression.TrainingExample(i, null, target, data);
View Full Code Here

        if (xi == null) {
          throw new IOException(String.format("unable to load mean path xi from %s.",
                                              pcaMeanPath.toString()));
        }

        xisquaredlen = xi.dot(xi);
        Omega omega = new Omega(seed, k + p);
        Vector s_b0 = omega.mutlithreadedTRightMultiply(xi);

        SSVDHelper.saveVector(s_b0, sbPath =
          new Path(pcaBasePath, "somega.seq"), conf);
View Full Code Here

    userIDs = dataModel.getUserIDs();
    while (userIDs.hasNext()) {
      long userID = userIDs.nextLong();
      Vector userVector = new DenseVector(factorization.getUserFeatures(userID));
      double regularization = userVector.dot(userVector);
      sum += regularization;
    }

    itemIDs = dataModel.getItemIDs();
    while (itemIDs.hasNext()) {
View Full Code Here

    itemIDs = dataModel.getItemIDs();
    while (itemIDs.hasNext()) {
      long itemID = itemIDs.nextLong();
      Vector itemVector = new DenseVector(factorization.getUserFeatures(itemID));
      double regularization = itemVector.dot(itemVector);
      sum += regularization;
    }

    double rmse = Math.sqrt(avg.getAverage());
    double loss = avg.getAverage() / 2 + lambda / 2 * sum;
 
View Full Code Here

    userIDs = dataModel.getUserIDs();
    while (userIDs.hasNext()) {
      long userID = userIDs.nextLong();
      Vector userVector = new DenseVector(factorization.getUserFeatures(userID));
      double regularization=userVector.dot(userVector);
      sum += regularization;
    }

    itemIDs = dataModel.getItemIDs();
    while (itemIDs.hasNext()) {
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.