|
Calculates the Moore-Penrose pseudo-inverse of the M by N matrix A, and stores the result in PInverse. The singular values of A are returned in S. The left singular vectors are returned in U, and the right singular vectors are returned in V.
\( A^{+} = V * \Sigma^{+} * U^{T}\)
where \( \Sigma^{+} \) is a \( N \times M \) matrix which is zero except for its min(m,n) diagonal elements, U is a \( M \times
M \) orthogonal matrix, and V is a \( N \times N \) orthogonal matrix. The diagonal elements of \( \Sigma^{+} \) are the reciprocal ofc non-zero singular values of A; they are real and non-negative, andc are returned in descending order. The first \(\mbox{min}(m,n) \) columns of U and V are the left and right singular vectors of A.
- Note
- This routine returns \( V^{T}\), not \(V\).
-
On exit, the content of A is altered.
There are three ways to call this method to compute the pseudo-inverse of the matrix A.
-
User provides matrices \(A\) and \(A^{+}\). The user first allocates memory for these matrices and vector.
Definition vctForwardDeclarations.h:157
The user can then call the P-Inverse routine
CISSTNETLIB_INTEGER nmrPInverse(vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrPInverseDynamicData &data) CISST_THROW(std Definition nmrPInverse.h:784
The PInverse method verifies that the size of the data objects matches the input, and allocates workspace memory, which is deallocated when the function ends. Remember that nmrPInverse alters the content of matrix A. For fixed size the function call is templated by size and row/column major, e.g.
-
Using a preallocated data object. The user first creates the input matrix.
size_type cols() const Definition vctDynamicConstMatrixBase.h:243
size_type rows() const Definition vctDynamicConstMatrixBase.h:238
const bool VCT_ROW_MAJOR Definition vctForwardDeclarations.h:41
The user creates a data object which could be of type nmrPInverseFixedSizeData or nmrPInverseDynamicData corresponding to fixed size, dynamic matrix.
Definition nmrPInverse.h:46
Finally, call the nmrPInverse function:
The contents of input matrix is modified by this routine. The matrices U, Vt and vector S are available through the following methods:
std::cout << data.U()
<< data.S()
<< data.Vt()
<< data.PInverse()
<< std::endl;
-
User provides matrix PInverse with workspace required by pseudo-inverse routine of LAPACK. User creates matrices:
User also needs to allocate memory for workspace. This method is particularly useful when the user is using more than one numerical methods from the library and is willing to share the workspace between them. In such as case, the user can allocate the a memory greater than the maximum required by different methods. To aid the user determine the minimum workspace required (and not spend time digging LAPACK documentation) the library provides helper function nmrPInverseDynamicData::WorkspaceSize(input).
static size_type WorkspaceSize(size_type m, size_type n) Definition nmrPInverse.h:213
Definition vctForwardDeclarations.h:131
Call the SVD function For fixed size the above two steps are replaced by
Definition nmrPInverse.h:498
nmrPInverse uses nmrSVD and returns the error code of nmrSVD. See nmrSVD for further details.
- Note
- The PInverse functions make use of LAPACK routines. To activate this code, set the CISST_HAS_CISSTNETLIB flag to ON during the configuration of cisst with CMake.
-
The general rule for numerical functions which depend on LAPACK is that column-major matrices should be used everywhere, and that all matrices should be compact.
-
For the specific case of PInverse, a valid result is also obtained if all the matrices are stored in row-major order. This is an exeption to the general rule. However, mixed-order is not tolerated.
|
| template<class _matrixOwnerType> |
| CISSTNETLIB_INTEGER | nmrPInverse (vctDynamicMatrixBase< _matrixOwnerType, CISSTNETLIB_DOUBLE > &A, nmrPInverseDynamicData &data) CISST_THROW(std |
| template<class _matrixOwnerTypeA, class _matrixOwnerTypePInverse, class _vectorOwnerTypeWorkspace> |
| CISSTNETLIB_INTEGER | nmrPInverse (vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &PInverse, vctDynamicVectorBase< _vectorOwnerTypeWorkspace, CISSTNETLIB_DOUBLE > &Workspace) |
| template<class _matrixOwnerTypeA, class _matrixOwnerTypePInverse> |
| CISSTNETLIB_INTEGER | nmrPInverse (vctDynamicMatrixBase< _matrixOwnerTypeA, CISSTNETLIB_DOUBLE > &A, vctDynamicMatrixBase< _matrixOwnerTypePInverse, CISSTNETLIB_DOUBLE > &PInverse) |
| template<vct::size_type _rows, vct::size_type _cols, vct::size_type _work, bool _storageOrder, class _dataPtrType> |
| CISSTNETLIB_INTEGER | nmrPInverse (vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, _storageOrder > &A, vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _cols, _rows, _storageOrder > &pInverse, vctFixedSizeVectorBase< _work, 1, CISSTNETLIB_DOUBLE, _dataPtrType > &workspace) |
| template<vct::size_type _rows, vct::size_type _cols, bool _storageOrder> |
| CISSTNETLIB_INTEGER | nmrPInverse (vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, _storageOrder > &A, vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _cols, _rows, _storageOrder > &pInverse) |
| template<vct::size_type _rows, vct::size_type _cols, bool _storageOrder> |
| CISSTNETLIB_INTEGER | nmrPInverse (vctFixedSizeMatrix< CISSTNETLIB_DOUBLE, _rows, _cols, _storageOrder > &A, nmrPInverseFixedSizeData< _rows, _cols, _storageOrder > &data) |
Declaration of nmrPInverse.