Package org.apache.mahout.math.matrix.impl

Examples of org.apache.mahout.math.matrix.impl.DenseDoubleMatrix2D


    double[] aggregates = new double[aggregatesRaw.length];
    for (int i = 0; i < aggregatesRaw.length; i++) {
      aggregates[i] = Double.longBitsToDouble(aggregatesRaw[i]);
    }

    DoubleMatrix2D VT = new DenseDoubleMatrix2D(convert(new long[][]{
        {4540286548932058396L, 4577864022762482570L, 4577700324701750780L, 4518480992251412349L, 4556435725689022825L,
            4488720014619835766L, 4335660689431780693L, 4502946434618942000L, 4531841594141675072L,
            4445484354574431038L, 4494181495103148132L, 4238500868784003636L, 4410983210480467520L,
            4378527886946299824L, 4535843255558462101L, 4533033844134633147L, 4588065853673790470L,
            4529714837625705005L, 4545016130375436933L, 4534987086323522839L, 4499740291369705403L,
View Full Code Here


    int m = rows;
    int n = columns;
    int p = B.columns;

    if (C == null) {
      C = new DenseDoubleMatrix2D(m, p);
    }
    if (B.rows != n) {
      throw new IllegalArgumentException(
          "Matrix2D inner dimensions must agree:" + toStringShort() + ", " + B.toStringShort());
    }
View Full Code Here

   * @return the covariance matrix (<tt>n x n, n=matrix.columns</tt>).
   */
  public static DoubleMatrix2D covariance(DoubleMatrix2D matrix) {
    int rows = matrix.rows();
    int columns = matrix.columns();
    DoubleMatrix2D covariance = new DenseDoubleMatrix2D(columns, columns);

    double[] sums = new double[columns];
    DoubleMatrix1D[] cols = new DoubleMatrix1D[columns];
    for (int i = columns; --i >= 0;) {
      cols[i] = matrix.viewColumn(i);
      sums[i] = cols[i].zSum();
    }

    for (int i = columns; --i >= 0;) {
      for (int j = i + 1; --j >= 0;) {
        double sumOfProducts = cols[i].zDotProduct(cols[j]);
        double cov = (sumOfProducts - sums[i] * sums[j] / rows) / rows;
        covariance.setQuick(i, j, cov);
        covariance.setQuick(j, i, cov); // symmetric
      }
    }
    return covariance;
  }
View Full Code Here

   * @param distanceFunction (EUCLID, CANBERRA, ..., or any user defined distance function operating on two vectors).
   * @return the distance matrix (<tt>n x n, n=matrix.columns</tt>).
   */
  public static DoubleMatrix2D distance(DoubleMatrix2D matrix, VectorVectorFunction distanceFunction) {
    int columns = matrix.columns();
    DoubleMatrix2D distance = new DenseDoubleMatrix2D(columns, columns);

    // cache views
    DoubleMatrix1D[] cols = new DoubleMatrix1D[columns];
    for (int i = columns; --i >= 0;) {
      cols[i] = matrix.viewColumn(i);
    }

    // work out all permutations
    for (int i = columns; --i >= 0;) {
      for (int j = i; --j >= 0;) {
        double d = distanceFunction.apply(cols[i], cols[j]);
        distance.setQuick(i, j, d);
        distance.setQuick(j, i, d); // symmetric
      }
    }
    return distance;
  }
View Full Code Here

    Vector previousVector = new DenseVector(currentVector.size());
    Matrix basis = new SparseRowMatrix(new int[]{desiredRank, corpus.numCols()});
    basis.assignRow(0, currentVector);
    double alpha = 0;
    double beta = 0;
    DoubleMatrix2D triDiag = new DenseDoubleMatrix2D(desiredRank, desiredRank);
    for (int i = 1; i < desiredRank; i++) {
      startTime(TimingSection.ITERATE);
      Vector nextVector = isSymmetric ? corpus.times(currentVector) : corpus.timesSquared(currentVector);
      log.info("{} passes through the corpus so far...", i);
      calculateScaleFactor(nextVector);
      nextVector.assign(new Scale(1 / scaleFactor));
      nextVector.assign(previousVector, new PlusMult(-beta));
      // now orthogonalize
      alpha = currentVector.dot(nextVector);
      nextVector.assign(currentVector, new PlusMult(-alpha));
      endTime(TimingSection.ITERATE);
      startTime(TimingSection.ORTHOGANLIZE);
      orthoganalizeAgainstAllButLast(nextVector, basis);
      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;
      }
      final double b = beta;
      nextVector.assign(new Scale(1 / b));
      basis.assignRow(i, nextVector);
      previousVector = currentVector;
      currentVector = nextVector;
      // save the projections and norms!
      triDiag.set(i - 1, i - 1, alpha);
      if (i < desiredRank - 1) {
        triDiag.set(i - 1, i, beta);
        triDiag.set(i, i - 1, beta);
      }
    }
    startTime(TimingSection.TRIDIAG_DECOMP);

    log.info("Lanczos iteration complete - now to diagonalize the tri-diagonal auxiliary matrix.");
View Full Code Here

   */
  public DoubleMatrix2D make(double[][] values) {
    if (this == sparse) {
      return new SparseDoubleMatrix2D(values);
    } else {
      return new DenseDoubleMatrix2D(values);
    }
  }
View Full Code Here

    if (this == rowCompressed) {
      return new RCDoubleMatrix2D(rows, columns);
    }
    //if (this==rowCompressedModified) return new RCMDoubleMatrix2D(rows,columns);
    else {
      return new DenseDoubleMatrix2D(rows, columns);
    }
  }
View Full Code Here

    int m = rows;
    int n = columns;
    int p = B.columns;

    if (C == null) {
      C = new DenseDoubleMatrix2D(m, p);
    }
    if (B.rows != n) {
      throw new IllegalArgumentException("Matrix2D inner dimensions must agree");
    }
    if (C.rows != m || C.columns != p) {
View Full Code Here

        D[i][i + 1] = e[i];
      } else if (e[i] < 0) {
        D[i][i - 1] = e[i];
      }
    }
    return new DenseDoubleMatrix2D(D);
  }
View Full Code Here

   * Returns the eigenvector matrix, <tt>V</tt>
   *
   * @return <tt>V</tt>
   */
  public DoubleMatrix2D getV() {
    return new DenseDoubleMatrix2D(V);
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.matrix.impl.DenseDoubleMatrix2D

Copyright © 2018 www.massapicom. 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.