Class SingularOps_DDRM
public class SingularOps_DDRM
extends java.lang.Object
-
Constructor Summary
Constructors Constructor Description SingularOps_DDRM() -
Method Summary
Modifier and Type Method Description static voidcheckSvdMatrixSize(@Nullable org.ejml.data.DMatrixRMaj U, boolean tranU, org.ejml.data.DMatrixRMaj W, @Nullable org.ejml.data.DMatrixRMaj V, boolean tranV)Checks to see if all the provided matrices are the expected size for an SVD.static voiddescendingOrder(@Nullable org.ejml.data.DMatrixRMaj U, boolean tranU, double[] singularValues, int singularLength, @Nullable org.ejml.data.DMatrixRMaj V, boolean tranV)Similar todescendingOrder(DMatrixRMaj, boolean, DMatrixRMaj, DMatrixRMaj, boolean)but takes in an array of singular values instead.static voiddescendingOrder(org.ejml.data.DMatrixRMaj U, boolean tranU, org.ejml.data.DMatrixRMaj W, org.ejml.data.DMatrixRMaj V, boolean tranV)Adjusts the matrices so that the singular values are in descending order.static intnullity(org.ejml.data.DMatrixRMaj A, double threshold)Returns the matrix's nullitystatic intnullity(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd)Extracts the nullity of a matrix using a preexisting decomposition and default threshold.static intnullity(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd, double threshold)Extracts the nullity of a matrix using a preexisting decomposition.static org.ejml.data.DMatrixRMajnullSpace(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<org.ejml.data.DMatrixRMaj> svd, @Nullable org.ejml.data.DMatrixRMaj nullSpace, double tol)Returns the null-space from the singular value decomposition.static org.ejml.data.DMatrixRMajnullspaceQR(org.ejml.data.DMatrixRMaj A, int totalSingular)Computes the null space using QR decomposition.static org.ejml.data.DMatrixRMajnullspaceQRP(org.ejml.data.DMatrixRMaj A, int totalSingular)Computes the null space using QRP decomposition.static org.ejml.data.DMatrixRMajnullspaceSVD(org.ejml.data.DMatrixRMaj A, int totalSingular)Computes the null space using SVD.static org.ejml.data.DMatrixRMajnullVector(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<org.ejml.data.DMatrixRMaj> svd, boolean isRight, @Nullable org.ejml.data.DMatrixRMaj nullVector)The vector associated will the smallest singular value is returned as the null space of the decomposed system.static intrank(org.ejml.data.DMatrixRMaj A)Returns the matrix's rank.static intrank(org.ejml.data.DMatrixRMaj A, double threshold)Returns the matrix's rankstatic intrank(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd)Extracts the rank of a matrix using a preexisting decomposition and default threshold.static intrank(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd, double threshold)Extracts the rank of a matrix using a preexisting decomposition.static doubleratioSmallestOverLargest(double[] sv)Computes the ratio of the smallest value to the largest.static doublesingularThreshold(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd)Returns a reasonable threshold for singular values.
tol = max (size (A)) * largest sigma * eps;static doublesingularThreshold(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd, double tolerance)static double[]singularValues(org.ejml.data.DMatrixRMaj A)Returns an array of all the singular values in A sorted in ascending orderstatic booleansvd(org.ejml.data.DMatrixRMaj A, @Nullable org.ejml.data.DMatrixRMaj U, org.ejml.data.DGrowArray sv, @Nullable org.ejml.data.DMatrixRMaj Vt)Computes the SVD and sorts singular values in descending order.
-
Constructor Details
-
SingularOps_DDRM
public SingularOps_DDRM()
-
-
Method Details
-
singularValues
public static double[] singularValues(org.ejml.data.DMatrixRMaj A)Returns an array of all the singular values in A sorted in ascending order- Parameters:
A- Matrix. Not modified.- Returns:
- singular values
-
ratioSmallestOverLargest
public static double ratioSmallestOverLargest(double[] sv)Computes the ratio of the smallest value to the largest. Does not assume the array is sorted first- Parameters:
sv- array- Returns:
- smallest / largest
-
rank
public static int rank(org.ejml.data.DMatrixRMaj A, double threshold)Returns the matrix's rank- Parameters:
A- Matrix. Not modified.threshold- Tolerance used to determine of a singular value is singular.- Returns:
- The rank of the decomposed matrix.
-
rank
public static int rank(org.ejml.data.DMatrixRMaj A)Returns the matrix's rank. Automatic selection of threshold- Parameters:
A- Matrix. Not modified.- Returns:
- The rank of the decomposed matrix.
-
svd
public static boolean svd(org.ejml.data.DMatrixRMaj A, @Nullable @Nullable org.ejml.data.DMatrixRMaj U, org.ejml.data.DGrowArray sv, @Nullable @Nullable org.ejml.data.DMatrixRMaj Vt)Computes the SVD and sorts singular values in descending order. While easier to use this can reduce performance when performed on small matrices numerous times. U*W*VT = A- Parameters:
A- (Input) Matrix being decomposedU- (Output) Storage for U. If null then it's ignored.sv- (Output) sorted list of singular values. Can be null.Vt- (Output) Storage for transposed V. Can be null.
-
descendingOrder
public static void descendingOrder(org.ejml.data.DMatrixRMaj U, boolean tranU, org.ejml.data.DMatrixRMaj W, org.ejml.data.DMatrixRMaj V, boolean tranV)Adjusts the matrices so that the singular values are in descending order.
In most implementations of SVD the singular values are automatically arranged in in descending order. In EJML this is not the case since it is often not needed and some computations can be saved by not doing that.
- Parameters:
U- Matrix. Modified.tranU- is U transposed or not.W- Diagonal matrix with singular values. Modified.V- Matrix. Modified.tranV- is V transposed or not.
-
descendingOrder
public static void descendingOrder(@Nullable @Nullable org.ejml.data.DMatrixRMaj U, boolean tranU, double[] singularValues, int singularLength, @Nullable @Nullable org.ejml.data.DMatrixRMaj V, boolean tranV)Similar to
descendingOrder(DMatrixRMaj, boolean, DMatrixRMaj, DMatrixRMaj, boolean)but takes in an array of singular values instead.- Parameters:
U- Matrix. Modified.tranU- is U transposed or not.singularValues- Array of singular values. Modified.singularLength- Number of elements in singularValues arrayV- Matrix. Modified.tranV- is V transposed or not.
-
checkSvdMatrixSize
public static void checkSvdMatrixSize(@Nullable @Nullable org.ejml.data.DMatrixRMaj U, boolean tranU, org.ejml.data.DMatrixRMaj W, @Nullable @Nullable org.ejml.data.DMatrixRMaj V, boolean tranV)Checks to see if all the provided matrices are the expected size for an SVD. If an error is encountered then an exception is thrown. This automatically handles compact and non-compact formats -
nullSpace
public static org.ejml.data.DMatrixRMaj nullSpace(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<org.ejml.data.DMatrixRMaj> svd, @Nullable @Nullable org.ejml.data.DMatrixRMaj nullSpace, double tol)Returns the null-space from the singular value decomposition. The null space is a set of non-zero vectors that when multiplied by the original matrix return zero.
The null space is found by extracting the columns in V that are associated singular values less than or equal to the threshold. In some situations a non-compact SVD is required.
- Parameters:
svd- A precomputed decomposition. Not modified.nullSpace- Storage for null space. Will be reshaped as needed. Modified.tol- Threshold for selecting singular values. Try UtilEjml.EPS.- Returns:
- The null space.
-
nullspaceQR
public static org.ejml.data.DMatrixRMaj nullspaceQR(org.ejml.data.DMatrixRMaj A, int totalSingular)Computes the null space using QR decomposition. This is much faster than using SVD- Parameters:
A- (Input) MatrixtotalSingular- Number of singular values- Returns:
- Null space
-
nullspaceQRP
public static org.ejml.data.DMatrixRMaj nullspaceQRP(org.ejml.data.DMatrixRMaj A, int totalSingular)Computes the null space using QRP decomposition. This is faster than using SVD but slower than QR. Much more stable than QR though.- Parameters:
A- (Input) MatrixtotalSingular- Number of singular values- Returns:
- Null space
-
nullspaceSVD
public static org.ejml.data.DMatrixRMaj nullspaceSVD(org.ejml.data.DMatrixRMaj A, int totalSingular)Computes the null space using SVD. Slowest bust most stable way to find the solution- Parameters:
A- (Input) MatrixtotalSingular- Number of singular values- Returns:
- Null space
-
nullVector
public static org.ejml.data.DMatrixRMaj nullVector(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<org.ejml.data.DMatrixRMaj> svd, boolean isRight, @Nullable @Nullable org.ejml.data.DMatrixRMaj nullVector)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.
- Parameters:
svd- A precomputed decomposition. Not modified.isRight- true for right null space and false for left null space. Right is more commonly used.nullVector- Optional storage for a vector for the null space. Modified.- Returns:
- Vector in V associated with smallest singular value..
-
singularThreshold
public static double singularThreshold(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd)Returns a reasonable threshold for singular values.
tol = max (size (A)) * largest sigma * eps;- Parameters:
svd- A precomputed decomposition. Not modified.- Returns:
- threshold for singular values
-
singularThreshold
public static double singularThreshold(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd, double tolerance) -
rank
public static int rank(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd)Extracts the rank of a matrix using a preexisting decomposition and default threshold.- Parameters:
svd- A precomputed decomposition. Not modified.- Returns:
- The rank of the decomposed matrix.
- See Also:
singularThreshold(SingularValueDecomposition_F64)
-
rank
public static int rank(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd, double threshold)Extracts the rank of a matrix using a preexisting decomposition.- Parameters:
svd- A precomputed decomposition. Not modified.threshold- Tolerance used to determine of a singular value is singular.- Returns:
- The rank of the decomposed matrix.
- See Also:
singularThreshold(SingularValueDecomposition_F64)
-
nullity
public static int nullity(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd)Extracts the nullity of a matrix using a preexisting decomposition and default threshold.- Parameters:
svd- A precomputed decomposition. Not modified.- Returns:
- The nullity of the decomposed matrix.
- See Also:
singularThreshold(SingularValueDecomposition_F64)
-
nullity
public static int nullity(org.ejml.interfaces.decomposition.SingularValueDecomposition_F64<?> svd, double threshold)Extracts the nullity of a matrix using a preexisting decomposition.- Parameters:
svd- A precomputed decomposition. Not modified.threshold- Tolerance used to determine of a singular value is singular.- Returns:
- The nullity of the decomposed matrix.
- See Also:
singularThreshold(SingularValueDecomposition_F64)
-
nullity
public static int nullity(org.ejml.data.DMatrixRMaj A, double threshold)Returns the matrix's nullity- Parameters:
A- Matrix. Not modified.threshold- Tolerance used to determine of a singular value is singular.- Returns:
- nullity
-