43 #include <visp3/core/vpMatrix.h>
45 int test_condition_number(
const std::string &test_name,
const vpMatrix &M)
47 double precision = 1e-6;
50 double inducedL2_norm_inv = 0, cond_inv = 0;
54 double cond = M.
cond();
55 double cond_pinv = inducedL2_norm * inducedL2_norm_pinv;
58 double rank = M.
kernel(kerMt);
62 cond_inv = inducedL2_norm * inducedL2_norm_inv;
65 M.
print(std::cout, 4, test_name);
66 std::cout <<
" Matrix rank: " << rank << std::endl;
67 std::cout <<
" Matrix induced L2 norm ||M||_L2: " << inducedL2_norm << std::endl;
69 std::cout <<
" Inverse induced L2 norm ||M^-1||_L2: " << inducedL2_norm_inv << std::endl;
71 std::cout <<
" Pseudo inverse induced L2 norm norm ||M^+||_L2: " << inducedL2_norm_pinv << std::endl;
73 std::cout <<
" Condition number such as cond(M)=||M||_L2 * ||M^-1||_L2: " << cond_inv << std::endl;
75 std::cout <<
" Condition number such as cond(M)=||M||_L2 * ||M^+||_L2: " << cond_pinv << std::endl;
76 std::cout <<
" Condition number cond(M): " << cond << std::endl;
78 std::cout <<
" Condition number differ from the one computed with the pseudo inverse" << std::endl;
83 std::cout <<
" Condition number differ from the one computed with the inverse" << std::endl;
93 #if defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)
97 if (test_condition_number(
"* Test square matrix M", M)) {
98 std::cout <<
" - Condition number computation fails" << std::endl;
101 std::cout <<
" + Condition number computation succeed" << std::endl;
112 if (test_condition_number(
"* Test rect matrix M", M)) {
113 std::cout <<
" - Condition number computation fails" << std::endl;
116 std::cout <<
" + Condition number computation succeed" << std::endl;
121 if (test_condition_number(
"* Test rect matrix M", M)) {
122 std::cout <<
" - Condition number computation fails" << std::endl;
125 std::cout <<
" + Condition number computation succeed" << std::endl;
142 if (test_condition_number(
"* Test rect matrix M", M)) {
143 std::cout <<
" - Condition number computation fails" << std::endl;
146 std::cout <<
" + Condition number computation succeed" << std::endl;
151 if (test_condition_number(
"* Test rect matrix M", M)) {
152 std::cout <<
" - Condition number computation fails" << std::endl;
155 std::cout <<
" + Condition number computation succeed" << std::endl;
157 std::cout <<
"Test succeed" << std::endl;
159 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