Package org.apache.mahout.math

Examples of org.apache.mahout.math.CholeskyDecomposition


  public SequentialBigSvd(Matrix A, int p) {
    // Y = A * \Omega
    y = A.times(new RandomTrinaryMatrix(A.columnSize(), p));

    // R'R = Y' Y
    cd1 = new CholeskyDecomposition(y.transpose().times(y));

    // B = Q" A = (Y R^{-1} )' A
    b = cd1.solveRight(y).transpose().times(A);

    // L L' = B B'
    cd2 = new CholeskyDecomposition(b.times(b.transpose()));

    // U_0 D V_0' = L
    svd = new SingularValueDecomposition(cd2.getL());
  }
View Full Code Here


        y2 = y.transpose().times(y);
      } else {
        y2.assign(y.transpose().times(y), Functions.PLUS);
      }
    }
    r2 = new CholeskyDecomposition(y2);

    // step 2, compute B
    int ncols = 0;
    for (File file : partsOfA) {
      MatrixWritable m = new MatrixWritable();
      DataInputStream in = new DataInputStream(new FileInputStream(file));
      try {
        m.readFields(in);
      } finally {
        in.close();
      }
      Matrix aI = m.get();
      ncols = Math.max(ncols, aI.columnSize());

      Matrix omega = new RandomTrinaryMatrix(seed, aI.numCols(), internalDimension, false);
      for (int j = 0; j < aI.numCols(); j += columnsPerSlice) {
        Matrix yI = aI.times(omega);
        Matrix aIJ = aI.viewPart(0, aI.rowSize(), j, Math.min(columnsPerSlice, aI.columnSize() - j));
        Matrix bIJ = r2.solveRight(yI).transpose().times(aIJ);
        addToSavedCopy(bFile(tmpDir, j), bIJ);
      }
    }

    // step 3, compute BB', L and SVD(L)
    Matrix b2 = new DenseMatrix(internalDimension, internalDimension);
    MatrixWritable bTmp = new MatrixWritable();
    for (int j = 0; j < ncols; j += columnsPerSlice) {
      if (bFile(tmpDir, j).exists()) {
        DataInputStream in = new DataInputStream(new FileInputStream(bFile(tmpDir, j)));
        try {
          bTmp.readFields(in);
        } finally {
          in.close();
        }

        b2.assign(bTmp.get().times(bTmp.get().transpose()), Functions.PLUS);
      }
    }
    l2 = new CholeskyDecomposition(b2);
    svd = new SingularValueDecomposition(l2.getL());
  }
View Full Code Here

        y2 = y.transpose().times(y);
      } else {
        y2.assign(y.transpose().times(y), Functions.PLUS);
      }
    }
    r2 = new CholeskyDecomposition(y2);

    // step 2, compute B
    int ncols = 0;
    for (File file : partsOfA) {
      MatrixWritable m = new MatrixWritable();
      DataInputStream in = new DataInputStream(new FileInputStream(file));
      try {
        m.readFields(in);
      } finally {
        in.close();
      }
      Matrix aI = m.get();
      ncols = Math.max(ncols, aI.columnSize());

      Matrix omega = new RandomTrinaryMatrix(seed, aI.numCols(), internalDimension, false);
      for (int j = 0; j < aI.numCols(); j += columnsPerSlice) {
        Matrix yI = aI.times(omega);
        Matrix aIJ = aI.viewPart(0, aI.rowSize(), j, Math.min(columnsPerSlice, aI.columnSize() - j));
        Matrix bIJ = r2.solveRight(yI).transpose().times(aIJ);
        addToSavedCopy(bFile(tmpDir, j), bIJ);
      }
    }

    // step 3, compute BB', L and SVD(L)
    Matrix b2 = new DenseMatrix(internalDimension, internalDimension);
    MatrixWritable bTmp = new MatrixWritable();
    for (int j = 0; j < ncols; j += columnsPerSlice) {
      if (bFile(tmpDir, j).exists()) {
        DataInputStream in = new DataInputStream(new FileInputStream(bFile(tmpDir, j)));
        try {
          bTmp.readFields(in);
        } finally {
          in.close();
        }

        b2.assign(bTmp.get().times(bTmp.get().transpose()), Functions.PLUS);
      }
    }
    l2 = new CholeskyDecomposition(b2);
    svd = new SingularValueDecomposition(l2.getL());
  }
View Full Code Here

        y2 = y.transpose().times(y);
      } else {
        y2.assign(y.transpose().times(y), Functions.PLUS);
      }
    }
    r2 = new CholeskyDecomposition(y2);

    // step 2, compute B
    int ncols = 0;
    for (File file : partsOfA) {
      MatrixWritable m = new MatrixWritable();
      final DataInputStream in = new DataInputStream(new FileInputStream(file));
      try {
        m.readFields(in);
      } finally {
        in.close();
      }
      Matrix aI = m.get();
      ncols = Math.max(ncols, aI.columnSize());

      Matrix omega = new RandomTrinaryMatrix(seed, aI.numCols(), internalDimension, false);
      for (int j = 0; j < aI.numCols(); j += columnsPerSlice) {
        Matrix yI = aI.times(omega);
        Matrix aIJ = aI.viewPart(0, aI.rowSize(), j, Math.min(columnsPerSlice, aI.columnSize() - j));
        Matrix bIJ = r2.solveRight(yI).transpose().times(aIJ);
        addToSavedCopy(bFile(tmpDir, j), bIJ);
      }
    }

    // step 3, compute BB', L and SVD(L)
    Matrix b2 = new DenseMatrix(internalDimension, internalDimension);
    MatrixWritable bTmp = new MatrixWritable();
    for (int j = 0; j < ncols; j += columnsPerSlice) {
      if (bFile(tmpDir, j).exists()) {
        final DataInputStream in = new DataInputStream(new FileInputStream(bFile(tmpDir, j)));
        try {
          bTmp.readFields(in);
        } finally {
          in.close();
        }

        b2.assign(bTmp.get().times(bTmp.get().transpose()), Functions.PLUS);
      }
    }
    l2 = new CholeskyDecomposition(b2);
    svd = new SingularValueDecomposition(l2.getL());
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.math.CholeskyDecomposition

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.