00001 #include <TooN/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 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, all three matrices should be the same.\n"; 00025 cout << t << endl << chol.get_L()*(chol.get_L().T()) << endl 00026 << chol.get_unscaled_L()*chol.get_D()*(chol.get_unscaled_L().T()) 00027 << endl; 00028 00029 cout << "Check inverse, third matrix should be close to identity.\n"; 00030 cout << t << "\n" << chol.get_inverse() << "\n" 00031 << t * chol.get_inverse() << endl; 00032 00033 Matrix<> t2 = t; 00034 00035 Cholesky<Dynamic,float> chol2(t2); 00036 00037 cout << "Dynamic size, single precision checks:\n"; 00038 cout << "Check decomposition, all three matrices should be the same.\n"; 00039 cout << t << endl << chol2.get_L()*(chol2.get_L().T()) << endl 00040 << chol2.get_unscaled_L()*chol2.get_D()*(chol2.get_unscaled_L().T()) 00041 << endl; 00042 00043 cout << "Check inverse, third matrix should be close to identity.\n"; 00044 cout << t2 << "\n" << chol2.get_inverse() << "\n" 00045 << t2 * chol2.get_inverse() << endl; 00046 00047 Vector<3> bla = makeVector(1,2,3); 00048 00049 cout << "Check backsub(), the following two vectors should be the same.\n"; 00050 cout << chol.backsub(bla) << endl; 00051 cout << chol.get_inverse() * bla << endl << endl; 00052 00053 cout << "Check mahalanobis(), result should be zero.\n"; 00054 cout << chol.mahalanobis(bla) - bla * chol.backsub(bla) << endl; 00055 00056 return 0; 00057 }