00001 #include <TooN/Lapack_Cholesky.h> 00002 00003 #include <iostream> 00004 #include <iomanip> 00005 00006 using namespace std; 00007 using namespace TooN; 00008 00009 int main(int, char ** ){ 00010 00011 cout << setprecision(10); 00012 00013 Matrix<3> t = Data( 00014 1, 0.5, 0.5, 00015 0.5, 2, 0.7, 00016 0.5, 0.7, 3); 00017 00018 Lapack_Cholesky<3> chol(t); 00019 00020 cout << "Check for determinant\n"; 00021 cout << chol.determinant() << endl << endl; 00022 00023 cout << "Static size checks:\n"; 00024 cout << "Check decomposition, both matrices should be the same.\n"; 00025 cout << t << endl << chol.get_L()*(chol.get_L().T()) << endl ; 00026 00027 cout << "Check inverse, third matrix should be close to identity.\n"; 00028 cout << t << "\n" << chol.get_inverse() << "\n" 00029 << t * chol.get_inverse() << endl; 00030 00031 Matrix<> t2 = t; 00032 00033 Lapack_Cholesky<Dynamic,float> chol2(t2); 00034 00035 cout << "Dynamic size, single precision checks:\n"; 00036 cout << "Check decomposition, both matrices should be the same.\n"; 00037 cout << t << endl << chol2.get_L()*(chol2.get_L().T()) << endl ; 00038 00039 cout << "Check inverse, third matrix should be close to identity.\n"; 00040 cout << t2 << "\n" << chol2.get_inverse() << "\n" 00041 << t2 * chol2.get_inverse() << endl; 00042 00043 Vector<3> bla = makeVector(1,2,3); 00044 00045 cout << "Check backsub(), the following two vectors should be the same.\n"; 00046 cout << chol.backsub(bla) << endl; 00047 cout << chol.get_inverse() * bla << endl << endl; 00048 00049 cout << "Check mahalanobis(), result should be zero.\n"; 00050 cout << chol.mahalanobis(bla) - bla * chol.backsub(bla) << endl; 00051 00052 return 0; 00053 }