Examples of DoubleMatrix1D


Examples of org.apache.mahout.math.matrix.DoubleMatrix1D

    int[] rowIndexes = new int[matrix.rows()]; // row indexes to reorder instead of matrix itself
    for (int i = rowIndexes.length; --i >= 0;) {
      rowIndexes[i] = i;
    }

    final DoubleMatrix1D col = matrix.viewColumn(column);
    IntComparator comp = new IntComparator() {
      public int compare(int a, int b) {
        double av = col.getQuick(a);
        double bv = col.getQuick(b);
        if (av != av || bv != bv) {
          return compareNaN(av, bv);
        } // swap NaNs to the end
        return av < bv ? -1 : (av == bv ? 0 : 1);
      }
View Full Code Here

Examples of org.apache.mahout.math.matrix.DoubleMatrix1D

    int[] sliceIndexes = new int[matrix.slices()]; // indexes to reorder instead of matrix itself
    for (int i = sliceIndexes.length; --i >= 0;) {
      sliceIndexes[i] = i;
    }

    final DoubleMatrix1D sliceView = matrix.viewRow(row).viewColumn(column);
    IntComparator comp = new IntComparator() {
      public int compare(int a, int b) {
        double av = sliceView.getQuick(a);
        double bv = sliceView.getQuick(b);
        if (av != av || bv != bv) {
          return compareNaN(av, bv);
        } // swap NaNs to the end
        return av < bv ? -1 : (av == bv ? 0 : 1);
      }
View Full Code Here

Examples of org.apache.mahout.math.matrix.DoubleMatrix1D

        g[c] = tmp;
      }
    };

    // compare splitter[a] with columnView[rowIndexes[b]]
    final DoubleMatrix1D columnView = matrix.viewColumn(column);
    IntComparator comp = new IntComparator() {
      public int compare(int a, int b) {
        double av = splitters[a];
        double bv = columnView.getQuick(g[b]);
        return av < bv ? -1 : (av == bv ? 0 : 1);
      }
    };

    // compare columnView[rowIndexes[a]] with columnView[rowIndexes[b]]
    IntComparator comp2 = new IntComparator() {
      public int compare(int a, int b) {
        double av = columnView.getQuick(g[a]);
        double bv = columnView.getQuick(g[b]);
        return av < bv ? -1 : (av == bv ? 0 : 1);
      }
    };

    // compare splitter[a] with splitter[b]
View Full Code Here

Examples of org.apache.mahout.math.matrix.DoubleMatrix1D

    if (isNoView && other.isNoView) { // quickest
      System.arraycopy(other.elements, 0, this.elements, 0, this.elements.length);
      return this;
    }
    if (haveSharedCells(other)) {
      DoubleMatrix1D c = other.copy();
      if (!(c instanceof DenseDoubleMatrix1D)) { // should not happen
        return super.assign(source);
      }
      other = (DenseDoubleMatrix1D) c;
    }
View Full Code Here

