/** * Returns the rank of the decomposed matrix. * * @see SingularOps#rank(org.ejml.interfaces.decomposition.SingularValueDecomposition, double) * * @return The matrix's rank */ public int rank() { return SingularOps.rank(svd,10.0* UtilEjml.EPS); }
/** * Returns the rank of the decomposed matrix. * * @see SingularOps#rank(org.ejml.interfaces.decomposition.SingularValueDecomposition, double) * * @return The matrix's rank */ public int rank() { return SingularOps.rank(svd,10.0* UtilEjml.EPS); }
/** * Returns the rank of the decomposed matrix. * * @see SingularOps#rank(org.ejml.interfaces.decomposition.SingularValueDecomposition, double) * * @return The matrix's rank */ public int rank() { return SingularOps.rank(svd,tol); }
/** * Extracts the rank of a matrix using a preexisting decomposition and default threshold. * * @see #singularThreshold(org.ejml.interfaces.decomposition.SingularValueDecomposition) * * @param svd A precomputed decomposition. Not modified. * @return The rank of the decomposed matrix. */ public static int rank( SingularValueDecomposition svd ) { double threshold = singularThreshold(svd); return rank(svd,threshold); }
/** * Computes the rank of a matrix using the specified tolerance. * * @param A Matrix whose rank is to be calculated. Not modified. * @param threshold The numerical threshold used to determine a singular value. * @return The matrix's rank. */ public static int rank( DenseMatrix64F A , double threshold ) { SingularValueDecomposition<DenseMatrix64F> svd = DecompositionFactory.svd(A.numRows,A.numCols,false,false,true); if( svd.inputModified() ) A = A.copy(); if( !svd.decompose(A) ) throw new RuntimeException("Decomposition failed"); return SingularOps.rank(svd, threshold); }
/** * Computes the rank of a matrix using the specified tolerance. * * @param A Matrix whose rank is to be calculated. Not modified. * @param threshold The numerical threshold used to determine a singular value. * @return The matrix's rank. */ public static int rank( DenseMatrix64F A , double threshold ) { SingularValueDecomposition<DenseMatrix64F> svd = DecompositionFactory.svd(A.numRows,A.numCols,false,false,true); if( svd.inputModified() ) A = A.copy(); if( !svd.decompose(A) ) throw new RuntimeException("Decomposition failed"); return SingularOps.rank(svd, threshold); }
/** * Computes the rank of a matrix using the specified tolerance. * * @param A Matrix whose rank is to be calculated. Not modified. * @param threshold The numerical threshold used to determine a singular value. * @return The matrix's rank. */ public static int rank( DenseMatrix64F A , double threshold ) { SingularValueDecomposition<DenseMatrix64F> svd = DecompositionFactory.svd(A.numRows,A.numCols,false,false,true); if( svd.inputModified() ) A = A.copy(); if( !svd.decompose(A) ) throw new RuntimeException("Decomposition failed"); return SingularOps.rank(svd, threshold); }
int n = SingularOps.rank(svd,1e-12);
int n = SingularOps.rank(svd,1e-12);
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout = 30000) public void zeroMatrixSVD(){ DenseMatrix64F []testMatrices = new DenseMatrix64F[]{ RandomMatrices.createRandom(2, 2, new Random()), new DenseMatrix64F(2,2), new DenseMatrix64F(new double[][]{{1,1},{0,0}}) }; for(int i=0;i<testMatrices.length;i++) { DenseMatrix64F testMatrix = testMatrices[i]; System.out.println("Matrix "+ i + testMatrix); SolvePseudoInverseSvd svdPseudoInverseSolver = new SolvePseudoInverseSvd(testMatrix.numRows, testMatrix.numCols); boolean setAResult=svdPseudoInverseSolver.setA(new DenseMatrix64F(testMatrix)); int rank=SingularOps.rank(svdPseudoInverseSolver.getDecomposer(), 1e-10); System.out.println("Singular Values: "+ Arrays.toString(svdPseudoInverseSolver.getDecomposer().getSingularValues())); System.out.println("setA="+setAResult + " rank="+ rank); System.out.println("----------------------------------------------------------------------------------------------------"); } }
int n = SingularOps.rank(svd,1e-12);
int rank = SingularOps.rank(svdU, 1e-13); Up.reshape(U.numRows,rank); CommonOps.extract(U,0,U.numRows,0,Up.numCols,Up,0,0);