/** * Returns the rank of the decomposed matrix. * * @see SingularOps_DDRM#rank(SingularValueDecomposition_F64, double) * * @return The matrix's rank */ public int rank() { if (is64) { return(SingularOps_DDRM.rank((SingularValueDecomposition_F64 <DMatrixRMaj>)svd, tol)); } else { return(SingularOps_FDRM.rank((SingularValueDecomposition_F32 <FMatrixRMaj>)svd, (float)tol)); } }
/** * The nullity of the decomposed matrix. * * @see SingularOps_DDRM#nullity(SingularValueDecomposition_F64, double) * * @return The matrix's nullity */ public int nullity() { if (is64) { return(SingularOps_DDRM.nullity((SingularValueDecomposition_F64 <DMatrixRMaj>)svd, 10.0 * UtilEjml.EPS)); } else { return(SingularOps_FDRM.nullity((SingularValueDecomposition_F32 <FMatrixRMaj>)svd, 5.0f * UtilEjml.F_EPS)); } }
public /**/ double quality() { if (is64) { var m = mat as DMatrixRMaj; var um = U.getMatrix() as DMatrixRMaj; var wm = W.getMatrix() as DMatrixRMaj; var vmt = V.transpose().getMatrix() as DMatrixRMaj; return(DecompositionFactory_DDRM.quality(m, um, wm, vmt)); } else { var m = mat as FMatrixRMaj; var um = U.getMatrix() as FMatrixRMaj; var wm = W.getMatrix() as FMatrixRMaj; var vmt = V.transpose().getMatrix() as FMatrixRMaj; return(DecompositionFactory_FDRM.quality(m, um, wm, vmt)); } } /** * Computes the null space from an SVD. For more information see {@link SingularOps_DDRM#nullSpace}. * @return Null space vector. */ public SimpleMatrix <T> nullSpace() { // TODO take advantage of the singular values being ordered already if (is64) { var ns = SingularOps_DDRM.nullSpace((SingularValueDecomposition_F64 <DMatrixRMaj>)svd, null, tol); return(SimpleMatrix <T> .wrap(ns as T)); } else { var ns = SingularOps_FDRM.nullSpace((SingularValueDecomposition_F32 <FMatrixRMaj>)svd, null, (float)tol); return(SimpleMatrix <T> .wrap(ns as T)); } }
public SimpleSVD(Matrix mat, bool compact) { this.mat = mat; this.is64 = mat is DMatrixRMaj; if (is64) { DMatrixRMaj m = (DMatrixRMaj)mat; svd = (SingularValueDecomposition <T>)DecompositionFactory_DDRM.svd(m.numRows, m.numCols, true, true, compact); } else { FMatrixRMaj m = (FMatrixRMaj)mat; svd = (SingularValueDecomposition <T>)DecompositionFactory_FDRM.svd(m.numRows, m.numCols, true, true, compact); } if (!svd.decompose((T)mat)) { throw new InvalidOperationException("Decomposition failed"); } U = SimpleMatrix <T> .wrap(svd.getU(null, false)); W = SimpleMatrix <T> .wrap(svd.getW(null)); V = SimpleMatrix <T> .wrap(svd.getV(null, false)); // order singular values from largest to smallest if (is64) { var um = U.getMatrix() as DMatrixRMaj; var wm = W.getMatrix() as DMatrixRMaj; var vm = V.getMatrix() as DMatrixRMaj; SingularOps_DDRM.descendingOrder(um, false, wm, vm, false); tol = SingularOps_DDRM.singularThreshold((SingularValueDecomposition_F64 <DMatrixRMaj>)svd); } else { var um = U.getMatrix() as FMatrixRMaj; var wm = W.getMatrix() as FMatrixRMaj; var vm = V.getMatrix() as FMatrixRMaj; SingularOps_FDRM.descendingOrder(um, false, wm, vm, false); tol = SingularOps_FDRM.singularThreshold((SingularValueDecomposition_F32 <FMatrixRMaj>)svd); } }