VCTransform.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @file VCTransform.cpp
  3. // refactor-nice.pl: check this substitution
  4. // old: * @brief Vector Transform
  5. * @brief NICE::Vector Transform
  6. * @author Michael Koch
  7. * @date 11/28/2007
  8. */
  9. #ifdef NOVISUAL
  10. #include <vislearning/nice_nonvis.h>
  11. #else
  12. #include <vislearning/nice.h>
  13. #endif
  14. #include <iostream>
  15. #include <fstream>
  16. #include "vislearning/classifier/vclassifier/VCTransform.h"
  17. #include "core/basics/FileMgt.h"
  18. #include "vislearning/math/ftransform/PCA.h"
  19. using namespace OBJREC;
  20. using namespace std;
  21. // refactor-nice.pl: check this substitution
  22. // old: using namespace ice;
  23. using namespace NICE;
  24. VCTransform::VCTransform(const Config *conf, VecClassifier * classifier,
  25. FTransform * transform)
  26. {
  27. this->classifier = classifier;
  28. this->transform = transform;
  29. this->dimension = conf->gI("FTransform", "dimension", 10);
  30. this->mode = conf->gI("FTransform", "mode", 0);
  31. transformedSet.clear();
  32. }
  33. VCTransform::~VCTransform()
  34. {
  35. }
  36. /** classify using simple vector */
  37. ClassificationResult VCTransform::classify(const NICE::Vector & x) const
  38. {
  39. NICE::Vector transformed_vector = transform->getFeatureVector(x);
  40. cerr << "PCA: transformed-vector: " << transformed_vector << endl;
  41. return this->classifier->classify(transformed_vector);
  42. }
  43. void VCTransform::teach(const LabeledSetVector & teachSet)
  44. {
  45. maxClassNo = teachSet.getMaxClassno();
  46. int n = teachSet.count();
  47. int d = teachSet.dimension();
  48. NICE::Matrix X = Matrix(n, d);
  49. //get input data
  50. uint featurecount = 0;
  51. LOOP_ALL(teachSet)
  52. {
  53. EACH(classno,x);
  54. for (uint k = 0; k < x.size(); ++k)
  55. {
  56. X(featurecount, k) = x[k];
  57. }
  58. ++featurecount;
  59. }
  60. //learning Ftransform
  61. transform->calculateBasis(X, this->dimension, this->mode);
  62. //save transformed Vectors
  63. LOOP_ALL(teachSet)
  64. {
  65. EACH(classno,x);
  66. NICE::Vector transformed_vector = transform->getFeatureVector(x);
  67. cerr << "PCA: transformed-vector: " << transformed_vector << endl;
  68. transformedSet.add(classno, transformed_vector);
  69. }
  70. this->classifier->teach(transformedSet);
  71. }
  72. void VCTransform::finishTeaching()
  73. {
  74. this->classifier->finishTeaching();
  75. }
  76. void VCTransform::restore(std::istream & is, int format)
  77. {
  78. fprintf(stderr, "NOT YET IMPLEMENTED !!\n");
  79. exit(-1);
  80. }
  81. void VCTransform::store(std::ostream & is, int format) const
  82. {
  83. fprintf(stderr, "NOT YET IMPLEMENTED !!\n");
  84. exit(-1);
  85. }
  86. void VCTransform::clear()
  87. {
  88. fprintf(stderr, "NOT YET IMPLEMENTED !!\n");
  89. exit(-1);
  90. }