41 #include <visp3/core/vpMatrix.h>
43 #ifdef ENABLE_VISP_NAMESPACE
47 int test_condition_number(
const std::string &test_name,
const vpMatrix &M)
49 double precision = 1e-6;
52 double inducedL2_norm_inv = 0, cond_inv = 0;
56 double cond = M.
cond();
57 double cond_pinv = inducedL2_norm * inducedL2_norm_pinv;
60 double rank = M.
kernel(kerMt);
64 cond_inv = inducedL2_norm * inducedL2_norm_inv;
67 M.
print(std::cout, 4, test_name);
68 std::cout <<
" Matrix rank: " << rank << std::endl;
69 std::cout <<
" Matrix induced L2 norm ||M||_L2: " << inducedL2_norm << std::endl;
71 std::cout <<
" Inverse induced L2 norm ||M^-1||_L2: " << inducedL2_norm_inv << std::endl;
73 std::cout <<
" Pseudo inverse induced L2 norm norm ||M^+||_L2: " << inducedL2_norm_pinv << std::endl;
75 std::cout <<
" Condition number such as cond(M)=||M||_L2 * ||M^-1||_L2: " << cond_inv << std::endl;
77 std::cout <<
" Condition number such as cond(M)=||M||_L2 * ||M^+||_L2: " << cond_pinv << std::endl;
78 std::cout <<
" Condition number cond(M): " << cond << std::endl;
80 std::cout <<
" Condition number differ from the one computed with the pseudo inverse" << std::endl;
85 std::cout <<
" Condition number differ from the one computed with the inverse" << std::endl;
95 #if defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)
99 if (test_condition_number(
"* Test square matrix M", M)) {
100 std::cout <<
" - Condition number computation fails" << std::endl;
104 std::cout <<
" + Condition number computation succeed" << std::endl;
115 if (test_condition_number(
"* Test rect matrix M", M)) {
116 std::cout <<
" - Condition number computation fails" << std::endl;
120 std::cout <<
" + Condition number computation succeed" << std::endl;
125 if (test_condition_number(
"* Test rect matrix M", M)) {
126 std::cout <<
" - Condition number computation fails" << std::endl;
130 std::cout <<
" + Condition number computation succeed" << std::endl;
147 if (test_condition_number(
"* Test rect matrix M", M)) {
148 std::cout <<
" - Condition number computation fails" << std::endl;
152 std::cout <<
" + Condition number computation succeed" << std::endl;
157 if (test_condition_number(
"* Test rect matrix M", M)) {
158 std::cout <<
" - Condition number computation fails" << std::endl;
162 std::cout <<
" + Condition number computation succeed" << std::endl;
164 std::cout <<
"Test succeed" << std::endl;
166 std::cout <<
"Test ignored: install Lapack, Eigen3 or OpenCV" << std::endl;
unsigned int getCols() const
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int getRows() const
static bool equal(double x, double y, double threshold=0.001)
Implementation of a matrix and operations on matrices.
double cond(double svThreshold=1e-6) const
int print(std::ostream &s, unsigned int length, const std::string &intro="") const
unsigned int kernel(vpMatrix &kerAt, double svThreshold=1e-6) const
vpMatrix inverseByLU() const
double inducedL2Norm() const
vpMatrix pseudoInverse(double svThreshold=1e-6) const
vpMatrix transpose() const