KMeansMatlab.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * @file KMeansMatlab.h
  3. * @brief K-Means using a matlab implementation
  4. * @author Erik Rodner
  5. * @date 10/29/2007
  6. */
  7. #ifndef KMeansMatlabINCLUDE
  8. #define KMeansMatlabINCLUDE
  9. #include "core/vector/VectorT.h"
  10. #include "core/vector/MatrixT.h"
  11. #include "core/basics/Config.h"
  12. #include "ClusterAlgorithm.h"
  13. namespace OBJREC {
  14. /**
  15. * @class KMeansMatlab
  16. * @brief K-Means using a matlab implementation
  17. * @author Erik Rodner
  18. */
  19. class KMeansMatlab : public ClusterAlgorithm
  20. {
  21. protected:
  22. /************************
  23. *
  24. * protected variables
  25. *
  26. **************************/
  27. int noClusters;
  28. // refactor-nice.pl: check this substitution
  29. // old: string kmeansDir;
  30. std::string kmeansDir;
  31. // refactor-nice.pl: check this substitution
  32. // old: string matlabExec;
  33. std::string matlabExec;
  34. // refactor-nice.pl: check this substitution
  35. // old: string matlabArgs;
  36. std::string matlabArgs;
  37. // refactor-nice.pl: check this substitution
  38. // old: string inputFN;
  39. std::string inputFN;
  40. // refactor-nice.pl: check this substitution
  41. // old: string outputFN;
  42. std::string outputFN;
  43. FILE *matlabPipe;
  44. /************************
  45. *
  46. * protected methods
  47. *
  48. **************************/
  49. int compute_prototypes ( const NICE::VVector & features,
  50. NICE::VVector & prototypes,
  51. std::vector<double> & weights,
  52. const std::vector<int> & assignment );
  53. public:
  54. ///////////////////// ///////////////////// /////////////////////
  55. // CONSTRUCTORS / DESTRUCTORS
  56. ///////////////////// ///////////////////// /////////////////////
  57. /**
  58. * @brief default constructor
  59. * @date 13-02-2014 (dd-mm-yyyy )
  60. * @author Alexander Freytag
  61. */
  62. KMeansMatlab ( );
  63. /**
  64. * @brief simple constructor
  65. * @author Erik Rodner, Alexander Freytag
  66. * Among others, you can specify for "section" the following attributes: "source_root", "tmpInput", "tmpOutput", "matlab_exec", "matlab_args"
  67. */
  68. KMeansMatlab( const NICE::Config * _conf, const std::string & _confSection = "KMeansMatlab" );
  69. /** simple destructor */
  70. virtual ~KMeansMatlab();
  71. /**
  72. * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
  73. * @author Alexander Freytag
  74. * @date 13-02-2014 ( dd-mm-yyyy )
  75. */
  76. void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "KMeansMatlab");
  77. ///////////////////// ///////////////////// /////////////////////
  78. // CLUSTERING STUFF
  79. ///////////////////// ///////////////////// //////////////////
  80. void cluster ( const NICE::VVector & features,
  81. NICE::VVector & prototypes,
  82. std::vector<double> & weights,
  83. std::vector<int> & assignment );
  84. ///////////////////// INTERFACE PERSISTENT /////////////////////
  85. // interface specific methods for store and restore
  86. ///////////////////// INTERFACE PERSISTENT /////////////////////
  87. /**
  88. * @brief Load object from external file (stream)
  89. * @author Alexander Freytag
  90. * @date 13-02-2014 ( dd-mm-yyyy )
  91. */
  92. void restore ( std::istream & is, int format = 0 );
  93. /**
  94. * @brief Save object to external file (stream)
  95. * @author Alexander Freytag
  96. * @date 13-02-2014 ( dd-mm-yyyy )
  97. */
  98. void store ( std::ostream & os, int format = 0 ) const;
  99. /**
  100. * @brief Clear object
  101. * @author Alexander Freytag
  102. * @date 13-02-2014 ( dd-mm-yyyy )
  103. */
  104. void clear ();
  105. };
  106. } // namespace
  107. #endif