public static double quality(DMatrixRMaj orig, DMatrixRMaj U, DMatrixRMaj W, DMatrixRMaj Vt) { // foundA = U*W*Vt DMatrixRMaj UW = new DMatrixRMaj(U.numRows, W.numCols); CommonOps_DDRM.mult(U, W, UW); DMatrixRMaj foundA = new DMatrixRMaj(UW.numRows, Vt.numCols); CommonOps_DDRM.mult(UW, Vt, foundA); double normA = NormOps_DDRM.normF(foundA); return(SpecializedOps_DDRM.diffNormF(orig, foundA) / normA); }
/** * <p> * The vector associated will the smallest singular value is returned as the null space * of the decomposed system. A right null space is returned if 'isRight' is set to true, * and a left null space if false. * </p> * * @param svd A precomputed decomposition. Not modified. * @param isRight true for right null space and false for left null space. Right is more commonly used. * @param nullVector Optional storage for a vector for the null space. Modified. * @return Vector in V associated with smallest singular value.. */ public static DMatrixRMaj nullVector(SingularValueDecomposition_F64 <DMatrixRMaj> svd, bool isRight, DMatrixRMaj nullVector) { int N = svd.numberOfSingularValues(); double[] s = svd.getSingularValues(); DMatrixRMaj A = isRight ? svd.getV(null, true) : svd.getU(null, false); if (isRight) { if (A.numRows != svd.numCols()) { throw new ArgumentException("Can't compute the null space using a compact SVD for a matrix of this size."); } if (nullVector == null) { nullVector = new DMatrixRMaj(svd.numCols(), 1); } else { nullVector.reshape(svd.numCols(), 1); } } else { if (A.numCols != svd.numRows()) { throw new ArgumentException("Can't compute the null space using a compact SVD for a matrix of this size."); } if (nullVector == null) { nullVector = new DMatrixRMaj(svd.numRows(), 1); } else { nullVector.reshape(svd.numRows(), 1); } } int smallestIndex = -1; if (isRight && svd.numCols() > svd.numRows()) { smallestIndex = svd.numCols() - 1; } else if (!isRight && svd.numCols() < svd.numRows()) { smallestIndex = svd.numRows() - 1; } else { // find the smallest singular value double smallestValue = Double.MaxValue; for (int i = 0; i < N; i++) { if (s[i] < smallestValue) { smallestValue = s[i]; smallestIndex = i; } } } // extract the null space if (isRight) { SpecializedOps_DDRM.subvector(A, smallestIndex, 0, A.numRows, true, 0, nullVector); } else { SpecializedOps_DDRM.subvector(A, 0, smallestIndex, A.numRows, false, 0, nullVector); } return(nullVector); }
public double quality() { return(SpecializedOps_DDRM.qualityTriangular(decomposer.getQR())); }
public DMatrixRMaj getRowPivot(DMatrixRMaj pivot) { return(SpecializedOps_DDRM.pivotMatrix(pivot, this.pivot, LU.numRows, false)); }