DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testEigenDecomposition.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/math/linalg/EigenDecomposition.h"

Go to the source code of this file.

Functions

bool testEigenDecomposition ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2014/04/02

Functions for testing class testEigenDecomposition.

This file is part of the DGtal library.

Definition in file testEigenDecomposition.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 104 of file testEigenDecomposition.cpp.

105{
106 trace.beginBlock ( "Testing class testEigenDecomposition" );
107 trace.info() << "Args:";
108 for ( int i = 0; i < argc; ++i )
109 trace.info() << " " << argv[ i ];
110 trace.info() << endl;
111
112 bool res = testEigenDecomposition(); // && ... other tests
113 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
114 trace.endBlock();
115 return res ? 0 : 1;
116}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool testEigenDecomposition()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testEigenDecomposition(), and DGtal::trace.

◆ testEigenDecomposition()

bool testEigenDecomposition ( )

Example of a test. To be completed.

Definition at line 46 of file testEigenDecomposition.cpp.

47{
48 unsigned int nbok = 0;
49 unsigned int nb = 0;
50
51 typedef EigenDecomposition<2,double> Eigen2;
52 typedef Eigen2::Vector Vector2;
53 typedef Eigen2::Matrix Matrix2;
54
55 trace.beginBlock ( "Testing block ..." );
56 // [4 1]
57 // [1 2]
58 Matrix2 A;
59 A.setComponent( 0, 0, 4 );
60 A.setComponent( 0, 1, 1 );
61 A.setComponent( 1, 0, 1 );
62 A.setComponent( 1, 1, 2 );
63 Matrix2 P;
64 Vector2 v;
65 Eigen2::getEigenDecomposition( A, P, v );
66 trace.info() << "Input matrix: " << A << std::endl;
67 trace.info() << "Eigenvectors: " << P << std::endl;
68 trace.info() << "Eigenvalues: " << v << std::endl;
69 Vector2 V0 = P.column( 0 );
70 Vector2 V1 = P.column( 1 );
71 Vector2 V0_exp( 0.3826834323650898, -0.9238795325112868 );
72 Vector2 V1_exp( 0.9238795325112868, 0.3826834323650898);
73 double v0_exp = 1.585786437626905;
74 double v1_exp = 4.414213562373095;
75 double error_V0 = (V0-V0_exp).norm();
76 double error_V1 = (V1-V1_exp).norm();
77 double error_v0 = fabs( v[0] - v0_exp );
78 double error_v1 = fabs( v[1] - v1_exp );
79 trace.info() << "error_V0 = " << error_V0 << std::endl;
80 trace.info() << "error_V1 = " << error_V1 << std::endl;
81 trace.info() << "error_v0 = " << error_v0 << std::endl;
82 trace.info() << "error_v1 = " << error_v1 << std::endl;
83 double epsilon = 1e-10;
84 ++nb; nbok += error_V0 < epsilon ? 1 : 0;
85 trace.info() << "(" << nbok << "/" << nb << ") "
86 << "error_V0 < epsilon, i.e. " << error_V0 << " < " << epsilon << std::endl;
87 ++nb; nbok += error_V1 < epsilon ? 1 : 0;
88 trace.info() << "(" << nbok << "/" << nb << ") "
89 << "error_V1 < epsilon, i.e. " << error_V1 << " < " << epsilon << std::endl;
90 ++nb; nbok += error_v0 < epsilon ? 1 : 0;
91 trace.info() << "(" << nbok << "/" << nb << ") "
92 << "error_v0 < epsilon, i.e. " << error_v0 << " < " << epsilon << std::endl;
93 ++nb; nbok += error_v1 < epsilon ? 1 : 0;
94 trace.info() << "(" << nbok << "/" << nb << ") "
95 << "error_v1 < epsilon, i.e. " << error_v1 << " < " << epsilon << std::endl;
97
98 return nbok == nb;
99}
Aim: This class provides methods to compute the eigen decomposition of a matrix. Its objective is to ...

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().