ClusterOnline.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @file ClusterOnline.cpp
  3. * @brief interface for online clustering
  4. * @author Erik Rodner
  5. * @date 02/13/2008
  6. */
  7. #include <iostream>
  8. #include <fstream>
  9. #include "vislearning/math/cluster/ClusterOnline.h"
  10. using namespace OBJREC;
  11. using namespace std;
  12. // refactor-nice.pl: check this substitution
  13. // old: using namespace ice;
  14. using namespace NICE;
  15. ClusterOnline::ClusterOnline()
  16. {
  17. }
  18. ClusterOnline::~ClusterOnline()
  19. {
  20. }
  21. void ClusterOnline::init ()
  22. {
  23. clusters.clear();
  24. weights.clear();
  25. }
  26. void ClusterOnline::cluster ( const VVector & features,
  27. VVector & prototypes,
  28. std::vector<double> & _weights,
  29. std::vector<int> & assignment )
  30. {
  31. init();
  32. assignment.clear();
  33. prototypes.clear();
  34. _weights.clear();
  35. for ( VVector::const_iterator i = features.begin();
  36. i != features.end(); i++ )
  37. {
  38. // refactor-nice.pl: check this substitution
  39. // old: const Vector & x = *i;
  40. const NICE::Vector & x = *i;
  41. // calling virtual function !
  42. int nearest_cluster = updateClusters ( x );
  43. assignment.push_back ( nearest_cluster );
  44. }
  45. prototypes.insert ( prototypes.begin(), clusters.begin(), clusters.end() );
  46. _weights.insert ( _weights.begin(), weights.begin(), weights.end() );
  47. }