Skip to content

Commit

Permalink
easy to use nullity
Browse files Browse the repository at this point in the history
  • Loading branch information
lessthanoptimal committed Nov 11, 2018
1 parent 4d6236d commit 70aa741
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions main/ejml-ddense/src/org/ejml/dense/row/SingularOps_DDRM.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,4 +656,32 @@ public static int nullity(SingularValueDecomposition_F64 svd , double threshold
}
return ret + numCol-N;
}

/**
* Returns the matrix's nullity
*
* @param A Matrix. Not modified.
* @param threshold Tolerance used to determine of a singular value is singular.
* @return nullity
*/
public static int nullity( DMatrixRMaj A , double threshold ) {
SingularValueDecomposition_F64<DMatrixRMaj> svd = DecompositionFactory_DDRM.svd(A.numRows,A.numCols,false,true,true);

if( svd.inputModified() ) {
A = A.copy();
}
if( !svd.decompose(A)) {
throw new RuntimeException("SVD Failed!");
}

double sv[] = svd.getSingularValues();

int count = 0;
for (int i = 0; i < sv.length; i++) {
if( sv[i] <= threshold ) {
count++;
}
}
return count;
}
}

0 comments on commit 70aa741

Please sign in to comment.