calcKernelMatrixProperties.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @file calcKernelMatrixProperties.cpp
  3. * @brief calc some kernel matrix properties
  4. * @author Erik Rodner
  5. * @date 01/15/2010
  6. */
  7. #include "core/basics/Config.h"
  8. #include "core/vector/Eigen.h"
  9. using namespace std;
  10. using namespace NICE;
  11. /**
  12. calc some kernel matrix properties
  13. */
  14. int main (int argc, char **argv)
  15. {
  16. std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
  17. Config conf ( argc, argv );
  18. string in = conf.gS("main", "in");
  19. cout << "reading kernel matrix ..." << endl;
  20. ifstream ifs ( in.c_str(), ios::in );
  21. if ( !ifs.good() )
  22. fthrow(IOException, "Unable to read " << in << "." );
  23. Matrix kernelMatrixOrig;
  24. ifs >> kernelMatrixOrig;
  25. ifs.close();
  26. int norig = kernelMatrixOrig.rows();
  27. int morig = kernelMatrixOrig.cols();
  28. if ( norig != morig )
  29. fthrow(Exception, "Kernel matrix has to be quadratic.");
  30. int size = conf.gI("main", "size", 100 );
  31. if ( size > norig ) size = norig;
  32. Matrix kernelMatrix ( size, size );
  33. for ( int i = 0 ; i < kernelMatrix.rows(); i++ )
  34. for ( int j = 0 ; j < kernelMatrix.cols(); j++ )
  35. kernelMatrix(i,j) = kernelMatrixOrig(i,j);
  36. int n = kernelMatrix.rows();
  37. int m = kernelMatrix.cols();
  38. cout << "size: " << n << " x " << m << " (orig: " << norig << " x " << norig << " )" << endl;
  39. cout << "performing eigenvalue decomposition ..." << endl;
  40. Vector eigvals (n);
  41. eigenvalues ( kernelMatrix, &eigvals );
  42. double min_lambda = eigvals.Min();
  43. double max_lambda = eigvals.Max();
  44. cout << "smallest eigenvalue: " << min_lambda << endl;
  45. cout << "largest eigenvalue: " << max_lambda << endl;
  46. double sigma = conf.gD("main", "sigma", 0.01);
  47. double upper_bound = 0.5 * sigma * sigma / ( pow(min_lambda,3) );
  48. double lower_bound = 0.5 * sigma * sigma / ( pow(min_lambda,3) + sigma*sigma );
  49. cout << "inverse approximation bounds (cf. GP Multi-Task Notes): " << lower_bound << " <= |R|_2 <= " << upper_bound << endl;
  50. return 0;
  51. }