41#include <visp3/core/vpMatrix.h>
43#ifdef ENABLE_VISP_NAMESPACE
46int test_condition_number(
const std::string &test_name,
const vpMatrix &M);
48int test_condition_number(
const std::string &test_name,
const vpMatrix &M)
50 double precision = 1
e-6;
53 double inducedL2_norm_inv = 0, cond_inv = 0;
57 double cond = M.
cond();
58 double cond_pinv = inducedL2_norm * inducedL2_norm_pinv;
61 double rank = M.
kernel(kerMt);
65 cond_inv = inducedL2_norm * inducedL2_norm_inv;
68 M.
print(std::cout, 4, test_name);
69 std::cout <<
" Matrix rank: " << rank << std::endl;
70 std::cout <<
" Matrix induced L2 norm ||M||_L2: " << inducedL2_norm << std::endl;
72 std::cout <<
" Inverse induced L2 norm ||M^-1||_L2: " << inducedL2_norm_inv << std::endl;
74 std::cout <<
" Pseudo inverse induced L2 norm norm ||M^+||_L2: " << inducedL2_norm_pinv << std::endl;
76 std::cout <<
" Condition number such as cond(M)=||M||_L2 * ||M^-1||_L2: " << cond_inv << std::endl;
78 std::cout <<
" Condition number such as cond(M)=||M||_L2 * ||M^+||_L2: " << cond_pinv << std::endl;
79 std::cout <<
" Condition number cond(M): " << cond << std::endl;
81 std::cout <<
" Condition number differ from the one computed with the pseudo inverse" << std::endl;
86 std::cout <<
" Condition number differ from the one computed with the inverse" << std::endl;
96#if defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)
100 if (test_condition_number(
"* Test square matrix M", M)) {
101 std::cout <<
" - Condition number computation fails" << std::endl;
105 std::cout <<
" + Condition number computation succeed" << std::endl;
116 if (test_condition_number(
"* Test rect matrix M", M)) {
117 std::cout <<
" - Condition number computation fails" << std::endl;
121 std::cout <<
" + Condition number computation succeed" << std::endl;
126 if (test_condition_number(
"* Test rect matrix M", M)) {
127 std::cout <<
" - Condition number computation fails" << std::endl;
131 std::cout <<
" + Condition number computation succeed" << std::endl;
148 if (test_condition_number(
"* Test rect matrix M", M)) {
149 std::cout <<
" - Condition number computation fails" << std::endl;
153 std::cout <<
" + Condition number computation succeed" << std::endl;
158 if (test_condition_number(
"* Test rect matrix M", M)) {
159 std::cout <<
" - Condition number computation fails" << std::endl;
163 std::cout <<
" + Condition number computation succeed" << std::endl;
165 std::cout <<
"Test succeed" << std::endl;
167 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