Package org.apache.mahout.math

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


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

      context.write(key, uRowWritable); // U inherits original A row labels.
    }
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

        for (int i = 0; i < 400; i++) {
            Vector v = new DenseVector(4);
            v.assign(randomValue);

            Tuple x = new DefaultTuple();
            x.append(target[v.dot(n) > 0 ? 1 : 0]);
            x.append(PigVector.toBytes(v));
            examples.add(x);
        }
        Tuple data = new DefaultTuple();
        data.append(examples);
View Full Code Here

        plusMult.setMultiplicator(-xii);
        bCol.assign(sq, plusMult);
      }

      for (int i = 0; i < k; i++) {
        vRow.setQuick(i, bCol.dot(uHat.viewColumn(i)) / sValues.getQuick(i));
      }
      context.write(key, vRowWritable);
    }

    @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)));
        }
      }

      /*
       * MAHOUT-1067: inherit A names too.
View Full Code Here

        // Apply Householder similarity transformation
        // H = (I-u*u'/h)*H*(I-u*u')/h)

        Vector ortPiece = ort.viewPart(m, high - m + 1);
        for (int j = m; j < n; j++) {
          double f = ortPiece.dot(hessenBerg.viewColumn(j).viewPart(m, high - m + 1)) / h;
          hessenBerg.viewColumn(j).viewPart(m, high - m + 1).assign(ortPiece, Functions.plusMult(-f));
        }

        for (int i = 0; i <= high; i++) {
          double f = ortPiece.dot(hessenBerg.viewRow(i).viewPart(m, high - m + 1)) / h;
View Full Code Here

          double f = ortPiece.dot(hessenBerg.viewColumn(j).viewPart(m, high - m + 1)) / h;
          hessenBerg.viewColumn(j).viewPart(m, high - m + 1).assign(ortPiece, Functions.plusMult(-f));
        }

        for (int i = 0; i <= high; i++) {
          double f = ortPiece.dot(hessenBerg.viewRow(i).viewPart(m, high - m + 1)) / h;
          hessenBerg.viewRow(i).viewPart(m, high - m + 1).assign(ortPiece, Functions.plusMult(-f));
        }
        ort.setQuick(m, scale * ort.getQuick(m));
        hessenBerg.setQuick(m, m - 1, scale * g);
      }
View Full Code Here

   
    Vector x = new DenseVector(b.size());

    iterations = 0;
    Vector residual = b.minus(a.times(x));
    residualNormSquared = residual.dot(residual);

    log.info("Conjugate gradient initial residual norm = {}", Math.sqrt(residualNormSquared));
    double previousConditionedNormSqr = 0.0;
    Vector updateDirection = null;
    while (Math.sqrt(residualNormSquared) > maxError && iterations < maxIterations) {
View Full Code Here

    for (Vector.Element element : data.all()) {
      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

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.