svd_matrixSvdMatrixSvdMatrixsvd_matrixT_svd_matrix
Short description
svd_matrixSvdMatrixSvdMatrixsvd_matrixT_svd_matrix โ Compute the singular value decomposition of a matrix.
Signature
svd_matrix( matrix MatrixID, string SVDType, string ComputeSingularVectors, out matrix MatrixUID, out matrix MatrixSID, out matrix MatrixVID )void SvdMatrix( const HTuple& MatrixID, const HTuple& SVDType, const HTuple& ComputeSingularVectors, HTuple* MatrixUID, HTuple* MatrixSID, HTuple* MatrixVID )static void HOperatorSet.SvdMatrix( HTuple matrixID, HTuple SVDType, HTuple computeSingularVectors, out HTuple matrixUID, out HTuple matrixSID, out HTuple matrixVID )def svd_matrix( matrix_id: HHandle, svdtype: str, compute_singular_vectors: str ) -> Tuple[HHandle, HHandle, HHandle]
Herror T_svd_matrix( const Htuple MatrixID, const Htuple SVDType, const Htuple ComputeSingularVectors, Htuple* MatrixUID, Htuple* MatrixSID, Htuple* MatrixVID )
HMatrix HMatrix::SvdMatrix( const HString& SVDType, const HString& ComputeSingularVectors, HMatrix* MatrixSID, HMatrix* MatrixVID ) const
HMatrix HMatrix::SvdMatrix( const char* SVDType, const char* ComputeSingularVectors, HMatrix* MatrixSID, HMatrix* MatrixVID ) const
HMatrix HMatrix::SvdMatrix( const wchar_t* SVDType, const wchar_t* ComputeSingularVectors, HMatrix* MatrixSID, HMatrix* MatrixVID ) const (Windows only)
HMatrix HMatrix.SvdMatrix( string SVDType, string computeSingularVectors, out HMatrix matrixSID, out HMatrix matrixVID )
Description
The operator svd_matrixSvdMatrix computes a full or reduced singular
value decomposition (SVD) of the Matrix defined by the
matrix handle MatrixIDmatrixIDmatrix_id. The operator returns the matrix
handle MatrixSIDmatrixSIDmatrix_sid of the matrix MatrixS with
singular values in descending order.
Optionally, the matrices MatrixU with the left and
MatrixV with the right singular vectors are computed and
the matrix handles MatrixUIDmatrixUIDmatrix_uid and MatrixVIDmatrixVIDmatrix_vid are
returned. Access to the elements of the matrices is possible e.g.,
with the operator get_full_matrixGetFullMatrix. The SVD is written
\[\begin{eqnarray*}
\texttt{Matrix} \quad = \quad \texttt{MatrixU} \quad \cdot \quad
\texttt{MatrixS} \quad \cdot \quad \texttt{MatrixV}^T.
\end{eqnarray*}\]
For SVDTypeSVDTypesvdtype = 'full'"full", a full SVD is computed.
Example:
SVDTypeSVDTypesvdtype = 'full'"full",
ComputeSingularVectorscomputeSingularVectorscompute_singular_vectors = 'both'"both"
\[\begin{eqnarray*}
\texttt{Matrix} =
\left[ \begin{array}{rr}
6.0 & -5.0 \\
10.0 & 4.0 \\
-3.0 & 5.0
\end{array} \right]
\end{eqnarray*}\]
\[\begin{eqnarray*}
\to \qquad
\texttt{MatrixU} &=&
\left[ \begin{array}{rrr}
-0.5228 & 0.5691 & 0.6346 \\
-0.8070 & -0.5702 & -0.1535 \\
0.2745 & -0.5924 & 0.7574
\end{array} \right]\\
\texttt{MatrixS} &=&
\left[ \begin{array}{rr}
12.0547 & 0 \\
0 & 8.1046 \\
0 & 0
\end{array} \right]\\
\texttt{MatrixV} &=&
\left[ \begin{array}{rrr}
-0.9980 & -0.0629 \\
0.0629 & -0.9980
\end{array} \right]
\end{eqnarray*}\]
For SVDTypeSVDTypesvdtype = 'reduced'"reduced", a reduced SVD is
computed.
Example:
SVDTypeSVDTypesvdtype = 'reduced'"reduced",
ComputeSingularVectorscomputeSingularVectorscompute_singular_vectors = 'both'"both"
\[\begin{eqnarray*}
\texttt{Matrix} =
\left[ \begin{array}{rr}
6.0 & -5.0 \\
10.0 & 4.0 \\
-3.0 & 5.0
\end{array} \right]
\end{eqnarray*}\]
\[\begin{eqnarray*}
\to \qquad
\texttt{MatrixU} &=&
\left[ \begin{array}{rrr}
-0.5228 & 0.5691 \\
-0.8070 & -0.5702 \\
0.2745 & -0.5924
\end{array} \right]\\
\texttt{MatrixS} &=&
\left[ \begin{array}{rr}
12.0547 & 0 \\
0 & 8.1046
\end{array} \right]\\
\texttt{MatrixV} &=&
\left[ \begin{array}{rrr}
-0.9980 & -0.0629 \\
0.0629 & -0.9980
\end{array} \right]
\end{eqnarray*}\]
For ComputeSingularVectorscomputeSingularVectorscompute_singular_vectors = 'left'"left", the matrix
MatrixU with the left singular vectors is computed. For
ComputeSingularVectorscomputeSingularVectorscompute_singular_vectors = 'right'"right", the matrix
MatrixV with the right singular vectors is computed. For
ComputeSingularVectorscomputeSingularVectorscompute_singular_vectors = 'both'"both", the matrices
MatrixU and MatrixV with the left and right
singular vectors are computed.
For ComputeSingularVectorscomputeSingularVectorscompute_singular_vectors = 'none'"none", no matrices
with the singular vectors are computed. The matrix
MatrixS is a matrix with \(n\) rows and one column, where
the number \(n\) = min(number of rows of the input Matrix,
number of columns of the input Matrix).
Example:
SVDTypeSVDTypesvdtype = 'reduced'"reduced" or 'full'"full",
ComputeSingularVectorscomputeSingularVectorscompute_singular_vectors = 'none'"none"
\[\begin{eqnarray*}
\texttt{Matrix} =
\left[ \begin{array}{rr}
6.0 & -5.0 \\
10.0 & 4.0 \\
-3.0 & 5.0
\end{array} \right]
\end{eqnarray*}\]
\[\begin{eqnarray*}
\to \qquad
\texttt{MatrixS} =
\left[ \begin{array}{r}
12.0547 \\
8.1046
\end{array} \right]
\end{eqnarray*}\]
It should be noted that in the examples there are differences in the
meaning of the values of the output matrices: If a value is shown as
an integer number, e.g., 0 or 1, the value of this element is per
definition this certain value. If the number is shown as a floating
point number, e.g., 0.0 or 1.0, the value is computed by the
operator.
Execution information
-
Multithreading type: reentrant (runs in parallel with non-exclusive operators).
-
Multithreading scope: global (may be called from any thread).
-
Processed without parallelization.
Parameters
MatrixIDmatrixIDmatrix_id (input_control) matrix โ (handle)HTuple (HHandle)HMatrix, HTuple (IntPtr)HHandleHtuple (handle)
Matrix handle of the input matrix.
SVDTypeSVDTypesvdtype (input_control) string โ (string)HTuple (HString)HTuple (string)strHtuple (char*)
Type of computation.
Default: 'full'"full"
List of values: 'full', 'reduced'"full", "reduced"
ComputeSingularVectorscomputeSingularVectorscompute_singular_vectors (input_control) string โ (string)HTuple (HString)HTuple (string)strHtuple (char*)
Computation of singular values.
Default: 'both'"both"
List of values: 'both', 'left', 'none', 'right'"both", "left", "none", "right"
MatrixUIDmatrixUIDmatrix_uid (output_control) matrix โ (handle)HTuple (HHandle)HMatrix, HTuple (IntPtr)HHandleHtuple (handle)
Matrix handle with the left singular vectors.
MatrixSIDmatrixSIDmatrix_sid (output_control) matrix โ (handle)HTuple (HHandle)HMatrix, HTuple (IntPtr)HHandleHtuple (handle)
Matrix handle with singular values.
MatrixVIDmatrixVIDmatrix_vid (output_control) matrix โ (handle)HTuple (HHandle)HMatrix, HTuple (IntPtr)HHandleHtuple (handle)
Matrix handle with the right singular vectors.
Result
If the parameters are valid, the operator svd_matrixSvdMatrix returns
the value 2 (H_MSG_TRUE). If necessary, an exception is raised.
Combinations with other operators
Combinations
Possible predecessors
create_matrixCreateMatrix
Possible successors
get_full_matrixGetFullMatrix, get_value_matrixGetValueMatrix
References
David Poole: โLinear Algebra: A Modern Introductionโ; Thomson;
Belmont; 2006.
Gene H. Golub, Charles F. van Loan: โMatrix Computationsโ; The
Johns Hopkins University Press; Baltimore and London; 1996.
Module
Foundation