Matrix¶
- class Matrix(*args, **kwargs)¶
Bases:
ArrayDouble2D
Implementation of a matrix and operations on matrices.
This class needs one of the following third-party to compute matrix inverse, pseudo-inverse, singular value decomposition, determinant:
If Lapack is installed and detected by ViSP, this 3rd party is used by vpMatrix . Installation instructions are provided here https://visp.inria.fr/3rd_lapack;
else if Eigen3 is installed and detected by ViSP, this 3rd party is used by vpMatrix . Installation instructions are provided here https://visp.inria.fr/3rd_eigen;
else if OpenCV is installed and detected by ViSP, this 3rd party is used, Installation instructions are provided here https://visp.inria.fr/3rd_opencv;
If none of these previous 3rd parties is installed, we use by default a Lapack built-in version.
vpMatrix class provides a data structure for the matrices as well as a set of operations on these matrices.
The vpMatrix class is derived from vpArray2D<double> .
The code below shows how to create a 2-by-3 matrix of doubles, set the element values and access them:
#include <visp3/code/vpMatrix.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix M(2, 3); M[0][0] = -1; M[0][1] = -2; M[0][2] = -3; M[1][0] = 4; M[1][1] = 5.5; M[1][2] = 6.0f; std::cout << "M:" << std::endl; for (unsigned int i = 0; i < M.getRows(); ++i) { for (unsigned int j = 0; j < M.getCols(); ++j) { std::cout << M[i][j] << " "; } std::cout << std::endl; } }
Once build, this previous code produces the following output:
M: -1 -2 -3 4 5.5 6
If ViSP is build with c++11 enabled, you can do the same using:
#include <visp3/code/vpMatrix.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix M( {-1, -2, -3}, {4, 5.5, 6.0f} ); std::cout << "M:\n" << M << std::endl; }
You can also create and initialize a matrix this way:
#include <visp3/code/vpMatrix.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix M(2, 3, {-1, -2, -3, 4, 5.5, 6.0f} ); }
The Matrix could also be initialized using operator=(const std::initializer_list< std::initializer_list< double > > &)
#include <visp3/code/vpMatrix.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix M; M = { {-1, -2, -3}, {4, 5.5, 6.0f} }; }
Note
See vpArray2D , vpRowVector , vpColVector , vpHomogeneousMatrix , vpRotationMatrix , vpVelocityTwistMatrix , vpForceTwistMatrix , vpHomography
Overloaded function.
__init__(self: visp._visp.core.Matrix) -> None
Basic constructor of a matrix of double. Number of columns and rows are zero.
__init__(self: visp._visp.core.Matrix, r: int, c: int) -> None
Constructor that initialize a matrix of double with 0.
- Parameters:
- r
Matrix number of rows.
- c
Matrix number of columns.
__init__(self: visp._visp.core.Matrix, r: int, c: int, val: float) -> None
Constructor that initialize a matrix of double with val .
- Parameters:
- r
Matrix number of rows.
- c
Matrix number of columns.
- val
Each element of the matrix is set to val .
__init__(self: visp._visp.core.Matrix, M: visp._visp.core.Matrix, r: int, c: int, nrows: int, ncols: int) -> None
Construct a matrix as a sub-matrix of the input matrix M .
Note
See init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols)
__init__(self: visp._visp.core.Matrix, A: visp._visp.core.ArrayDouble2D) -> None
__init__(self: visp._visp.core.Matrix, A: visp._visp.core.Matrix) -> None
__init__(self: visp._visp.core.Matrix, R: visp._visp.core.HomogeneousMatrix) -> None
__init__(self: visp._visp.core.Matrix, R: visp._visp.core.RotationMatrix) -> None
__init__(self: visp._visp.core.Matrix, V: visp._visp.core.VelocityTwistMatrix) -> None
__init__(self: visp._visp.core.Matrix, F: visp._visp.core.ForceTwistMatrix) -> None
__init__(self: visp._visp.core.Matrix, v: visp._visp.core.ColVector) -> None
__init__(self: visp._visp.core.Matrix, v: visp._visp.core.RowVector) -> None
__init__(self: visp._visp.core.Matrix, t: visp._visp.core.TranslationVector) -> None
__init__(self: visp._visp.core.Matrix, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.Matrix, nrows: int, ncols: int, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.Matrix, lists: std::initializer_list<std::initializer_list<double> >) -> None
__init__(self: visp._visp.core.Matrix, np_array: numpy.ndarray[numpy.float64]) -> None
Construct a matrix by copying a 2D numpy array.
- Parameters:
- np_array
The numpy array to copy.
Methods
Overloaded function.
Overloaded function.
Overloaded function.
Overloaded function.
Operation C = A*wA + B*wB
Compute the Cholesky decomposition of a Hermitian positive-definite matrix using Eigen3 library.
Compute the Cholesky decomposition of a Hermitian positive-definite matrix using Lapack library.
Compute the Cholesky decomposition of a Hermitian positive-definite matrix using OpenCV library.
Removes all elements from the matrix (which are destroyed), leaving the container with a size of 0.
Overloaded function.
Overloaded function.
Compute \({\bf H} + \alpha * diag({\bf H})\)
- param svThreshold:
Threshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
Overloaded function.
Create a diagonal matrix with the element of a vector \(DA_{ii} = A_i\) .
Permits to compute an approximated inverse of a matrix that is ill-conditionned.
Compute the determinant of a n-by-n matrix.
Compute the determinant of a square matrix using the LU decomposition.
Compute the determinant of a square matrix using the LU decomposition with Eigen3 3rd party.
Compute the determinant of a square matrix using the LU decomposition with Lapack 3rd party.
Compute the determinant of a n-by-n matrix using the LU decomposition with OpenCV 3rd party.
Overloaded function.
Overloaded function.
Compute the exponential matrix of a square matrix.
Extract a sub matrix from a matrix M .
Overloaded function.
Compute and return the Frobenius norm (also called Euclidean norm) \(||A|| = \sqrt{ \sum{A_{ij}^2}}\) .
Overloaded function.
Extract a diagonal vector from a matrix.
Return the minimum size of rows and columns required to enable Blas/Lapack usage on matrices and vectors.
Overloaded function.
Overloaded function.
Compute and return the induced L2 norm \(||A|| = \Sigma_{max}(A)\) which is equal to the maximum singular value of the matrix.
Compute and return the infinity norm \({||A||}_{\infty} = max\left(\sum_{j=0}^{n}{\mid A_{ij} \mid}\right)\) with \(i \in \{0, ..., m\}\) where \((m,n)\) is the matrix size.
Initialize the matrix from a part of an input matrix M .
Overloaded function.
Overloaded function.
Compute the inverse of a n-by-n matrix using the Cholesky decomposition.
Compute the inverse of a n-by-n matrix using the Cholesky decomposition with Lapack 3rd party.
Compute the inverse of a n-by-n matrix using the Cholesky decomposition with OpenCV 3rd party.
Compute the inverse of a n-by-n matrix using the LU decomposition.
Compute the inverse of a n-by-n matrix using the LU decomposition with Eigen3 3rd party.
Compute the inverse of a n-by-n matrix using the LU decomposition with Lapack 3rd party.
Compute the inverse of a n-by-n matrix using the LU decomposition with OpenCV 3rd party.
Compute the inverse of a n-by-n matrix using the QR decomposition.
Compute the inverse of a n-by-n matrix using the QR decomposition with Lapack 3rd party.
Compute the inverse of a full-rank n-by-n triangular matrix.
Overloaded function.
Function to compute the null space (the kernel) of a m-by-n matrix \(\bf A\) .
Overloaded function.
Overloaded function.
Overloaded function.
Operation w = A * v (v and w are vectors).
Operation C = -A.
Overloaded function.
Numpy view of the underlying array data.
Pretty print a matrix.
Overloaded function.
Overloaded function.
Overloaded function.
Overloaded function.
Compute the QR decomposition of a (m x n) matrix of rank r.
Compute the QR pivot decomposition of a (m x n) matrix of rank r.
Save a matrix to a file.
Save a matrix in a YAML-formatted file.
Modify default size used to determine if Blas/Lapack basic linear algebra operations are enabled.
Overloaded function.
Overloaded function.
Overloaded function.
Overloaded function.
Overloaded function.
Overloaded function.
Overloaded function.
Overloaded function.
Returns a C++ code representation of this data array (see cppPrint in the C++ documentation)
Returns the CSV representation of this data array (see csvPrint in the C++ documentation)
Returns the CSV representation of this data array (see maplePrint in the C++ documentation)
Returns the Matlab representation of this data array (see matlabPrint in the C++ documentation)
Overloaded function.
Return the sum of all the \(a_{ij}\) elements of the matrix.
Return the sum square of all the \(A_{ij}\) elements of the matrix \(A(m, n)\) .
Matrix singular value decomposition (SVD).
Singular value decomposition (SVD) using Eigen3 3rd party.
Singular value decomposition (SVD) using Lapack 3rd party.
Singular value decomposition (SVD) using OpenCV 3rd party.
Overloaded function.
Overloaded function.
Inherited Methods
Return the array max value.
Insert array B in array A at the given position.
Return the number of rows of the 2D array.
Overloaded function.
Save an array in a YAML-formatted file.
Set the size of the array and initialize all the values to zero.
Return the array min value.
Return the number of columns of the 2D array.
Return the number of elements of the 2D array.
Operators
Operation C = A + B (A is unchanged).
__doc__
Overloaded function.
Overloaded function.
Multiply all the element of the matrix by x : Aij = Aij * x.
Overloaded function.
Overloaded function.
Divide all the element of the matrix by x : Aij = Aij / x.
__module__
Overloaded function.
Operation C = -A (A is unchanged).
Operation C = A - B (A is unchanged).
Cij = Aij / x (A is unchanged)
Attributes
LU_DECOMPOSITION
__annotations__
- class DetMethod(self, value: int)¶
Bases:
pybind11_object
Method used to compute the determinant of a square matrix.
Note
See det()
Values:
LU_DECOMPOSITION: LU decomposition method.
- AAt(*args, **kwargs)¶
Overloaded function.
AAt(self: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Note
See AAt(vpMatrix &) const
- Returns:
\(A*A^T\)
AAt(self: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> None
Compute the AAt operation such as \(B = A*A^T\) .
The result is placed in the parameter B and not returned.
A new matrix won’t be allocated for every use of the function. This results in a speed gain if used many times with the same result matrix size.
Note
See AAt()
- AtA(*args, **kwargs)¶
Overloaded function.
AtA(self: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Note
See AtA(vpMatrix &) const
- Returns:
\(A^T*A\)
AtA(self: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> None
Compute the AtA operation such as \(B = A^T*A\) .
The result is placed in the parameter B and not returned.
A new matrix won’t be allocated for every use of the function. This results in a speed gain if used many times with the same result matrix size.
Note
See AtA()
- __add__(self, B: visp._visp.core.Matrix) visp._visp.core.Matrix ¶
Operation C = A + B (A is unchanged).
Note
See add2Matrices() to avoid matrix allocation for each use.
- __eq__(*args, **kwargs)¶
Overloaded function.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
- __getitem__(*args, **kwargs)¶
Overloaded function.
__getitem__(self: visp._visp.core.Matrix, arg0: tuple[int, int]) -> float
__getitem__(self: visp._visp.core.Matrix, arg0: int) -> numpy.ndarray[numpy.float64]
__getitem__(self: visp._visp.core.Matrix, arg0: slice) -> numpy.ndarray[numpy.float64]
__getitem__(self: visp._visp.core.Matrix, arg0: tuple) -> numpy.ndarray[numpy.float64]
- __iadd__(*args, **kwargs)¶
Overloaded function.
__iadd__(self: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Operation A = A + B.
__iadd__(self: visp._visp.core.Matrix, x: float) -> visp._visp.core.Matrix
Add x to all the element of the matrix : Aij = Aij + x.
- __imul__(self, x: float) visp._visp.core.Matrix ¶
Multiply all the element of the matrix by x : Aij = Aij * x.
Operator that allows to multiply all the elements of a matrix by a scalar.
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.Matrix) -> None
Basic constructor of a matrix of double. Number of columns and rows are zero.
__init__(self: visp._visp.core.Matrix, r: int, c: int) -> None
Constructor that initialize a matrix of double with 0.
- Parameters:
- r
Matrix number of rows.
- c
Matrix number of columns.
__init__(self: visp._visp.core.Matrix, r: int, c: int, val: float) -> None
Constructor that initialize a matrix of double with val .
- Parameters:
- r
Matrix number of rows.
- c
Matrix number of columns.
- val
Each element of the matrix is set to val .
__init__(self: visp._visp.core.Matrix, M: visp._visp.core.Matrix, r: int, c: int, nrows: int, ncols: int) -> None
Construct a matrix as a sub-matrix of the input matrix M .
Note
See init(const vpMatrix &M, unsigned int r, unsigned int c, unsigned int nrows, unsigned int ncols)
__init__(self: visp._visp.core.Matrix, A: visp._visp.core.ArrayDouble2D) -> None
__init__(self: visp._visp.core.Matrix, A: visp._visp.core.Matrix) -> None
__init__(self: visp._visp.core.Matrix, R: visp._visp.core.HomogeneousMatrix) -> None
__init__(self: visp._visp.core.Matrix, R: visp._visp.core.RotationMatrix) -> None
__init__(self: visp._visp.core.Matrix, V: visp._visp.core.VelocityTwistMatrix) -> None
__init__(self: visp._visp.core.Matrix, F: visp._visp.core.ForceTwistMatrix) -> None
__init__(self: visp._visp.core.Matrix, v: visp._visp.core.ColVector) -> None
__init__(self: visp._visp.core.Matrix, v: visp._visp.core.RowVector) -> None
__init__(self: visp._visp.core.Matrix, t: visp._visp.core.TranslationVector) -> None
__init__(self: visp._visp.core.Matrix, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.Matrix, nrows: int, ncols: int, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.Matrix, lists: std::initializer_list<std::initializer_list<double> >) -> None
__init__(self: visp._visp.core.Matrix, np_array: numpy.ndarray[numpy.float64]) -> None
Construct a matrix by copying a 2D numpy array.
- Parameters:
- np_array
The numpy array to copy.
- __isub__(*args, **kwargs)¶
Overloaded function.
__isub__(self: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Operation A = A - B.
__isub__(self: visp._visp.core.Matrix, x: float) -> visp._visp.core.Matrix
subtract x to all the element of the matrix : Aij = Aij - x
- __itruediv__(self, x: float) visp._visp.core.Matrix ¶
Divide all the element of the matrix by x : Aij = Aij / x.
- __mul__(*args, **kwargs)¶
Overloaded function.
__mul__(self: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Operation C = A * B (A is unchanged).
Note
See mult2Matrices() to avoid matrix allocation for each use.
__mul__(self: visp._visp.core.Matrix, R: visp._visp.core.RotationMatrix) -> visp._visp.core.Matrix
Operator that allow to multiply a matrix by a rotation matrix. The matrix should be of dimension m-by-3.
__mul__(self: visp._visp.core.Matrix, R: visp._visp.core.HomogeneousMatrix) -> visp._visp.core.Matrix
Operator that allow to multiply a matrix by a homogeneous matrix. The matrix should be of dimension m-by-4.
__mul__(self: visp._visp.core.Matrix, V: visp._visp.core.VelocityTwistMatrix) -> visp._visp.core.Matrix
Operator that allow to multiply a matrix by a velocity twist matrix. The matrix should be of dimension m-by-6.
__mul__(self: visp._visp.core.Matrix, V: visp._visp.core.ForceTwistMatrix) -> visp._visp.core.Matrix
Operator that allow to multiply a matrix by a force/torque twist matrix. The matrix should be of dimension m-by-6.
__mul__(self: visp._visp.core.Matrix, tv: visp._visp.core.TranslationVector) -> visp._visp.core.TranslationVector
Operator that allows to multiply a matrix by a translation vector. The matrix should be of dimension (3x3)
__mul__(self: visp._visp.core.Matrix, v: visp._visp.core.ColVector) -> visp._visp.core.ColVector
Operation w = A * v (matrix A is unchanged, v and w are column vectors).
Note
See multMatrixVector() to avoid matrix allocation for each use.
__mul__(self: visp._visp.core.Matrix, x: float) -> visp._visp.core.Matrix
Operator that allows to multiply all the elements of a matrix by a scalar.
- __ne__(*args, **kwargs)¶
Overloaded function.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
- __neg__(self) visp._visp.core.Matrix ¶
Operation C = -A (A is unchanged).
Note
See negateMatrix() to avoid matrix allocation for each use.
- __sub__(self, B: visp._visp.core.Matrix) visp._visp.core.Matrix ¶
Operation C = A - B (A is unchanged).
Note
See sub2Matrices() to avoid matrix allocation for each use.
- __truediv__(self, x: float) visp._visp.core.Matrix ¶
Cij = Aij / x (A is unchanged)
- static add2Matrices(*args, **kwargs)¶
Overloaded function.
add2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix) -> None
Operation C = A + B.
The result is placed in the third parameter C and not returned. A new matrix won’t be allocated for every use of the function (speed gain if used many times with the same result matrix size).
Note
See operator+()
add2Matrices(A: visp._visp.core.ColVector, B: visp._visp.core.ColVector, C: visp._visp.core.ColVector) -> None
Warning
This function is provided for compat with previous releases. You should rather use the functionalities provided in vpColVector class.
Operation C = A + B.
The result is placed in the third parameter C and not returned. A new vector won’t be allocated for every use of the function (speed gain if used many times with the same result matrix size).
Note
See vpColVector::operator+()
- static add2WeightedMatrices(A: visp._visp.core.Matrix, wA: float, B: visp._visp.core.Matrix, wB: float, C: visp._visp.core.Matrix) None ¶
Operation C = A*wA + B*wB
The result is placed in the third parameter C and not returned. A new matrix won’t be allocated for every use of the function (Speed gain if used many times with the same result matrix size).
Note
See operator+()
- cholesky(self) visp._visp.core.Matrix ¶
- choleskyByEigen3(self) visp._visp.core.Matrix ¶
Compute the Cholesky decomposition of a Hermitian positive-definite matrix using Eigen3 library.
- Returns:
vpMatrix The lower triangular matrix resulting from the Cholesky decomposition
- choleskyByLapack(self) visp._visp.core.Matrix ¶
Compute the Cholesky decomposition of a Hermitian positive-definite matrix using Lapack library.
- Returns:
vpMatrix The lower triangular matrix resulting from the Cholesky decomposition
- choleskyByOpenCV(self) visp._visp.core.Matrix ¶
Compute the Cholesky decomposition of a Hermitian positive-definite matrix using OpenCV library.
- Returns:
vpMatrix The lower triangular matrix resulting from the Cholesky decomposition
- clear(self) None ¶
Removes all elements from the matrix (which are destroyed), leaving the container with a size of 0.
- static computeCovarianceMatrix(*args, **kwargs)¶
Overloaded function.
computeCovarianceMatrix(A: visp._visp.core.Matrix, x: visp._visp.core.ColVector, b: visp._visp.core.ColVector) -> visp._visp.core.Matrix
Compute the covariance matrix of the parameters x from a least squares minimization defined as: Ax = b
- Parameters:
- A
Matrix A from Ax = b.
- x
Vector x from Ax = b corresponding to the parameters to estimate.
- b
Vector b from Ax = b.
computeCovarianceMatrix(A: visp._visp.core.Matrix, x: visp._visp.core.ColVector, b: visp._visp.core.ColVector, w: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Compute the covariance matrix of the parameters x from a least squares minimization defined as: WAx = Wb
- Parameters:
- A
Matrix A from WAx = Wb.
- x
Vector x from WAx = Wb corresponding to the parameters to estimate.
- b
Vector b from WAx = Wb.
- static computeCovarianceMatrixVVS(*args, **kwargs)¶
Overloaded function.
computeCovarianceMatrixVVS(cMo: visp._visp.core.HomogeneousMatrix, deltaS: visp._visp.core.ColVector, Ls: visp._visp.core.Matrix, W: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Compute the covariance matrix of an image-based virtual visual servoing. This assumes the optimization has been done via v = (W * Ls). pseudoInverse() W * DeltaS.
- Parameters:
- cMo
Pose matrix that has been computed with the v.
- deltaS
Error vector used in v = (W * Ls). pseudoInverse() * W * DeltaS.
- Ls
interaction matrix used in v = (W * Ls). pseudoInverse() * W * DeltaS.
- W
Weight matrix used in v = (W * Ls). pseudoInverse() * W * DeltaS.
computeCovarianceMatrixVVS(cMo: visp._visp.core.HomogeneousMatrix, deltaS: visp._visp.core.ColVector, Ls: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Compute the covariance matrix of an image-based virtual visual servoing. This assumes the optimization has been done via v = Ls.pseudoInverse() * DeltaS.
- Parameters:
- cMo
Pose matrix that has been computed with the v.
- deltaS
Error vector used in v = Ls.pseudoInverse() * DeltaS
- Ls
interaction matrix used in v = Ls.pseudoInverse() * DeltaS
- static computeHLM(H: visp._visp.core.Matrix, alpha: float, HLM: visp._visp.core.Matrix) None ¶
Compute \({\bf H} + \alpha * diag({\bf H})\)
- Parameters:
- H: visp._visp.core.Matrix¶
input Matrix \({\bf H}\) . This matrix should be square.
- alpha: float¶
Scalar \(\alpha\)
- HLM: visp._visp.core.Matrix¶
Resulting operation.
- cond(self, svThreshold: float = 1e-6) float ¶
- static conv2(*args, **kwargs)¶
Overloaded function.
conv2(M: visp._visp.core.Matrix, kernel: visp._visp.core.Matrix, mode: str) -> visp._visp.core.Matrix
Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .
<unparsed image <doxmlparser.compound.docImageType object at 0x7f1229e21cc0>>
Note
This is a very basic implementation that does not use FFT.
- Parameters:
- M
First matrix.
- kernel
Second matrix.
- mode
Convolution mode: “full” (default), “same”, “valid”.
conv2(M: visp._visp.core.Matrix, kernel: visp._visp.core.Matrix, res: visp._visp.core.Matrix, mode: str) -> None
Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .
<unparsed image <doxmlparser.compound.docImageType object at 0x7f1229e238e0>>
Note
This is a very basic implementation that does not use FFT.
- Parameters:
- M
First array.
- kernel
Second array.
- res
Result.
- mode
Convolution mode: “full” (default), “same”, “valid”.
- static createDiagonalMatrix(A: visp._visp.core.ColVector, DA: visp._visp.core.Matrix) None ¶
Create a diagonal matrix with the element of a vector \(DA_{ii} = A_i\) .
Note
See diag()
- Parameters:
- A: visp._visp.core.ColVector¶
Vector which element will be put in the diagonal.
- DA: visp._visp.core.Matrix¶
Diagonal matrix DA[i][i] = A[i]
- dampedInverse(self, ratioOfMaxSvd: float = 1e-4) visp._visp.core.Matrix ¶
Permits to compute an approximated inverse of a matrix that is ill-conditionned. If the matrix is well-conditionned, the damped inverse is close to the Moore-Penrose pseudo-inverse.
The corresponding equation is the following, assuming that \(\textbf{A}\) is the matrix we want to compute the damped inverse:
\(\textbf{A} \approx ( \lambda \textbf{I} + \textbf{A}^T \textbf{A})^{-1} \textbf{A}^T\)
- det(self, method: visp._visp.core.Matrix.DetMethod) float ¶
Compute the determinant of a n-by-n matrix.
#include <iostream> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3,3); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.; std::cout << "Initial matrix: \n" << A << std::endl; // Compute the determinant std:: cout << "Determinant by default method : " << A.det() << std::endl; std:: cout << "Determinant by LU decomposition : " << A.detByLU() << std::endl; std:: cout << "Determinant by LU decomposition (Lapack): " << A.detByLULapack() << std::endl; std:: cout << "Determinant by LU decomposition (OpenCV): " << A.detByLUOpenCV() << std::endl; std:: cout << "Determinant by LU decomposition (Eigen3): " << A.detByLUEigen3() << std::endl; }
- Parameters:
- method: visp._visp.core.Matrix.DetMethod¶
Method used to compute the determinant. Default LU decomposition method is faster than the method based on Gaussian elimination.
- Returns:
Determinant of the matrix.
- detByLU(self) float ¶
Compute the determinant of a square matrix using the LU decomposition.
This function calls the first following function that is available:
detByLULapack() if Lapack 3rd party is installed
detByLUEigen3() if Eigen3 3rd party is installed
detByLUOpenCV() if OpenCV 3rd party is installed.
If none of these previous 3rd parties is installed, we use by default detByLULapack() with a Lapack built-in version.
#include <iostream> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3,3); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.; std::cout << "Initial matrix: \n" << A << std::endl; // Compute the determinant std:: cout << "Determinant by default method : " << A.det() << std::endl; std:: cout << "Determinant by LU decomposition : " << A.detByLU() << std::endl; }
Note
See detByLULapack() , detByLUEigen3() , detByLUOpenCV()
- Returns:
The determinant of the matrix if the matrix is square.
- detByLUEigen3(self) float ¶
Compute the determinant of a square matrix using the LU decomposition with Eigen3 3rd party.
#include <iostream> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3,3); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.; std::cout << "Initial matrix: \n" << A << std::endl; // Compute the determinant std:: cout << "Determinant by LU decomposition (Eigen3): " << A.detByLUEigen3() << std::endl; }
Note
See detByLU() , detByLUOpenCV() , detByLULapack()
- Returns:
The determinant of the matrix if the matrix is square.
- detByLULapack(self) float ¶
Compute the determinant of a square matrix using the LU decomposition with Lapack 3rd party.
#include <iostream> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3,3); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.; std::cout << "Initial matrix: \n" << A << std::endl; // Compute the determinant std:: cout << "Determinant by LU decomposition (Lapack): " << A.detByLULapack() << std::endl; }
Note
See detByLU() , detByLUEigen3() , detByLUOpenCV()
- Returns:
The determinant of the matrix if the matrix is square.
- detByLUOpenCV(self) float ¶
Compute the determinant of a n-by-n matrix using the LU decomposition with OpenCV 3rd party.
#include <iostream> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3,3); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[1][0] = 1/3.; A[1][1] = 1/4.; A[1][2] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/7.; A[2][2] = 1/8.; std::cout << "Initial matrix: \n" << A << std::endl; // Compute the determinant std:: cout << "Determinant by LU decomposition (OpenCV): " << A.detByLUOpenCV() << std::endl; }
Note
See detByLU() , detByLUEigen3() , detByLULapack()
- Returns:
Determinant of the matrix.
- diag(*args, **kwargs)¶
Overloaded function.
diag(self: visp._visp.core.Matrix, val: float = 1.0) -> None
Set the matrix as a diagonal matrix where each element on the diagonal is set to val . Elements that are not on the diagonal are set to 0.
Note
See eye()
#include <iostream> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3, 4); A.diag(2); std::cout << "A:\n" << A << std::endl; }
Matrix A is now equal to:
2 0 0 0 0 2 0 0 0 0 2 0
- Parameters:
- val
Value to set.
diag(self: visp._visp.core.Matrix, A: visp._visp.core.ColVector) -> None
Create a diagonal matrix with the element of a vector.
Note
See createDiagonalMatrix()
#include <iostream> #include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A; vpColVector v(3); v[0] = 1; v[1] = 2; v[2] = 3; A.diag(v); std::cout << "A:\n" << A << std::endl; }
Matrix A is now equal to:
1 0 0 0 2 0 0 0 3
- Parameters:
- A
Vector which element will be put in the diagonal.
- eigenValues(*args, **kwargs)¶
Overloaded function.
eigenValues(self: visp._visp.core.Matrix) -> visp._visp.core.ColVector
Compute the eigenvalues of a n-by-n real symmetric matrix using Lapack 3rd party.
Here an example:
#include <iostream> #include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3,3); // A is a symmetric matrix A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[1][0] = 1/2.; A[1][1] = 1/3.; A[1][2] = 1/4.; A[2][0] = 1/3.; A[2][1] = 1/4.; A[2][2] = 1/5.; std::cout << "Initial symmetric matrix: \n" << A << std::endl; // Compute the eigen values vpColVector evalue; // Eigenvalues evalue = A.eigenValues(); std::cout << "Eigen values: \n" << evalue << std::endl; }
Note
See eigenValues(vpColVector &, vpMatrix &)
- Returns:
The eigenvalues of a n-by-n real symmetric matrix, sorted in ascending order.
eigenValues(self: visp._visp.core.Matrix, evalue: visp._visp.core.ColVector, evector: visp._visp.core.Matrix) -> None
Compute the eigenvalues of a n-by-n real symmetric matrix using Lapack 3rd party.
Here an example:
#include <iostream> #include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); // A is a symmetric matrix A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.; A[1][0] = 1/2.; A[1][1] = 1/3.; A[1][2] = 1/4.; A[1][3] = 1/5.; A[2][0] = 1/3.; A[2][1] = 1/4.; A[2][2] = 1/5.; A[2][3] = 1/6.; A[3][0] = 1/4.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.; std::cout << "Initial symmetric matrix: \n" << A << std::endl; vpColVector d; // Eigenvalues vpMatrix V; // Eigenvectors // Compute the eigenvalues and eigenvectors A.eigenValues(d, V); std::cout << "Eigen values: \n" << d << std::endl; std::cout << "Eigen vectors: \n" << V << std::endl; vpMatrix D; D.diag(d); // Eigenvalues are on the diagonal std::cout << "D: " << D << std::endl; // Verification: A * V = V * D std::cout << "AV-VD = 0 ? \n" << (A*V) - (V*D) << std::endl; }
Note
See eigenValues()
- Parameters:
- evalue
Eigenvalues of the matrix, sorted in ascending order.
- evector
Corresponding eigenvectors of the matrix.
- expm(self) visp._visp.core.Matrix ¶
Compute the exponential matrix of a square matrix.
- Returns:
Return the exponential matrix.
- extract(self, r: int, c: int, nrows: int, ncols: int) visp._visp.core.Matrix ¶
Extract a sub matrix from a matrix M .
The following code shows how to use this function:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix M(4,5); int val = 0; for(size_t i=0; i<M.getRows(); i++) { for(size_t j=0; j<M.getCols(); j++) { M[i][j] = val++; } } M.print(std::cout, 4, "M "); vpMatrix N = M.extract(0, 1, 2, 3); N.print(std::cout, 4, "N "); }
It produces the following output:
M [4,5]= 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 N [2,3]= 1 2 3 6 7 8
Note
See init(const vpMatrix &, unsigned int, unsigned int, unsigned int, unsigned int)
- eye(*args, **kwargs)¶
Overloaded function.
eye(self: visp._visp.core.Matrix) -> None
Set an m-by-n matrix to identity with ones on the diagonal and zeros else where.
eye(self: visp._visp.core.Matrix, n: int) -> None
Set an n-by-n matrix to identity with ones on the diagonal and zeros else where.
eye(self: visp._visp.core.Matrix, m: int, n: int) -> None
Set an m-by-n matrix to identity with ones on the diagonal and zeros else where.
- frobeniusNorm(self) float ¶
Compute and return the Frobenius norm (also called Euclidean norm) \(||A|| = \sqrt{ \sum{A_{ij}^2}}\) .
Note
See infinityNorm() , inducedL2Norm()
- Returns:
The Frobenius norm (also called Euclidean norm) if the matrix is initialized, 0 otherwise.
- getCol(*args, **kwargs)¶
Overloaded function.
getCol(self: visp._visp.core.Matrix, j: int) -> visp._visp.core.ColVector
The following example shows how to use this function:
#include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); for (unsigned int i = 0; i < A.getRows(); i++) for (unsigned int j = 0; j < A.getCols(); j++) A[i][j] = i*A.getCols()+j; A.print(std::cout, 4); vpColVector cv = A.getCol(1); std::cout << "Column vector: \n" << cv << std::endl; }
It produces the following output :
[4, 4] = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 column vector : 1 5 9 13
- Parameters:
- j
Index of the column to extract. If j=0, the first column is extracted.
- Returns:
The extracted column vector.
getCol(self: visp._visp.core.Matrix, j: int, i_begin: int, size: int) -> visp._visp.core.ColVector
The following example shows how to use this function:
#include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); for(unsigned int i=0; i < A.getRows(); i++) for(unsigned int j=0; j < A.getCols(); j++) A[i][j] = i*A.getCols()+j; A.print(std::cout, 4); vpColVector cv = A.getCol(1, 1, 3); std::cout << "Column vector: \n" << cv << std::endl; }
It produces the following output :
[4, 4] = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 column vector : 5 9 13
- Parameters:
- j
Index of the column to extract. If col=0, the first column is extracted.
- i_begin
Index of the row that gives the location of the first element of the column vector to extract.
- Returns:
The extracted column vector.
- getDiag(self) visp._visp.core.ColVector ¶
Extract a diagonal vector from a matrix.
Warning
An empty vector is returned if the matrix is empty.
The following example shows how to use this function:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3, 4); for (unsigned int i = 0; i < A.getRows(); i++) for (unsigned int j = 0; j < A.getCols(); j++) A[i][j] = i*A.getCols()+j; A.print(std::cout, 4); vpColVector diag = A.getDiag(); std::cout << "Diag vector: \n" << diag.t() << std::endl; }
It produces the following output :
[3, 4] = 0 1 2 3 4 5 6 7 8 9 10 11 Diag vector : 0 5 10
- Returns:
The diagonal of the matrix.
- static getLapackMatrixMinSize() int ¶
Return the minimum size of rows and columns required to enable Blas/Lapack usage on matrices and vectors.
To get more info see tutorial-basic-linear-algebra.
Note
See setLapackMatrixMinSize()
- getRow(*args, **kwargs)¶
Overloaded function.
getRow(self: visp._visp.core.Matrix, i: int) -> visp._visp.core.RowVector
The following example shows how to use this function:
#include <visp3/core/vpMatrix.h> #include <visp3/core/vpRowVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); for(unsigned int i=0; i < A.getRows(); i++) for(unsigned int j=0; j < A.getCols(); j++) A[i][j] = i*A.getCols()+j; A.print(std::cout, 4); vpRowVector rv = A.getRow(1); std::cout << "Row vector: \n" << rv << std::endl; }
It produces the following output :
[4, 4] = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Row vector : 4 5 6 7
- Parameters:
- i
Index of the row to extract. If i=0, the first row is extracted.
- Returns:
The extracted row vector.
getRow(self: visp._visp.core.Matrix, i: int, j_begin: int, size: int) -> visp._visp.core.RowVector
The following example shows how to use this function:
#include <visp3/core/vpMatrix.h> #include <visp3/core/vpRowVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4, 4); for (unsigned int i = 0; i < A.getRows(); i++) for (unsigned int j = 0; j < A.getCols(); j++) A[i][j] = i*A.getCols()+j; A.print(std::cout, 4); vpRowVector rv = A.getRow(1, 1, 3); std::cout << "Row vector: \n" << rv << std::endl; }
It produces the following output :
[4, 4] = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Row vector : 5 6 7
- Parameters:
- i
Index of the row to extract.If i = 0, the first row is extracted.
- j_begin
Index of the column that gives the location of the first element of the row vector to extract.
- Returns:
The extracted row vector.
- hadamard(*args, **kwargs)¶
Overloaded function.
hadamard(self: visp._visp.core.Matrix, m: visp._visp.core.Matrix) -> visp._visp.core.Matrix
- Parameters:
- m
Second matrix;
- Returns:
m1.hadamard(m2) The Hadamard product : \(m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j}\)
hadamard(self: visp._visp.core.ArrayDouble2D, m: visp._visp.core.ArrayDouble2D) -> visp._visp.core.ArrayDouble2D
- Parameters:
- m
Second matrix;
- Returns:
m1.hadamard(m2) The Hadamard product : \(m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j}\)
- inducedL2Norm(self) float ¶
Compute and return the induced L2 norm \(||A|| = \Sigma_{max}(A)\) which is equal to the maximum singular value of the matrix.
Note
See infinityNorm() , frobeniusNorm()
- Returns:
The induced L2 norm if the matrix is initialized, 0 otherwise.
- infinityNorm(self) float ¶
Compute and return the infinity norm \({||A||}_{\infty} = max\left(\sum_{j=0}^{n}{\mid A_{ij} \mid}\right)\) with \(i \in \{0, ..., m\}\) where \((m,n)\) is the matrix size.
Note
See frobeniusNorm() , inducedL2Norm()
- Returns:
The infinity norm if the matrix is initialized, 0 otherwise.
- init(self, M: visp._visp.core.Matrix, r: int, c: int, nrows: int, ncols: int) None ¶
Initialize the matrix from a part of an input matrix M .
The sub-matrix starting from M[r][c] element and ending on M[r+nrows-1][c+ncols-1] element is used to initialize the matrix.
The following code shows how to use this function:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix M(4,5); int val = 0; for(size_t i=0; i<M.getRows(); i++) { for(size_t j=0; j<M.getCols(); j++) { M[i][j] = val++; } } M.print(std::cout, 4, "M "); vpMatrix N; N.init(M, 0, 1, 2, 3); N.print(std::cout, 4, "N "); }
It produces the following output:
M [4,5]= 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 N [2,3]= 1 2 3 6 7 8
Note
See extract()
- insert(*args, **kwargs)¶
Overloaded function.
insert(self: visp._visp.core.Matrix, A: visp._visp.core.Matrix, r: int, c: int) -> None
Insert matrix A at the given position in the current matrix.
Warning
Throw vpException::dimensionError if the dimensions of the matrices do not allow the operation.
- Parameters:
- A
The matrix to insert.
- r
The index of the row to begin to insert data.
- c
The index of the column to begin to insert data.
insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, r: int, c: int) -> None
Insert array A at the given position in the current array.
Warning
Throw vpException::dimensionError if the dimensions of the matrices do not allow the operation.
- Parameters:
- A
The array to insert.
- r
The index of the row to begin to insert data.
- c
The index of the column to begin to insert data.
insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, r: int, c: int) -> visp._visp.core.ArrayDouble2D
Insert array B in array A at the given position.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.
- Parameters:
- A
Main array.
- B
Array to insert.
- r
Index of the row where to add the array.
- c
Index of the column where to add the array.
- Returns:
Array with B insert in A.
- static insertMatrixInMatrix(*args, **kwargs)¶
Overloaded function.
insertMatrixInMatrix(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, r: int, c: int) -> visp._visp.core.Matrix
Insert matrix B in matrix A at the given position.
Warning
Throw exception if the sizes of the matrices do not allow the insertion.
- Parameters:
- A
Main matrix.
- B
Matrix to insert.
- r
Index of the row where to add the matrix.
- c
Index of the column where to add the matrix.
- Returns:
Matrix with B insert in A.
insertMatrixInMatrix(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix, r: int, c: int) -> None
Insert matrix B in matrix A at the given position.
Warning
Throw exception if the sizes of the matrices do not allow the insertion.
- Parameters:
- A
Main matrix.
- B
Matrix to insert.
- C
Result matrix.
- r
Index of the row where to insert matrix B.
- c
Index of the column where to insert matrix B.
- static insertStatic(A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, C: visp._visp.core.ArrayDouble2D, r: int, c: int) None ¶
Insert array B in array A at the given position.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.
- Parameters:
- A: visp._visp.core.ArrayDouble2D¶
Main array.
- B: visp._visp.core.ArrayDouble2D¶
Array to insert.
- C: visp._visp.core.ArrayDouble2D¶
Result array.
- r: int¶
Index of the row where to insert array B.
- c: int¶
Index of the column where to insert array B.
- inverseByCholesky(self) visp._visp.core.Matrix ¶
Compute the inverse of a n-by-n matrix using the Cholesky decomposition. The matrix must be real symmetric positive defined.
This function calls the first following function that is available:
inverseByCholeskyLapack() if Lapack 3rd party is installed
inverseByLUOpenCV() if OpenCV 3rd party is installed.
If none of these 3rd parties is installed we use a Lapack built-in version.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); // Symmetric matrix A[0][0] = 1/1.; A[0][1] = 1/5.; A[0][2] = 1/6.; A[0][3] = 1/7.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/3.; A[2][2] = 1/2.; A[2][3] = 1/6.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.; // Compute the inverse vpMatrix A_1; // A^-1 A_1 = A.inverseByCholesky(); std::cout << "Inverse by Cholesky: \n" << A_1 << std::endl; std::cout << "A*A^-1: \n" << A * A_1 << std::endl; }
Note
See pseudoInverse()
- Returns:
The inverse matrix.
- inverseByCholeskyLapack(self) visp._visp.core.Matrix ¶
Compute the inverse of a n-by-n matrix using the Cholesky decomposition with Lapack 3rd party. The matrix must be real symmetric positive defined.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { unsigned int n = 4; vpMatrix A(n, n); vpMatrix I; I.eye(4); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.; // Make matrix symmetric positive A = 0.5*(A+A.t()); A = A + n*I; // Compute the inverse vpMatrix A_1 = A.inverseByCholeskyLapack(); std::cout << "Inverse by Cholesky (Lapack): \n" << A_1 << std::endl; std::cout << "A*A^-1: \n" << A * A_1 << std::endl; }
Note
See inverseByCholesky() , inverseByCholeskyOpenCV()
- Returns:
The inverse matrix.
- inverseByCholeskyOpenCV(self) visp._visp.core.Matrix ¶
Compute the inverse of a n-by-n matrix using the Cholesky decomposition with OpenCV 3rd party. The matrix must be real symmetric positive defined.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { unsigned int n = 4; vpMatrix A(n, n); vpMatrix I; I.eye(4); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.; // Make matrix symmetric positive A = 0.5*(A+A.t()); A = A + n*I; // Compute the inverse vpMatrix A_1 = A.inverseByCholeskyOpenCV(); std::cout << "Inverse by Cholesky (OpenCV): \n" << A_1 << std::endl; std::cout << "A*A^-1: \n" << A * A_1 << std::endl; }
Note
See inverseByCholesky() , inverseByCholeskyLapack()
- Returns:
The inverse matrix.
- inverseByLU(self) visp._visp.core.Matrix ¶
Compute the inverse of a n-by-n matrix using the LU decomposition.
This function calls the first following function that is available:
inverseByLULapack() if Lapack 3rd party is installed
inverseByLUEigen3() if Eigen3 3rd party is installed
inverseByLUOpenCV() if OpenCV 3rd party is installed
If none of these previous 3rd parties is installed, we use by default inverseByLULapack() with a Lapack built-in version.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.; // Compute the inverse vpMatrix A_1 = A.inverseByLU(); std::cout << "Inverse by LU "; #if defined(VISP_HAVE_LAPACK) std::cout << "(using Lapack)"; #elif defined(VISP_HAVE_EIGEN3) std::cout << "(using Eigen3)"; #elif defined(VISP_HAVE_OPENCV) std::cout << "(using OpenCV)"; #endif std::cout << ": \n" << A_1 << std::endl; std::cout << "A*A^-1: \n" << A * A_1 << std::endl; }
Note
See inverseByLULapack() , inverseByLUEigen3() , inverseByLUOpenCV() , pseudoInverse()
- Returns:
The inverse matrix.
- inverseByLUEigen3(self) visp._visp.core.Matrix ¶
Compute the inverse of a n-by-n matrix using the LU decomposition with Eigen3 3rd party.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.; // Compute the inverse vpMatrix A_1; // A^-1 A_1 = A.inverseByLUEigen3(); std::cout << "Inverse by LU (Eigen3): \n" << A_1 << std::endl; std::cout << "A*A^-1: \n" << A * A_1 << std::endl; }
Note
See inverseByLU() , inverseByLULapack() , inverseByLUOpenCV()
- Returns:
The inverse matrix.
- inverseByLULapack(self) visp._visp.core.Matrix ¶
Compute the inverse of a n-by-n matrix using the LU decomposition with Lapack 3rd party.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.; // Compute the inverse vpMatrix A_1; // A^-1 A_1 = A.inverseByLULapack(); std::cout << "Inverse by LU (Lapack): \n" << A_1 << std::endl; std::cout << "A*A^-1: \n" << A * A_1 << std::endl; }
Note
See inverseByLU() , inverseByLUEigen3() , inverseByLUOpenCV()
- Returns:
The inverse matrix.
- inverseByLUOpenCV(self) visp._visp.core.Matrix ¶
Compute the inverse of a n-by-n matrix using the LU decomposition with OpenCV 3rd party.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.; // Compute the inverse vpMatrix A_1; // A^-1 A_1 = A.inverseByLUOpenCV(); std::cout << "Inverse by LU (OpenCV): \n" << A_1 << std::endl; std::cout << "A*A^-1: \n" << A * A_1 << std::endl; }
Note
See inverseByLU() , inverseByLUEigen3() , inverseByLULapack()
- Returns:
The inverse matrix.
- inverseByQR(self) visp._visp.core.Matrix ¶
Compute the inverse of a n-by-n matrix using the QR decomposition. Only available if Lapack 3rd party is installed. If Lapack is not installed we use a Lapack built-in version.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.; // Compute the inverse vpMatrix A_1 = A.inverseByQR(); std::cout << "Inverse by QR: \n" << A_1 << std::endl; std::cout << "A*A^-1: \n" << A * A_1 << std::endl; }
Note
See inverseByLU() , inverseByCholesky()
- Returns:
The inverse matrix.
- inverseByQRLapack(self) visp._visp.core.Matrix ¶
Compute the inverse of a n-by-n matrix using the QR decomposition with Lapack 3rd party.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(4,4); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[0][3] = 1/4.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[1][3] = 1/5.; A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[2][3] = 1/6.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; A[3][3] = 1/7.; // Compute the inverse vpMatrix A_1 = A.inverseByQRLapack(); std::cout << "Inverse by QR: \n" << A_1 << std::endl; std::cout << "A*A^-1: \n" << A * A_1 << std::endl; }
Note
See inverseByQR()
- Returns:
The inverse matrix.
- inverseTriangular(self, upper: bool = true) visp._visp.core.Matrix ¶
Compute the inverse of a full-rank n-by-n triangular matrix. Only available if Lapack 3rd party is installed. If Lapack is not installed we use a Lapack built-in version.
The function does not check if the matrix is actually upper or lower triangular.
- static juxtaposeMatrices(*args, **kwargs)¶
Overloaded function.
juxtaposeMatrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Juxtapose to matrices C = [ A B ].
\(C = \left( \begin{array}{cc} A & B \end{array}\right)\)
Warning
A and B must have the same number of rows.
- Parameters:
- A
Left matrix.
- B
Right matrix.
- Returns:
Juxtaposed matrix C = [ A B ]
juxtaposeMatrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix) -> None
Juxtapose to matrices C = [ A B ].
\(C = \left( \begin{array}{cc} A & B \end{array}\right)\)
Warning
A and B must have the same number of rows.
- Parameters:
- A
Left matrix.
- B
Right matrix.
- C
Juxtaposed matrix C = [ A B ]
- kernel(self, kerAt: visp._visp.core.Matrix, svThreshold: float = 1e-6) int ¶
Function to compute the null space (the kernel) of a m-by-n matrix \(\bf A\) .
The null space of a matrix \(\bf A\) is defined as \(\mbox{Ker}({\bf A}) = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\) .
- Parameters:
- kerAt: visp._visp.core.Matrix¶
The matrix that contains the null space (kernel) of \(\bf A\) defined by the matrix \({\bf X}^T\) . If matrix \(\bf A\) is full rank, the dimension of kerAt is (0, n), otherwise the dimension is (n-r, n). This matrix is thus the transpose of \(\mbox{Ker}({\bf A})\) .
- svThreshold: float = 1e-6¶
Threshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
- Returns:
The rank of the matrix.
- kron(*args, **kwargs)¶
Overloaded function.
kron(self: visp._visp.core.Matrix, m1: visp._visp.core.Matrix, out: visp._visp.core.Matrix) -> None
Compute Kronecker product matrix.
- Parameters:
- out
If m1.kron(m2) out contains the kronecker product’s result : \(m1 \otimes m2\) .
kron(self: visp._visp.core.Matrix, m1: visp._visp.core.Matrix) -> visp._visp.core.Matrix
- Returns:
m1.kron(m2) The kronecker product : \(m1 \otimes m2\)
- static kronStatic(*args, **kwargs)¶
Overloaded function.
kronStatic(m1: visp._visp.core.Matrix, m2: visp._visp.core.Matrix, out: visp._visp.core.Matrix) -> None
Compute Kronecker product matrix.
- Parameters:
- m1
vpMatrix ;
- m2
vpMatrix ;
- out
The kronecker product : \(m1 \otimes m2\)
kronStatic(m1: visp._visp.core.Matrix, m2: visp._visp.core.Matrix) -> visp._visp.core.Matrix
- Parameters:
- m1
vpMatrix ;
- m2
vpMatrix ;
- Returns:
The kronecker product : \(m1 \otimes m2\)
- static mult2Matrices(*args, **kwargs)¶
Overloaded function.
mult2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix) -> None
Operation C = A * B.
The result is placed in the third parameter C and not returned. A new matrix won’t be allocated for every use of the function (speed gain if used many times with the same result matrix size).
Note
See operator*()
mult2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.RotationMatrix) -> None
Warning
This function is provided for compat with previous releases. You should rather use the functionalities provided in vpRotationMatrix class.
Operation C = A * B.
The result is placed in the third parameter C and not returned. A new matrix won’t be allocated for every use of the function (speed gain if used many times with the same result matrix size).
mult2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.HomogeneousMatrix) -> None
Warning
This function is provided for compat with previous releases. You should rather use the functionalities provided in vpHomogeneousMatrix class.
Operation C = A * B.
The result is placed in the third parameter C and not returned. A new matrix won’t be allocated for every use of the function (speed gain if used many times with the same result matrix size).
mult2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.ColVector, C: visp._visp.core.ColVector) -> None
Warning
This function is provided for compat with previous releases. You should rather use multMatrixVector() that is more explicit.
Operation C = A * B.
The result is placed in the third parameter C and not returned. A new matrix won’t be allocated for every use of the function (speed gain if used many times with the same result matrix size).
Note
See multMatrixVector()
- static multMatrixVector(A: visp._visp.core.Matrix, v: visp._visp.core.ColVector, w: visp._visp.core.ColVector) None ¶
Operation w = A * v (v and w are vectors).
A new matrix won’t be allocated for every use of the function (Speed gain if used many times with the same result matrix size).
Note
See operator*(const vpColVector &v) const
- static negateMatrix(A: visp._visp.core.Matrix, C: visp._visp.core.Matrix) None ¶
Operation C = -A.
The result is placed in the second parameter C and not returned. A new matrix won’t be allocated for every use of the function (Speed gain if used many times with the same result matrix size).
Note
See operator-(void)
- nullSpace(*args, **kwargs)¶
Overloaded function.
nullSpace(self: visp._visp.core.Matrix, kerA: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> int
Function to compute the null space (the kernel) of a m-by-n matrix \(\bf A\) .
The null space of a matrix \(\bf A\) is defined as \(\mbox{Ker}({\bf A}) = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\) .
- Parameters:
- kerA
The matrix that contains the null space (kernel) of \(\bf A\) . If matrix \(\bf A\) is full rank, the dimension of kerA is (n, 0), otherwise its dimension is (n, n-r).
- svThreshold
Threshold used to test the singular values. The dimension of kerA corresponds to the number of singular values lower than this threshold
- Returns:
The dimension of the nullspace, that is \(n - r\) .
nullSpace(self: visp._visp.core.Matrix, kerA: visp._visp.core.Matrix, dim: int) -> int
Function to compute the null space (the kernel) of a m-by-n matrix \(\bf A\) .
The null space of a matrix \(\bf A\) is defined as \(\mbox{Ker}({\bf A}) = { {\bf X} : {\bf A}*{\bf X} = {\bf 0}}\) .
- Parameters:
- kerA
The matrix that contains the null space (kernel) of \(\bf A\) . If matrix \(\bf A\) is full rank, the dimension of kerA is (n, 0), otherwise its dimension is (n, n-r).
- dim
the dimension of the null space when it is known a priori
- Returns:
The estimated dimension of the nullspace, that is \(n - r\) , by using 1e-6 as threshold for the sigular values.
- numpy(self) numpy.ndarray[numpy.float64] ¶
Numpy view of the underlying array data. This numpy view can be used to directly modify the array.
- print(self: visp._visp.core.Matrix, s: std::ostream, length: int, intro: str =) int ¶
Pretty print a matrix. The data are tabulated. The common widths before and after the decimal point are set with respect to the parameter length .
Note
See std::ostream & operator<<(std::ostream &s, const vpArray2D<Type> &A)
- Parameters:
- s
Stream used for the printing.
- length
The suggested width of each matrix element. If needed, the used length grows in order to accommodate the whole integral part, and shrinks the decimal part to print only length digits.
- intro
The introduction which is printed before the matrix. Can be set to zero (or omitted), in which case the introduction is not printed.
- Returns:
Returns the common total width for all matrix elements.
- pseudoInverse(*args, **kwargs)¶
Overloaded function.
pseudoInverse(self: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> visp._visp.core.Matrix
Compute and return the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) .
Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(2, 3); A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; A.print(std::cout, 10, "A: "); vpMatrix A_p = A.pseudoInverse(); A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); }
Once build, the previous example produces the following output:
A: [2,3]= 2 3 5 -4 2 3 A^+ (pseudo-inverse): [3,2]= 0.117899 -0.190782 0.065380 0.039657 0.113612 0.052518
- Parameters:
- svThreshold
Threshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
- Returns:
The Moore-Penros pseudo inverse \(A^+\) .
pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> int
Compute the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) and return the rank of the matrix.
Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(2, 3); A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; A.print(std::cout, 10, "A: "); vpMatrix A_p; unsigned int rank = A.pseudoInverse(A_p); A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); std::cout << "Rank: " << rank << std::endl; }
Once build, the previous example produces the following output:
A: [2,3]= 2 3 5 -4 2 3 A^+ (pseudo-inverse): [3,2]= 0.117899 -0.190782 0.065380 0.039657 0.113612 0.052518 Rank: 2
- Parameters:
- Ap
The Moore-Penros pseudo inverse \(A^+\) .
- svThreshold
Threshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
- Returns:
The rank of the matrix.
pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float = 1e-6) -> int
Compute the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) along with singular values and return the rank of the matrix.
Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(2, 3); A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; A.print(std::cout, 10, "A: "); vpMatrix A_p; vpColVector sv; unsigned int rank = A.pseudoInverse(A_p, sv); A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); std::cout << "Rank: " << rank << std::endl; std::cout << "Singular values: " << sv.t() << std::endl; }
Once build, the previous example produces the following output:
A: [2,3]= 2 3 5 -4 2 3 A^+ (pseudo-inverse): [3,2]= 0.117899 -0.190782 0.065380 0.039657 0.113612 0.052518 Rank: 2 Singular values: 6.874359351 4.443330227
- Parameters:
- Ap
The Moore-Penros pseudo inverse \(A^+\) .
- sv
Vector corresponding to matrix \(A\) singular values. The size of this vector is equal to min(m, n).
- svThreshold
Threshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
- Returns:
The rank of the matrix \(\bf A\) .
pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix) -> int
Compute the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) along with singular values, \(\mbox{Im}(A)\) and \(\mbox{Im}(A^T)\) and return the rank of the matrix.
See pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const for a complete description of this function.
Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(2, 3); A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; A.print(std::cout, 10, "A: "); vpMatrix A_p; vpColVector sv; vpMatrix imA, imAt; unsigned int rank = A.pseudoInverse(A_p, sv, 1e-6, imA, imAt); A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); std::cout << "Rank: " << rank << std::endl; std::cout << "Singular values: " << sv.t() << std::endl; imA.print(std::cout, 10, "Im(A): "); imAt.print(std::cout, 10, "Im(A^T): "); }
Once build, the previous example produces the following output:
A: [2,3]= 2 3 5 -4 2 3 A^+ (pseudo-inverse): [3,2]= 0.117899 -0.190782 0.065380 0.039657 0.113612 0.052518 Rank: 2 Singular values: 6.874359351 4.443330227 Im(A): [2,2]= 0.81458 -0.58003 0.58003 0.81458 Im(A^T): [3,2]= -0.100515 -0.994397 0.524244 -0.024967 0.845615 -0.102722
- Parameters:
- Ap
The Moore-Penros pseudo inverse \(A^+\) .
- sv
Vector corresponding to matrix \(A\) singular values. The size of this vector is equal to min(m, n).
- svThreshold
Threshold used to test the singular values. If a singular value is lower than this threshold we consider that the matrix is not full rank.
- imA
math:mbox{Im}({bf A}) that is a m-by-r matrix.
- imAt
math:mbox{Im}({bf A}^T) that is n-by-r matrix.
- Returns:
The rank of the matrix \(\bf A\) .
pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int
Compute the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) along with singular values, \(\mbox{Im}(A)\) , \(\mbox{Im}(A^T)\) and \(\mbox{Ker}(A)\) and return the rank of the matrix.
Here an example to compute the pseudo - inverse of a 2 - by - 3 matrix that is rank 2.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(2, 3); A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; A.print(std::cout, 10, "A: "); vpColVector sv; vpMatrix A_p, imA, imAt, kerAt; unsigned int rank = A.pseudoInverse(A_p, sv, 1e-6, imA, imAt, kerAt); A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); std::cout << "Rank: " << rank << std::endl; std::cout << "Singular values: " << sv.t() << std::endl; imA.print(std::cout, 10, "Im(A): "); imAt.print(std::cout, 10, "Im(A^T): "); if (kerAt.size()) { kerAt.t().print(std::cout, 10, "Ker(A): "); } else { std::cout << "Ker(A) empty " << std::endl; } // Reconstruct matrix A from ImA, ImAt, KerAt vpMatrix S(rank, A.getCols()); for (unsigned int i = 0; i< rank; i++) S[i][i] = sv[i]; vpMatrix Vt(A.getCols(), A.getCols()); Vt.insert(imAt.t(), 0, 0); Vt.insert(kerAt, rank, 0); (imA *S *Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); }
Once build, the previous example produces the following output :
A: [2,3] = 2 3 5 -4 2 3 A^+(pseudo-inverse): [3,2]= 0.117899 -0.190782 0.065380 0.039657 0.113612 0.052518 Rank: 2 Singular values: 6.874359351 4.443330227 Im(A): [2,2]= 0.81458 -0.58003 0.58003 0.81458 Im(A^T): [3,2] = -0.100515 -0.994397 0.524244 -0.024967 0.845615 -0.102722 Ker(A): [3,1]= -0.032738 -0.851202 0.523816 Im(A) * S * [Im(A^T) | Ker(A)]^T: [2,3]= 2 3 5 -4 2 3
- Parameters:
- Ap
The Moore-Penros pseudo inverse \({\bf A}^+\) .
- sv
Vector corresponding to matrix A singular values. The size of this vector is equal to min(m, n).
- svThreshold
Threshold used to test the singular values.If a singular value is lower than this threshold we consider that the matrix is not full rank.
- imA
math:mbox { Im }({ bf A }) that is a m - by - r matrix.
- imAt
math:mbox { Im }({ bf A } ^ T) that is n - by - r matrix.
- kerAt
The matrix that contains the null space(kernel) of \(\bf A\) defined by the matrix \({ \bf X } ^ T\) .If matrix \(\bf A\) is full rank, the dimension of kerAt is(0, n), otherwise the dimension is (n - r, n). This matrix is thus the transpose of \(\mbox { Ker }({ \bf A })\) .
- Returns:
The rank of the matrix \(\bf A\) .
pseudoInverse(self: visp._visp.core.Matrix, rank_in: int) -> visp._visp.core.Matrix
Compute and return the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) .
Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(2, 3); // This matrix rank is 2 A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; A.print(std::cout, 10, "A: "); int rank_in = 2; vpMatrix A_p = A.pseudoInverseLapack(rank_in); A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); }
Once build, the previous example produces the following output:
A: [2,3]= 2 3 5 -4 2 3 A^+ (pseudo-inverse): [3,2]= 0.117899 -0.190782 0.065380 0.039657 0.113612 0.052518
- Parameters:
- rank_in
Known rank of the matrix.
- Returns:
The Moore-Penros pseudo inverse \(A^+\) .
pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, rank_in: int) -> int
Compute the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) and return the rank of the matrix.
Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(2, 3); // This matrix rank is 2 A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; A.print(std::cout, 10, "A: "); vpMatrix A_p; int rank_in = 2; int rank_out = A.pseudoInverse(A_p, rank_in); if (rank_out != rank_in) { std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; } A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); std::cout << "Rank in : " << rank_in << std::endl; std::cout << "Rank out: " << rank_out << std::endl; }
Once build, the previous example produces the following output:
A: [2,3]= 2 3 5 -4 2 3 A^+ (pseudo-inverse): [3,2]= 0.117899 -0.190782 0.065380 0.039657 0.113612 0.052518 Rank in : 2 Rank out: 2
- Parameters:
- Ap
The Moore-Penros pseudo inverse \(A^+\) .
- rank_in
Known rank of the matrix.
- Returns:
The rank of the matrix.
pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int) -> int
Compute the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) along with singular values and return the rank of the matrix.
Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(2, 3); A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; A.print(std::cout, 10, "A: "); vpMatrix A_p; vpColVector sv; int rank_in = 2; int rank_out = A.pseudoInverse(A_p, sv, rank_in); if (rank_out != rank_in) { std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; } A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); std::cout << "Rank in : " << rank_in << std::endl; std::cout << "Rank out: " << rank_out << std::endl; std::cout << "Singular values: " << sv.t() << std::endl; }
Once build, the previous example produces the following output:
A: [2,3]= 2 3 5 -4 2 3 A^+ (pseudo-inverse): [3,2]= 0.117899 -0.190782 0.065380 0.039657 0.113612 0.052518 Rank in : 2 Rank out: 2 Singular values: 6.874359351 4.443330227
- Parameters:
- Ap
The Moore-Penros pseudo inverse \(A^+\) .
- sv
Vector corresponding to matrix \(A\) singular values. The size of this vector is equal to min(m, n).
- rank_in
Known rank of the matrix.
- Returns:
The rank of the matrix \(\bf A\) .
pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix) -> int
Compute the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) along with singular values, \(\mbox{Im}(A)\) and \(\mbox{Im}(A^T)\) and return the rank of the matrix.
See pseudoInverse(vpMatrix &, vpColVector &, double, vpMatrix &, vpMatrix &, vpMatrix &) const for a complete description of this function.
Here an example to compute the pseudo-inverse of a 2-by-3 matrix that is rank 2.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(2, 3); A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; A.print(std::cout, 10, "A: "); vpMatrix A_p; vpColVector sv; vpMatrix imA, imAt; int rank_in = 2; int rank_out = A.pseudoInverse(A_p, sv, rank_in, imA, imAt); if (rank_out != rank_in) { std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; } A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); std::cout << "Rank in : " << rank_in << std::endl; std::cout << "Rank out: " << rank_in << std::endl; std::cout << "Singular values: " << sv.t() << std::endl; imA.print(std::cout, 10, "Im(A): "); imAt.print(std::cout, 10, "Im(A^T): "); }
Once build, the previous example produces the following output:
A: [2,3]= 2 3 5 -4 2 3 A^+ (pseudo-inverse): [3,2]= 0.117899 -0.190782 0.065380 0.039657 0.113612 0.052518 Rank: 2 Singular values: 6.874359351 4.443330227 Im(A): [2,2]= 0.81458 -0.58003 0.58003 0.81458 Im(A^T): [3,2]= -0.100515 -0.994397 0.524244 -0.024967 0.845615 -0.102722
- Parameters:
- Ap
The Moore-Penros pseudo inverse \(A^+\) .
- sv
Vector corresponding to matrix \(A\) singular values. The size of this vector is equal to min(m, n).
- rank_in
Known rank of the matrix.
- imA
math:mbox{Im}({bf A}) that is a m-by-r matrix.
- imAt
math:mbox{Im}({bf A}^T) that is n-by-r matrix.
- Returns:
The rank of the matrix \(\bf A\) .
pseudoInverse(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int
Compute the Moore-Penros pseudo inverse \(A^+\) of a m-by-n matrix \(\bf A\) along with singular values, \(\mbox{Im}(A)\) , \(\mbox{Im}(A^T)\) and \(\mbox { Ker }(A)\) and return the rank of the matrix.
Here an example to compute the pseudo - inverse of a 2 - by - 3 matrix that is rank 2.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(2, 3); A[0][0] = 2; A[0][1] = 3; A[0][2] = 5; A[1][0] = -4; A[1][1] = 2; A[1][2] = 3; A.print(std::cout, 10, "A: "); vpColVector sv; vpMatrix A_p, imA, imAt, kerAt; int rank_in = 2; int rank_out = A.pseudoInverse(A_p, sv, rank_in, imA, imAt, kerAt); if (rank_out != rank_in) { std::cout << "There is a possibility that the pseudo-inverse in wrong." << std::endl; std::cout << "Are you sure that the matrix rank is " << rank_in << std::endl; } A_p.print(std::cout, 10, "A^+ (pseudo-inverse): "); std::cout << "Rank in : " << rank_in << std::endl; std::cout << "Rank out: " << rank_out << std::endl; std::cout << "Singular values: " << sv.t() << std::endl; imA.print(std::cout, 10, "Im(A): "); imAt.print(std::cout, 10, "Im(A^T): "); if (kerAt.size()) { kerAt.t().print(std::cout, 10, "Ker(A): "); } else { std::cout << "Ker(A) empty " << std::endl; } // Reconstruct matrix A from ImA, ImAt, KerAt vpMatrix S(rank, A.getCols()); for (unsigned int i = 0; i < rank_in; i++) S[i][i] = sv[i]; vpMatrix Vt(A.getCols(), A.getCols()); Vt.insert(imAt.t(), 0, 0); Vt.insert(kerAt, rank, 0); (imA * S * Vt).print(std::cout, 10, "Im(A) * S * [Im(A^T) | Ker(A)]^T:"); }
Once build, the previous example produces the following output :
A : [2, 3] = 2 3 5 - 4 2 3 A ^ +(pseudo - inverse) : [3, 2] = 0.117899 - 0.190782 0.065380 0.039657 0.113612 0.052518 Rank in : 2 Rank out : 2 Singular values : 6.874359351 4.443330227 Im(A) : [2, 2] = 0.81458 - 0.58003 0.58003 0.81458 Im(A ^ T) : [3, 2] = -0.100515 - 0.994397 0.524244 - 0.024967 0.845615 - 0.102722 Ker(A) : [3, 1] = -0.032738 - 0.851202 0.523816 Im(A) * S *[Im(A ^ T) | Ker(A)] ^ T : [2, 3] = 2 3 5 - 4 2 3
- Parameters:
- Ap
The Moore - Penros pseudo inverse \({ \bf A } ^ +\) .
- sv
Vector corresponding to matrix \(A\) singular values.The size of this vector is equal to min(m, n).
- rank_in
Known rank of the matrix.
- imA
math:mbox { Im }({ bf A }) that is a m - by - r matrix.
- imAt
math:mbox { Im }({ bf A } ^T) that is n - by - r matrix.
- kerAt
The matrix that contains the null space(kernel) of \(\bf A\) defined by the matrix \({ \bf X } ^ T\) .If matrix \(\bf A\) is full rank, the dimension of kerAt is(0, n), otherwise the dimension is(n - r, n).This matrix is thus the transpose of \(\mbox { Ker }({ \bf A })\) .
- Returns:
The rank of the matrix \(\bf A\) .
- pseudoInverseEigen3(*args, **kwargs)¶
Overloaded function.
pseudoInverseEigen3(self: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> visp._visp.core.Matrix
pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> int
pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float = 1e-6) -> int
pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int
pseudoInverseEigen3(self: visp._visp.core.Matrix, rank_in: int) -> visp._visp.core.Matrix
pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, rank_in: int) -> int
pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int) -> int
pseudoInverseEigen3(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int
- pseudoInverseLapack(*args, **kwargs)¶
Overloaded function.
pseudoInverseLapack(self: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> visp._visp.core.Matrix
pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> int
pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float = 1e-6) -> int
pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int
pseudoInverseLapack(self: visp._visp.core.Matrix, rank_in: int) -> visp._visp.core.Matrix
pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, rank_in: int) -> int
pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int) -> int
pseudoInverseLapack(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int
- pseudoInverseOpenCV(*args, **kwargs)¶
Overloaded function.
pseudoInverseOpenCV(self: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> visp._visp.core.Matrix
pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, svThreshold: float = 1e-6) -> int
pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float = 1e-6) -> int
pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, svThreshold: float, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int
pseudoInverseOpenCV(self: visp._visp.core.Matrix, rank_in: int) -> visp._visp.core.Matrix
pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, rank_in: int) -> int
pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int) -> int
pseudoInverseOpenCV(self: visp._visp.core.Matrix, Ap: visp._visp.core.Matrix, sv: visp._visp.core.ColVector, rank_in: int, imA: visp._visp.core.Matrix, imAt: visp._visp.core.Matrix, kerAt: visp._visp.core.Matrix) -> int
- qr(self, Q: visp._visp.core.Matrix, R: visp._visp.core.Matrix, full: bool = false, squareR: bool = false, tol: float = 1e-6) int ¶
Compute the QR decomposition of a (m x n) matrix of rank r. Only available if Lapack 3rd party is installed. If Lapack is not installed we use a Lapack built-in version.
If full is false (default) then Q is (m x min(n,m)) and R is (min(n,m) x n). We then have this = QR.
If full is true and m > n then Q is (m x m) and R is (n x n). In this case this = Q (R, 0)^T
If squareR is true and n > m then R is (m x m). If r = m then R is invertible.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif double residual(vpMatrix M1, vpMatrix M2) { return (M1 - M2).frobeniusNorm(); } int main() { vpMatrix A(4,3); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/3.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/2.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/6.; // Economic QR (Q 4x3, R 3x3) vpMatrix Q, R; int r = A.qr(A, R); std::cout << "QR Residual: " << residual(A, Q*R) << std::endl; // Full QR (Q 4x4, R 3x3) r = A.qr(Q, R, true); std::cout << "Full QR Residual: " << residual(A, Q.extract(0, 0, 4, 3)*R) << std::endl; }
Note
See qrPivot()
- Parameters:
- Q: visp._visp.core.Matrix¶
orthogonal matrix (will be modified).
- R: visp._visp.core.Matrix¶
upper-triangular matrix (will be modified).
- full: bool = false¶
whether or not we want full decomposition.
- squareR: bool = false¶
will return only the square (min(m,n) x min(m,n)) part of R.
- tol: float = 1e-6¶
tolerance to test the rank of R.
- Returns:
The rank r of the matrix.
- qrPivot(self, Q: visp._visp.core.Matrix, R: visp._visp.core.Matrix, P: visp._visp.core.Matrix, full: bool = false, squareR: bool = false, tol: float = 1e-6) int ¶
Compute the QR pivot decomposition of a (m x n) matrix of rank r. Only available if Lapack 3rd party is installed. If Lapack is not installed we use a Lapack built-in version.
If full is false (default) then Q is (m x min(n,m)) and R is (min(n,m) x n). We then have this.P = Q.R.
If full is true and m > n then Q is (m x m) and R is (n x n). In this case this.P = Q (R, 0)^T
If squareR is true then R is (r x r) invertible.
Here an example:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif double residual(vpMatrix M1, vpMatrix M2) { return (M1 - M2).frobeniusNorm(); } int main() { vpMatrix A(4,3); A[0][0] = 1/1.; A[0][1] = 1/2.; A[0][2] = 1/2.; A[1][0] = 1/5.; A[1][1] = 1/3.; A[1][2] = 1/3.; A[2][0] = 1/6.; A[2][1] = 1/4.; A[2][2] = 1/4.; A[3][0] = 1/7.; A[3][1] = 1/5.; A[3][2] = 1/5.; // A is (4x3) but rank 2 // Economic QR (Q 4x3, R 3x3) vpMatrix Q, R, P; int r = A.qrPivot(Q, R, P); std::cout << "A rank: " << r << std::endl; std::cout << "Residual: " << residual(A*P, Q*R) << std::endl; // Full QR (Q 4x4, R 3x3) r = A.qrPivot(Q, R, P, true); std::cout << "QRPivot Residual: " << residual(A*P, Q.extract(0, 0, 4, 3)*R) << std::endl; // Using permutation matrix: keep only non-null part of R Q.resize(4, r, false); // Q is 4 x 2 R = R.extract(0, 0, r, 3)*P.t(); // R is 2 x 3 std::cout << "Full QRPivot Residual: " << residual(A, Q*R) << std::endl; }
Note
See qrPivot()
- Parameters:
- Q: visp._visp.core.Matrix¶
orthogonal matrix (will be modified).
- R: visp._visp.core.Matrix¶
upper-triangular matrix (will be modified).
- P: visp._visp.core.Matrix¶
the (n x n) permutation matrix.
- full: bool = false¶
whether or not we want full decomposition.
- squareR: bool = false¶
will return only the (r x r) part of R and the (r x n) part of P.
- tol: float = 1e-6¶
tolerance to test the rank of R.
- Returns:
The rank r of the matrix.
- resize(self, nrows: int, ncols: int, flagNullify: bool = true, recopy_: bool = true) None ¶
Set the size of the array and initialize all the values to zero.
- Parameters:
- nrows: int¶
number of rows.
- ncols: int¶
number of column.
- flagNullify: bool = true¶
if true, then the array is re-initialized to 0 after resize. If false, the initial values from the common part of the array (common part between old and new version of the array) are kept. Default value is true.
- recopy_: bool = true¶
if true, will perform an explicit recopy of the old data.
- static save(*args, **kwargs)¶
Overloaded function.
save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
Save a matrix to a file.
Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.
Note
See load()
- Parameters:
- filename
Absolute file name.
- A
Array to be saved.
- binary
If true the matrix is saved in a binary file, else a text file.
- header
Optional line that will be saved at the beginning of the file.
- Returns:
Returns true if success.
save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
Save a matrix to a file.
Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.
Note
See load()
- Parameters:
- filename
Absolute file name.
- A
Array to be saved.
- binary
If true the matrix is saved in a binary file, else a text file.
- header
Optional line that will be saved at the beginning of the file.
- Returns:
Returns true if success.
save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
Save a matrix to a file.
Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.
Note
See load()
- Parameters:
- filename
Absolute file name.
- A
Array to be saved.
- binary
If true the matrix is saved in a binary file, else a text file.
- header
Optional line that will be saved at the beginning of the file.
- Returns:
Returns true if success.
- static saveMatrix(filename: str, M: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str =) bool ¶
Save a matrix to a file. This function overloads vpArray2D::save() .
Warning
If you save the matrix as a text file the precision is less than if you save it as a binary file.
The following example shows how to use this function:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { std::string filename("matrix.bin"); bool binary_data = true; { vpMatrix M(2, 3); M[0][0] = -1; M[0][1] = -2; M[0][2] = -3; M[1][0] = 4; M[1][1] = 5.5; M[1][2] = 6.0f; std::string header("My header"); if (vpMatrix::saveMatrix(filename, M, binary_data, header.c_str())) { std::cout << "Matrix saved in " << filename << std::endl; M.print(std::cout, 10, header); } else { std::cout << "Cannot save matrix in " << filename << std::endl; } } { vpMatrix N; char header[FILENAME_MAX]; if (vpMatrix::loadMatrix(filename, N, binary_data, header)) { std::cout << "Matrix loaded from " << filename << std::endl; N.print(std::cout, 10, header); } else { std::cout << "Cannot load matrix from " << filename << std::endl; } } }
The output of this example is the following:
Matrix saved in matrix.bin My header[2,3]= -1.0 -2.0 -3.0 4.0 5.5 6.0 Matrix loaded from matrix.bin My header[2,3]= -1.0 -2.0 -3.0 4.0 5.5 6.0
And the content of matrix.bin file where data are saved as binary data is the following:
% cat matrix.bin My header??@@@%
Note
See loadMatrix() , saveMatrixYAML() , loadMatrixYAML()
- Parameters:
- filename
Absolute file name.
- M
Matrix to be saved.
- binary
If true the matrix is save as a binary file, otherwise as a text file.
- header
Optional line that will be saved at the beginning of the file as a header.
- Returns:
Returns true if no problem appends.
- static saveMatrixYAML(filename: str, M: visp._visp.core.ArrayDouble2D, header: str =) bool ¶
Save a matrix in a YAML-formatted file. This function overloads vpArray2D::saveYAML() .
The following example shows how to use this function:
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { std::string filename("matrix.yaml"); { vpMatrix M(2, 3); M[0][0] = -1; M[0][1] = -2; M[0][2] = -3; M[1][0] = 4; M[1][1] = 5.5; M[1][2] = 6.0f; std::string header("My header"); if (vpMatrix::saveMatrixYAML(filename, M, header.c_str())) { std::cout << "Matrix saved in " << filename << std::endl; M.print(std::cout, 10, header); } else { std::cout << "Cannot save matrix in " << filename << std::endl; } } { vpMatrix N; char header[FILENAME_MAX]; if (vpMatrix::loadMatrixYAML(filename, N, header)) { std::cout << "Matrix loaded from " << filename << std::endl; N.print(std::cout, 10, header); } else { std::cout << "Cannot load matrix from " << filename << std::endl; } } }
The output of this example is the following:
Matrix saved in matrix.yaml My header[2,3]= -1.0 -2.0 -3.0 4.0 5.5 6.0 Matrix loaded from matrix.yaml My header[2,3]= -1.0 -2.0 -3.0 4.0 5.5 6.0
And the content of matrix.yaml file is the following:
% cat matrix.yaml My header rows: 2 cols: 3 data: - [-1, -2, -3] - [4, 5.5, 6]
Note
See saveMatrix() , loadMatrix() , loadMatrixYAML()
- Parameters:
- filename
Absolute file name.
- M
Matrix to be saved in the file.
- header
Optional lines that will be saved at the beginning of the file as a header.
- Returns:
Returns true if success.
- static saveYAML(filename: str, A: visp._visp.core.ArrayDouble2D, header: str =) bool ¶
Save an array in a YAML-formatted file.
Here is an example of outputs.
vpArray2D<double> M(3,4); vpArray2D::saveYAML("matrix.yml", M, "example: a YAML-formatted header"); vpArray2D::saveYAML("matrixIndent.yml", M, "example:\n - a YAML-formatted \ header\n - with inner indentation");
Content of matrix.yml:
example: a YAML-formatted header rows: 3 cols: 4 data: - [0, 0, 0, 0] - [0, 0, 0, 0] - [0, 0, 0, 0]
Content of matrixIndent.yml:
example: - a YAML-formatted header - with inner indentation rows: 3 cols: 4 data: - [0, 0, 0, 0] - [0, 0, 0, 0] - [0, 0, 0, 0]
Note
See loadYAML()
- Parameters:
- filename
absolute file name.
- A
array to be saved in the file.
- header
optional lines that will be saved at the beginning of the file. Should be YAML-formatted and will adapt to the indentation if any.
- Returns:
Returns true if success.
- static setLapackMatrixMinSize(min_size: int) None ¶
Modify default size used to determine if Blas/Lapack basic linear algebra operations are enabled.
To get more info see tutorial-basic-linear-algebra.
Note
See getLapackMatrixMinSize()
- Parameters:
- min_size: int¶
Minimum size of rows and columns required for a matrix or a vector to use Blas/Lapack third parties like MKL, OpenBLAS, Netlib or Atlas. When matrix or vector size is lower or equal to this parameter, Blas/Lapack is not used. In that case we prefer use naive code that runs faster for small matrices.
- solveByQR(*args, **kwargs)¶
Overloaded function.
solveByQR(self: visp._visp.core.Matrix, b: visp._visp.core.ColVector, x: visp._visp.core.ColVector) -> None
Solve a linear system Ax = b using QR Decomposition.
Non destructive wrt. A and b.
Warning
If Ax = b does not have a solution, this method does not return the least-square minimizer. Use solveBySVD() to get this vector.
Here an example:
#include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3,3); A[0][0] = 4.64; A[0][1] = 0.288; A[0][2] = -0.384; A[1][0] = 0.288; A[1][1] = 7.3296; A[1][2] = 2.2272; A[2][0] = -0.384; A[2][1] = 2.2272; A[2][2] = 6.0304; vpColVector X(3), B(3); B[0] = 1; B[1] = 2; B[2] = 3; A.solveByQR(B, X); // Obtained values of X // X[0] = 0.2468; // X[1] = 0.120782; // X[2] = 0.468587; std::cout << "X:\n" << X << std::endl; }
Note
See qrPivot()
- Parameters:
- b
Vector b
- x
Vector x
solveByQR(self: visp._visp.core.Matrix, b: visp._visp.core.ColVector) -> visp._visp.core.ColVector
Solve a linear system Ax = b using QR Decomposition.
Non destructive wrt. A and B.
Warning
If Ax = b does not have a solution, this method does not return the least-square minimizer. Use solveBySVD() to get this vector.
Here an example:
#include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3,3); A[0][0] = 4.64; A[0][1] = 0.288; A[0][2] = -0.384; A[1][0] = 0.288; A[1][1] = 7.3296; A[1][2] = 2.2272; A[2][0] = -0.384; A[2][1] = 2.2272; A[2][2] = 6.0304; vpColVector X(3), B(3); B[0] = 1; B[1] = 2; B[2] = 3; X = A.solveByQR(B); // Obtained values of X // X[0] = 0.2468; // X[1] = 0.120782; // X[2] = 0.468587; std::cout << "X:\n" << X << std::endl; }
Note
See qrPivot()
- Parameters:
- b
Vector b
- Returns:
Vector x
- solveBySVD(*args, **kwargs)¶
Overloaded function.
solveBySVD(self: visp._visp.core.Matrix, B: visp._visp.core.ColVector, x: visp._visp.core.ColVector) -> None
Solve a linear system \(A X = B\) using Singular Value Decomposition (SVD).
Non destructive wrt. A and B.
Here an example:
#include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3,3); A[0][0] = 4.64; A[0][1] = 0.288; A[0][2] = -0.384; A[1][0] = 0.288; A[1][1] = 7.3296; A[1][2] = 2.2272; A[2][0] = -0.384; A[2][1] = 2.2272; A[2][2] = 6.0304; vpColVector X(3), B(3); B[0] = 1; B[1] = 2; B[2] = 3; A.solveBySVD(B, X); // Obtained values of X // X[0] = 0.2468; // X[1] = 0.120782; // X[2] = 0.468587; std::cout << "X:\n" << X << std::endl; }
Note
See solveBySVD(const vpColVector &)
- Parameters:
- x
Vector \(X\) .
solveBySVD(self: visp._visp.core.Matrix, B: visp._visp.core.ColVector) -> visp._visp.core.ColVector
Solve a linear system \(A X = B\) using Singular Value Decomposition (SVD).
Non destructive wrt. A and B.
Here an example:
#include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix A(3,3); A[0][0] = 4.64; A[0][1] = 0.288; A[0][2] = -0.384; A[1][0] = 0.288; A[1][1] = 7.3296; A[1][2] = 2.2272; A[2][0] = -0.384; A[2][1] = 2.2272; A[2][2] = 6.0304; vpColVector X(3), B(3); B[0] = 1; B[1] = 2; B[2] = 3; X = A.solveBySVD(B); // Obtained values of X // X[0] = 0.2468; // X[1] = 0.120782; // X[2] = 0.468587; std::cout << "X:\n" << X << std::endl; }
Note
See solveBySVD(const vpColVector &, vpColVector &)
- Parameters:
- B
Vector \(B\) .
- Returns:
Vector \(X\) .
- stack(*args, **kwargs)¶
Overloaded function.
stack(self: visp._visp.core.Matrix, A: visp._visp.core.Matrix) -> None
Stack A at the end of the current matrix, or copy if the matrix has no dimensions : this = [ this A ]^T.
stack(self: visp._visp.core.Matrix, r: visp._visp.core.RowVector) -> None
Stack row vector r at the end of the current matrix, or copy if the matrix has no dimensions: this = [ this r ]^T.
Here an example for a robot velocity log :
vpMatrix A; vpColVector v(6); for(unsigned int i = 0;i<100;i++) { robot.getVelocity(vpRobot::ARTICULAR_FRAME, v); Velocities.stack(v.t()); }
stack(self: visp._visp.core.Matrix, c: visp._visp.core.ColVector) -> None
Stack column vector c at the right of the current matrix, or copy if the matrix has no dimensions: this = [ this c ].
Here an example for a robot velocity log matrix:
vpMatrix log; vpColVector v(6); for(unsigned int i = 0; i<100;i++) { robot.getVelocity(vpRobot::ARTICULAR_FRAME, v); log.stack(v); }
Here the log matrix has size 6 rows by 100 columns.
- static stackColumn(*args, **kwargs)¶
Overloaded function.
stackColumn(A: visp._visp.core.Matrix, c: visp._visp.core.ColVector) -> visp._visp.core.Matrix
Stack column vector c to matrix A and return the resulting matrix [ A c ]
Warning
A and c must have the same number of rows.
- Parameters:
- A
Left matrix.
- c
Right column vector.
- Returns:
Stacked matrix [ A c ]
stackColumn(A: visp._visp.core.Matrix, c: visp._visp.core.ColVector, C: visp._visp.core.Matrix) -> None
Stack column vector c to the end of matrix A and return the resulting matrix in C .
Warning
A and c must have the same number of rows. A and C must be two different objects.
- Parameters:
- A
Left matrix.
- c
Right column vector.
- C
Stacked matrix C = [ A c ]
- stackColumns(*args, **kwargs)¶
Overloaded function.
stackColumns(self: visp._visp.core.Matrix, out: visp._visp.core.ColVector) -> None
Stacks columns of a matrix in a vector.
- Parameters:
- out
a vpColVector .
stackColumns(self: visp._visp.core.Matrix) -> visp._visp.core.ColVector
- Returns:
a vpColVector .
- static stackMatrices(*args, **kwargs)¶
Overloaded function.
stackMatrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Stack matrix B to the end of matrix A and return the resulting matrix [ A B ]^T
Warning
A and B must have the same number of columns.
- Parameters:
- A
Upper matrix.
- B
Lower matrix.
- Returns:
Stacked matrix [ A B ]^T
stackMatrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix) -> None
Stack matrix B to the end of matrix A and return the resulting matrix in C .
Warning
A and B must have the same number of columns. A and C, B and C must be two different objects.
- Parameters:
- A
Upper matrix.
- B
Lower matrix.
- C
Stacked matrix C = [ A B ]^T
- static stackRow(*args, **kwargs)¶
Overloaded function.
stackRow(A: visp._visp.core.Matrix, r: visp._visp.core.RowVector) -> visp._visp.core.Matrix
Stack row vector r to matrix A and return the resulting matrix [ A r ]^T
Warning
A and r must have the same number of columns.
- Parameters:
- A
Upper matrix.
- r
Lower row vector.
- Returns:
Stacked matrix [ A r ]^T
stackRow(A: visp._visp.core.Matrix, r: visp._visp.core.RowVector, C: visp._visp.core.Matrix) -> None
Stack row vector r to the end of matrix A and return the resulting matrix in C .
Warning
A and r must have the same number of columns. A and C must be two different objects.
- Parameters:
- A
Upper matrix.
- r
Lower row vector.
- C
Stacked matrix C = [ A r ]^T
- stackRows(*args, **kwargs)¶
Overloaded function.
stackRows(self: visp._visp.core.Matrix, out: visp._visp.core.RowVector) -> None
Stacks rows of a matrix in a vector
- Parameters:
- out
a vpRowVector .
stackRows(self: visp._visp.core.Matrix) -> visp._visp.core.RowVector
- Returns:
a vpRowVector .
- strCppCode(self, name: str, byte_per_byte: bool = False) str ¶
Returns a C++ code representation of this data array (see cppPrint in the C++ documentation)
- strCsv(self) str ¶
Returns the CSV representation of this data array (see csvPrint in the C++ documentation)
- strMaple(self) str ¶
Returns the CSV representation of this data array (see maplePrint in the C++ documentation)
- strMatlab(self) str ¶
Returns the Matlab representation of this data array (see matlabPrint in the C++ documentation)
- static sub2Matrices(*args, **kwargs)¶
Overloaded function.
sub2Matrices(A: visp._visp.core.Matrix, B: visp._visp.core.Matrix, C: visp._visp.core.Matrix) -> None
Operation C = A - B.
The result is placed in the third parameter C and not returned. A new matrix won’t be allocated for every use of the function (speed gain if used many times with the same result matrix size).
Note
See operator-()
sub2Matrices(A: visp._visp.core.ColVector, B: visp._visp.core.ColVector, C: visp._visp.core.ColVector) -> None
Warning
This function is provided for compat with previous releases. You should rather use the functionalities provided in vpColVector class.
Operation C = A - B on column vectors.
The result is placed in the third parameter C and not returned. A new vector won’t be allocated for every use of the function (speed gain if used many times with the same result matrix size).
Note
See vpColVector::operator-()
- sum(self) float ¶
Return the sum of all the \(a_{ij}\) elements of the matrix.
- Returns:
Value of \(\sum a_{ij}\)
- sumSquare(self) float ¶
Return the sum square of all the \(A_{ij}\) elements of the matrix \(A(m, n)\) .
- Returns:
The value \(\sum A_{ij}^{2}\) .
- svd(self, w: visp._visp.core.ColVector, V: visp._visp.core.Matrix) None ¶
Matrix singular value decomposition (SVD).
This function calls the first following function that is available:
svdLapack() if Lapack 3rd party is installed
svdEigen3() if Eigen3 3rd party is installed
svdOpenCV() if OpenCV 3rd party is installed.
If none of these previous 3rd parties is installed, we use by default svdLapack() with a Lapack built-in version.
Given matrix \(M\) , this function computes it singular value decomposition such as
\[M = U \Sigma V^{\top} \]Warning
This method is destructive wrt. to the matrix \(M\) to decompose. You should make a COPY of that matrix if needed.
The matrix object (*this) is updated with :math:`U .
Note
The singular values are ordered in decreasing fashion in w . It means that the highest singular value is in w [0].
Here an example of SVD decomposition of a non square Matrix M.
#include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix M(3,2); M[0][0] = 1; M[0][1] = 6; M[1][0] = 2; M[1][1] = 8; M[2][0] = 0.5; M[2][1] = 9; vpColVector w; vpMatrix V, Sigma, U = M; U.svd(w, V); // Construct the diagonal matrix from the singular values Sigma.diag(w); // Reconstruct the initial matrix using the decomposition vpMatrix Mrec = U * Sigma * V.t(); // Here, Mrec is obtained equal to the initial value of M // Mrec[0][0] = 1; Mrec[0][1] = 6; // Mrec[1][0] = 2; Mrec[1][1] = 8; // Mrec[2][0] = 0.5; Mrec[2][1] = 9; std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl; }
Note
See svdLapack() , svdEigen3() , svdOpenCV()
- Parameters:
- w: visp._visp.core.ColVector¶
Vector of singular values: \(\Sigma = diag(w)\) .
- V: visp._visp.core.Matrix¶
Matrix \(V\) .
- svdEigen3(self, w: visp._visp.core.ColVector, V: visp._visp.core.Matrix) None ¶
Singular value decomposition (SVD) using Eigen3 3rd party.
Given matrix \(M\) , this function computes it singular value decomposition such as
\[M = U \Sigma V^{\top} \]Warning
This method is destructive wrt. to the matrix \(M\) to decompose. You should make a COPY of that matrix if needed.
The matrix object (*this) is updated with \(U\) .
Note
The singular values are ordered in decreasing fashion in w . It means that the highest singular value is in w [0].
Here an example of SVD decomposition of a non square Matrix M.
#include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix M(3,2); M[0][0] = 1; M[1][0] = 2; M[2][0] = 0.5; M[0][1] = 6; M[1][1] = 8 ; M[2][1] = 9 ; vpMatrix V; vpColVector w; vpMatrix Mrec; vpMatrix Sigma; M.svdEigen3(w, V); // Here M is modified and is now equal to U // Construct the diagonal matrix from the singular values Sigma.diag(w); // Reconstruct the initial matrix M using the decomposition Mrec = M * Sigma * V.t(); // Here, Mrec is obtained equal to the initial value of M // Mrec[0][0] = 1; // Mrec[1][0] = 2; // Mrec[2][0] = 0.5; // Mrec[0][1] = 6; // Mrec[1][1] = 8 ; // Mrec[2][1] = 9 ; std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl; }
Note
See svd() , svdLapack() , svdOpenCV()
- Parameters:
- w: visp._visp.core.ColVector¶
Vector of singular values: \(\Sigma = diag(w)\) .
- V: visp._visp.core.Matrix¶
Matrix \(V\) .
- svdLapack(self, w: visp._visp.core.ColVector, V: visp._visp.core.Matrix) None ¶
Singular value decomposition (SVD) using Lapack 3rd party.
Given matrix \(M\) , this function computes it singular value decomposition such as
\[M = U \Sigma V^{\top} \]Warning
This method is destructive wrt. to the matrix \(M\) to decompose. You should make a COPY of that matrix if needed.
The matrix object (*this) is updated with \(U\) .
Note
The singular values are ordered in decreasing fashion in w . It means that the highest singular value is in w [0].
Here an example of SVD decomposition of a non square Matrix M.
#include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix M(3,2); M[0][0] = 1; M[1][0] = 2; M[2][0] = 0.5; M[0][1] = 6; M[1][1] = 8 ; M[2][1] = 9 ; vpMatrix V; vpColVector w; vpMatrix Mrec; vpMatrix Sigma; M.svdLapack(w, V); // Here M is modified and is now equal to U // Construct the diagonal matrix from the singular values Sigma.diag(w); // Reconstruct the initial matrix M using the decomposition Mrec = M * Sigma * V.t(); // Here, Mrec is obtained equal to the initial value of M // Mrec[0][0] = 1; // Mrec[1][0] = 2; // Mrec[2][0] = 0.5; // Mrec[0][1] = 6; // Mrec[1][1] = 8 ; // Mrec[2][1] = 9 ; std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl; }
Note
See svd() , svdEigen3() , svdOpenCV()
- Parameters:
- w: visp._visp.core.ColVector¶
Vector of singular values: \(\Sigma = diag(w)\) .
- V: visp._visp.core.Matrix¶
Matrix \(V\) .
- svdOpenCV(self, w: visp._visp.core.ColVector, V: visp._visp.core.Matrix) None ¶
Singular value decomposition (SVD) using OpenCV 3rd party.
Given matrix \(M\) , this function computes it singular value decomposition such as
\[M = U \Sigma V^{\top} \]Warning
This method is destructive wrt. to the matrix \(M\) to decompose. You should make a COPY of that matrix if needed.
The matrix object (*this) is updated with \(U\) .
Note
The singular values are ordered in decreasing fashion in w . It means that the highest singular value is in w [0].
Here an example of SVD decomposition of a non square Matrix M.
#include <visp3/core/vpColVector.h> #include <visp3/core/vpMatrix.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpMatrix M(3,2); M[0][0] = 1; M[1][0] = 2; M[2][0] = 0.5; M[0][1] = 6; M[1][1] = 8 ; M[2][1] = 9 ; vpMatrix V; vpColVector w; vpMatrix Mrec; vpMatrix Sigma; M.svdOpenCV(w, V); // Here M is modified and is now equal to U // Construct the diagonal matrix from the singular values Sigma.diag(w); // Reconstruct the initial matrix M using the decomposition Mrec = M * Sigma * V.t(); // Here, Mrec is obtained equal to the initial value of M // Mrec[0][0] = 1; // Mrec[1][0] = 2; // Mrec[2][0] = 0.5; // Mrec[0][1] = 6; // Mrec[1][1] = 8 ; // Mrec[2][1] = 9 ; std::cout << "Reconstructed M matrix: \n" << Mrec << std::endl; }
Note
See svd() , svdEigen3() , svdLapack()
- Parameters:
- w: visp._visp.core.ColVector¶
Vector of singular values: \(\Sigma = diag(w)\) .
- V: visp._visp.core.Matrix¶
Matrix \(V\) .
- t(*args, **kwargs)¶
Overloaded function.
t(self: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Compute and return the transpose of the matrix.
t(self: visp._visp.core.ArrayDouble2D) -> visp._visp.core.ArrayDouble2D
Compute the transpose of the array.
- Returns:
vpArray2D<Type> C = A^T
- transpose(*args, **kwargs)¶
Overloaded function.
transpose(self: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Compute and return the transpose of the matrix.
Note
See t()
transpose(self: visp._visp.core.Matrix, At: visp._visp.core.Matrix) -> None
Compute At the transpose of the matrix.
Note
See t()
- Parameters:
- At
(output) : Resulting transpose matrix.
-
__hash__ =
None
¶