@Override public double[] getVariances() { return svd.getS(); }
private void runSVD() { int gramDimension = gramMatrix.numRows(); try { svd = new no.uib.cipr.matrix.SVD(gramDimension, gramDimension).factor(gramMatrix); } catch (NotConvergedException e) { throw new RuntimeException(e); } double[] Vt_1D = svd.getVt().getData(); rightEigenvectors = LinearAlgebraUtils.reshape1DArray(Vt_1D, gramDimension, gramDimension); } }
DenseMatrix matA = inputs[0].getOriginal(); no.uib.cipr.matrix.SVD svd = new no.uib.cipr.matrix.SVD(matA.numRows(),matA.numColumns()); DenseMatrix tmp = new DenseMatrix(matA); SVD s = svd.factor(tmp); U = s.getU(); S = s.getS(); Vt = s.getVt(); } catch (NotConvergedException e) { throw new RuntimeException(e);
private void estimate_internal(Matrix y, Matrix x) { try { final no.uib.cipr.matrix.DenseMatrix mjtX = new no.uib.cipr.matrix.DenseMatrix(x.getArray()); no.uib.cipr.matrix.SVD svd; svd = no.uib.cipr.matrix.SVD.factorize(mjtX); final Matrix u = MatrixUtils.convert(svd.getU(), svd.getU().numRows(), svd.getS().length); final Matrix v = MatrixUtils.convert(svd.getVt(), svd.getS().length, svd.getVt().numColumns()).transpose(); final Matrix d = MatrixUtils.diag(svd.getS()); weights = v.times(MatrixUtils.pseudoInverse(d)).times(u.transpose()).times(y); } catch (final NotConvergedException e) { throw new RuntimeException(e.getMessage()); } }
/** * Convenience method for computing a full SVD * * @param A * Matrix to decompose, not modified * @return Newly allocated factorization * @throws NotConvergedException */ public static SVD factorize(Matrix A) throws NotConvergedException { return new SVD(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
/** * Solves the system <code>Ax = 0</code>, returning the vector x as an array. * Internally computes the least-squares solution using the SVD of * <code>A</code>. * * @param A * the matrix describing the system * @return the solution vector */ public static double[] solveHomogeneousSystem(DenseMatrix A) { try { final SVD svd = SVD.factorize(A); final double[] x = new double[svd.getVt().numRows()]; final int c = svd.getVt().numColumns() - 1; for (int i = 0; i < x.length; i++) { x[i] = svd.getVt().get(c, i); } return x; } catch (final NotConvergedException e) { throw new RuntimeException(e); } }
new no.uib.cipr.matrix.SVD( numRows, numColumns ); internalSVD.factor( new no.uib.cipr.matrix.DenseMatrix( matrix.getInternalMatrix() ) ); DenseMatrix U = matrixFactory.createWrapper( internalSVD.getU() ); double[] singularValues = internalSVD.getS(); int numSingular = singularValues.length; DenseMatrix S = matrixFactory.createMatrix( numRows, numColumns ); internalSVD.getVt() );
public Matrix[] calc(Matrix source) { try { DenseMatrix m = null; if (source instanceof MTJDenseDoubleMatrix2D) { m = ((MTJDenseDoubleMatrix2D) source).getWrappedObject(); } else { m = new MTJDenseDoubleMatrix2D(source).getWrappedObject(); } no.uib.cipr.matrix.SVD svd = no.uib.cipr.matrix.SVD.factorize(m); Matrix u = new MTJDenseDoubleMatrix2D(svd.getU()); Matrix v = new MTJDenseDoubleMatrix2D(svd.getVt()).transpose(); double[] svs = svd.getS(); Matrix s = SparseDoubleMatrix2D.Factory.zeros(source.getSize()); for (int i = (int) Math.min(s.getRowCount(), s.getColumnCount()); --i >= 0;) { s.setAsDouble(svs[i], i, i); } return new Matrix[] { u, s, v }; } catch (Exception e) { throw new RuntimeException(e); } } }
/** * Convenience method for computing a full SVD * * @param A * Matrix to decompose, not modified * @return Newly allocated factorization * @throws NotConvergedException */ public static SVD factorize(Matrix A) throws NotConvergedException { return new SVD(A.numRows(), A.numColumns()).factor(new DenseMatrix(A)); }
new no.uib.cipr.matrix.SVD( numRows, numColumns ); internalSVD.factor( new no.uib.cipr.matrix.DenseMatrix( matrix.getInternalMatrix() ) ); DenseMatrix U = matrixFactory.createWrapper( internalSVD.getU() ); double[] singularValues = internalSVD.getS(); int numSingular = singularValues.length; DenseMatrix S = matrixFactory.createMatrix( numRows, numColumns ); internalSVD.getVt() );
svd = no.uib.cipr.matrix.SVD.factorize(mjtA); } catch (final NotConvergedException e) { throw new RuntimeException(e); final double[] Sarr = svd.getS(); for (int i = 0; i < svd.getS().length; i++) { if (Sarr[i] != 0) Sinv.set(i, i, 1.0 / Sarr[i]); final Matrix Vt = new Matrix(svd.getVt().numRows(), svd.getVt().numColumns()); for (int r = 0; r < svd.getVt().numRows(); r++) { for (int c = 0; c < svd.getVt().numColumns(); c++) { Vt.set(r, c, svd.getVt().get(r, c)); final Matrix U = new Matrix(svd.getU().numRows(), svd.getU().numColumns()); for (int r = 0; r < svd.getU().numRows(); r++) { for (int c = 0; c < svd.getU().numColumns(); c++) { U.set(r, c, svd.getU().get(r, c));
private void runSVD() { int gramDimension = gramMatrix.numRows(); try { svd = new no.uib.cipr.matrix.SVD(gramDimension, gramDimension).factor(gramMatrix); } catch (NotConvergedException e) { throw new RuntimeException(e); } double[] Vt_1D = svd.getVt().getData(); rightEigenvectors = LinearAlgebraUtils.reshape1DArray(Vt_1D, gramDimension, gramDimension); } }
@Override public double[] getVariances() { return svd.getS(); }
new no.uib.cipr.matrix.SVD( numRows, numColumns ); internalSVD.factor( new no.uib.cipr.matrix.DenseMatrix( matrix.getInternalMatrix() ) ); DenseMatrix U = matrixFactory.createWrapper( internalSVD.getU() ); double[] singularValues = internalSVD.getS(); int numSingular = singularValues.length; DenseMatrix S = matrixFactory.createMatrix( numRows, numColumns ); internalSVD.getVt() );
public Matrix[] calc(Matrix source) { try { DenseMatrix m = null; if (source instanceof MTJDenseDoubleMatrix2D) { m = ((MTJDenseDoubleMatrix2D) source).getWrappedObject(); } else { m = new MTJDenseDoubleMatrix2D(source).getWrappedObject(); } no.uib.cipr.matrix.SVD svd = no.uib.cipr.matrix.SVD.factorize(m); Matrix u = new MTJDenseDoubleMatrix2D(svd.getU()); Matrix v = new MTJDenseDoubleMatrix2D(svd.getVt()).transpose(); double[] svs = svd.getS(); Matrix s = SparseDoubleMatrix2D.Factory.zeros(source.getSize()); for (int i = (int) Math.min(s.getRowCount(), s.getColumnCount()); --i >= 0;) { s.setAsDouble(svs[i], i, i); } return new Matrix[] { u, s, v }; } catch (Exception e) { throw new RuntimeException(e); } } }
no.uib.cipr.matrix.SVD svd; try { svd = no.uib.cipr.matrix.SVD.factorize(mjtA); } catch (final NotConvergedException e) { throw new RuntimeException(e); final DenseMatrix U = svd.getU(); final DenseMatrix Vt = svd.getVt(); final double[] svector = svd.getS(); final DenseMatrix S = new DenseMatrix(U.numColumns(), Vt.numRows()); for (int i = 0; i < rank; i++)