Package org.apache.mahout.math

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


    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

  public Vector classify(Vector instance) {
    Vector result = classifyNoLink(instance);
    // Convert to probabilities by exponentiation.
    double max = result.maxValue();
    result.assign(Functions.minus(max)).assign(Functions.EXP);
    result = result.divide(result.norm(1));

    return result.viewPart(1, result.size() - 1);
  }

  @Override
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

public class SimpleEigenVerifier implements SingularVectorVerifier {

  @Override
  public EigenStatus verify(VectorIterable corpus, Vector vector) {
    Vector resultantVector = corpus.timesSquared(vector);
    double newNorm = resultantVector.norm(2);
    double oldNorm = vector.norm(2);
    double eigenValue;
    double cosAngle;
    if (newNorm > 0 && oldNorm > 0) {
      eigenValue = newNorm / oldNorm;
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

    Vector v;
    do {
      double r = rng.nextDouble();
      index = (int) (r * corpus.numRows());
      v = corpus.viewRow(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

    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

    InteractionValueEncoder enc = new InteractionValueEncoder("interactions", wv, cv);
    Vector v1 = new DenseVector(200);
    enc.addInteractionToVector("a","1.0",1.0, v1);
    int k = enc.getProbes();
    // should set k distinct locations to 1
    assertEquals((float) k, v1.norm(1), 0);
    assertEquals(1.0, v1.maxValue(), 0);

    // adding same interaction again should increment weights
    enc.addInteractionToVector("a","1.0",1.0,v1);
    assertEquals((float) k*2, v1.norm(1), 0);
View Full Code Here

    assertEquals((float) k, v1.norm(1), 0);
    assertEquals(1.0, v1.maxValue(), 0);

    // adding same interaction again should increment weights
    enc.addInteractionToVector("a","1.0",1.0,v1);
    assertEquals((float) k*2, v1.norm(1), 0);
    assertEquals(2.0, v1.maxValue(), 0);

    Vector v2 = new DenseVector(20000);
    enc.addInteractionToVector("a","1.0",1.0,v2);
    wv.addToVector("a", v2);
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.