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); } }
/** * 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); } }
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); } }
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()); } }
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); } } }
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); } } }
U = s.getU(); S = s.getS(); Vt = s.getVt(); } catch (NotConvergedException e) { throw new RuntimeException(e);
final DenseMatrix Vt = svd.getVt(); final double[] svector = svd.getS(); final DenseMatrix S = new DenseMatrix(U.numColumns(), Vt.numRows());
internalSVD.getVt() );
internalSVD.getVt() );
internalSVD.getVt() );