Examples of org.apache.mahout.math.matrix.DoubleMatrix1D

      LUrows[i] = LU.viewRow(i);
    }

    IntArrayList nonZeroIndexes =
        new IntArrayList(); // sparsity
    DoubleMatrix1D LUcolj = LU.viewColumn(0).like()// blocked column j
    Mult multFunction = Mult.mult(0);

    // Outer loop.
    int CUT_OFF = 10;
    for (int j = 0; j < n; j++) {
      // blocking (make copy of j-th column to localize references)
      LUcolj.assign(LU.viewColumn(j));

      // sparsity detection
      int maxCardinality = m / CUT_OFF; // == heuristic depending on speedup
      LUcolj.getNonZeros(nonZeroIndexes, null, maxCardinality);
      int cardinality = nonZeroIndexes.size();
      boolean sparse = (cardinality < maxCardinality);

      // Apply previous transformations.
      for (int i = 0; i < m; i++) {
        int kmax = Math.min(i, j);
        double s;
        if (sparse) {
          s = LUrows[i].zDotProduct(LUcolj, 0, kmax, nonZeroIndexes);
        } else {
          s = LUrows[i].zDotProduct(LUcolj, 0, kmax);
        }
        double before = LUcolj.getQuick(i);
        double after = before - s;
        LUcolj.setQuick(i, after); // LUcolj is a copy
        LU.setQuick(i, j, after);   // this is the original
        if (sparse) {
          if (before == 0 && after != 0) { // nasty bug fixed!
            int pos = nonZeroIndexes.binarySearch(i);
            pos = -pos - 1;
            nonZeroIndexes.beforeInsert(pos, i);
          }
          if (before != 0 && after == 0) {
            nonZeroIndexes.remove(nonZeroIndexes.binarySearch(i));
          }
        }
      }

      // Find pivot and exchange if necessary.
      int p = j;
      if (p < m) {
        double max = Math.abs(LUcolj.getQuick(p));
        for (int i = j + 1; i < m; i++) {
          double v = Math.abs(LUcolj.getQuick(i));
          if (v > max) {
            p = i;
            max = v;
          }
        }
View Full Code Here

Examples of org.apache.mahout.math.matrix.DoubleMatrix1D

    Mult div = Mult.div(0);
    PlusMult minusMult = PlusMult.minusMult(0);

    IntArrayList nonZeroIndexes =
        new IntArrayList(); // sparsity
    DoubleMatrix1D Browk = org.apache.mahout.math.matrix.DoubleFactory1D.dense.make(nx); // blocked row k

    // Solve L*Y = B(piv,:)
    int CUT_OFF = 10;
    for (int k = 0; k < n; k++) {
      // blocking (make copy of k-th row to localize references)
      Browk.assign(Brows[k]);

      // sparsity detection
      int maxCardinality = nx / CUT_OFF; // == heuristic depending on speedup
      Browk.getNonZeros(nonZeroIndexes, null, maxCardinality);
      int cardinality = nonZeroIndexes.size();
      boolean sparse = (cardinality < maxCardinality);

      for (int i = k + 1; i < n; i++) {
        //for (int j = 0; j < nx; j++) B[i][j] -= B[k][j]*LU[i][k];
        //for (int j = 0; j < nx; j++) B.set(i,j, B.get(i,j) - B.get(k,j)*LU.get(i,k));

        minusMult.setMultiplicator(-LU.getQuick(i, k));
        if (minusMult.getMultiplicator() != 0) {
          if (sparse) {
            Brows[i].assign(Browk, minusMult, nonZeroIndexes);
          } else {
            Brows[i].assign(Browk, minusMult);
          }
        }
      }
    }

    // Solve U*B = Y;
    for (int k = n - 1; k >= 0; k--) {
      // for (int j = 0; j < nx; j++) B[k][j] /= LU[k][k];
      // for (int j = 0; j < nx; j++) B.set(k,j, B.get(k,j) / LU.get(k,k));
      div.setMultiplicator(1 / LU.getQuick(k, k));
      Brows[k].assign(div);

      // blocking
      if (Browk == null) {
        Browk = org.apache.mahout.math.matrix.DoubleFactory1D.dense.make(B.columns());
      }
      Browk.assign(Brows[k]);

      // sparsity detection
      int maxCardinality = nx / CUT_OFF; // == heuristic depending on speedup
      Browk.getNonZeros(nonZeroIndexes, null, maxCardinality);
      int cardinality = nonZeroIndexes.size();
      boolean sparse = (cardinality < maxCardinality);

      //Browk.getNonZeros(nonZeroIndexes,null);
      //boolean sparse = nonZeroIndexes.size() < nx/10;
View Full Code Here

Examples of org.apache.mahout.math.matrix.DoubleMatrix1D

        QR.setQuick(k, k, QR.getQuick(k, k) + 1);

        // Apply transformation to remaining columns.
        for (int j = k + 1; j < n; j++) {
          DoubleMatrix1D QRcolj = QR.viewColumn(j).viewPart(k, m - k);
          double s = QRcolumnsPart[k].zDotProduct(QRcolj);
          /*
          // fixes bug reported by John Chambers
          DoubleMatrix1D QRcolj = QR.viewColumn(j).viewPart(k,m-k);
          double s = QRcolumnsPart[k].zDotProduct(QRcolumns[j]);
View Full Code Here

Examples of org.apache.mahout.math.matrix.DoubleMatrix1D

   */
  public DoubleMatrix2D getQ() {
    DoubleMatrix2D Q = QR.like();
    //double[][] Q = X.getArray();
    for (int k = n - 1; k >= 0; k--) {
      DoubleMatrix1D QRcolk = QR.viewColumn(k).viewPart(k, m - k);
      Q.setQuick(k, k, 1);
      for (int j = k; j < n; j++) {
        if (QR.getQuick(k, k) != 0) {
          DoubleMatrix1D Qcolj = Q.viewColumn(j).viewPart(k, m - k);
          double s = QRcolk.zDotProduct(Qcolj);
          s = -s / QR.getQuick(k, k);
          Qcolj.assign(QRcolk, Functions.plusMult(s));
        }
      }
    }
    return Q;
  }
View Full Code Here

Examples of org.apache.mahout.math.matrix.DoubleMatrix1D

    log.info("Lanczos iteration complete - now to diagonalize the tri-diagonal auxiliary matrix.");
    // at this point, have tridiag all filled out, and basis is all filled out, and orthonormalized
    EigenvalueDecomposition decomp = new EigenvalueDecomposition(triDiag);

    DoubleMatrix2D eigenVects = decomp.getV();
    DoubleMatrix1D eigenVals = decomp.getRealEigenvalues();
    endTime(TimingSection.TRIDIAG_DECOMP);
    startTime(TimingSection.FINAL_EIGEN_CREATE);

    for (int i = 0; i < basis.numRows() - 1; i++) {
      Vector realEigen = new DenseVector(corpus.numCols());
      // the eigenvectors live as columns of V, in reverse order.  Weird but true.
      DoubleMatrix1D ejCol = eigenVects.viewColumn(basis.numRows() - i - 1);
      for (int j = 0; j < ejCol.size(); j++) {
        double d = ejCol.getQuick(j);
        realEigen.assign(basis.getRow(j), new PlusMult(d));
      }
      realEigen = realEigen.normalize();
      eigenVectors.assignRow(i, realEigen);
      log.info("Eigenvector {} found with eigenvalue {}", i, eigenVals.get(i));
View Full Code Here

Examples of org.apache.mahout.math.matrix.DoubleMatrix1D

   * @throws IndexOutOfBoundsException if <tt>index<0 || width<0 || index+width>size()</tt>.
   */
  @Override
  public DoubleMatrix1D viewPart(final int index, int width) {
    checkRange(index, width);
    DoubleMatrix1D view = new WrapperDoubleMatrix1D(this) {
      @Override
      public double getQuick(int i) {
        return content.get(index + i);
      }

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.