KCGPRegression.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @file KCGPRegression.cpp
  3. * @brief Gaussian Process Regression for Classification
  4. * @author Erik Rodner
  5. * @date 12/03/2009
  6. */
  7. #include <iostream>
  8. #include <typeinfo>
  9. #include "core/vector/Algorithms.h"
  10. #include "vislearning/regression/gpregression/RegGaussianProcess.h"
  11. #include "KCGPRegression.h"
  12. using namespace std;
  13. using namespace NICE;
  14. using namespace OBJREC;
  15. KCGPRegression::KCGPRegression( const Config *conf, Kernel *kernel, const string & section )
  16. : KernelClassifier ( conf, kernel )
  17. {
  18. regressionAlgorithm = new RegGaussianProcess ( conf, kernel, section );
  19. }
  20. KCGPRegression::KCGPRegression( const KCGPRegression & src ) : KernelClassifier ( src )
  21. {
  22. regressionAlgorithm = src.regressionAlgorithm->clone();
  23. y = src.y;
  24. }
  25. KCGPRegression::~KCGPRegression()
  26. {
  27. delete regressionAlgorithm;
  28. }
  29. void KCGPRegression::teach ( KernelData *kernelData, const NICE::Vector & y )
  30. {
  31. if ( y.size() <= 0 ) {
  32. fthrow(Exception, "Number of training vectors is zero!");
  33. }
  34. this->y.resize ( y.size() );
  35. this->y = y;
  36. this->y = 2*this->y;
  37. this->y += -1.0;
  38. if ( (this->y.Min() != -1) || (this->y.Max() != 1) ) {
  39. fthrow(Exception, "This classifier is suitable only for binary classification problems" );
  40. }
  41. regressionAlgorithm->teach ( kernelData, this->y );
  42. }
  43. ClassificationResult KCGPRegression::classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const
  44. {
  45. double yEstimate = regressionAlgorithm->predictKernel ( kernelVector, kernelSelf );
  46. FullVector scores ( 2 );
  47. scores[0] = 0.0;
  48. scores[1] = yEstimate;
  49. ClassificationResult r ( (yEstimate < 0) ? 0 : 1, scores );
  50. return r;
  51. }
  52. KCGPRegression *KCGPRegression::clone() const
  53. {
  54. return new KCGPRegression ( *this );
  55. }