00001 00064 #ifndef __MOST_DISCRIMINATING_DATA_POINTS_H__ 00065 #define __MOST_DISCRIMINATING_DATA_POINTS_H__ 00066 00067 #include <cstddef> 00068 #include <vector> 00069 00070 namespace cob_3d_features 00071 { 00072 00073 struct SortableDataPoint 00074 { 00075 public: 00076 SortableDataPoint() : idx(-1), dist(0.0) { } 00077 00078 SortableDataPoint(const int &index, const float &mean_distance) : idx(index), dist(mean_distance) 00079 { } 00080 00081 inline bool 00082 operator<( const SortableDataPoint& other) const { return (dist < other.dist); } 00083 00084 inline bool 00085 operator>( const SortableDataPoint& other) const { return (dist > other.dist); } 00086 00087 inline bool 00088 operator<=( const SortableDataPoint& other) const { return (dist <= other.dist); } 00089 00090 inline bool 00091 operator>=( const SortableDataPoint& other) const { return (dist >= other.dist); } 00092 00093 00094 int idx; 00095 float dist; 00096 00097 }; 00098 00099 class MostDiscriminatingDataPoints 00100 { 00101 public: 00102 MostDiscriminatingDataPoints () : predefined_initial_centers_(false), k_(1) { } 00103 00104 00105 inline void 00106 setInputData(const std::vector<std::vector<float> > * const pdata) 00107 { 00108 pdata_ = pdata; 00109 m_ = (pdata->at(0)).size(); 00110 n_ = pdata->size(); 00111 } 00112 00113 inline void 00114 setK(const int k) 00115 { 00116 k_ = k; 00117 } 00118 00119 inline void 00120 setInitialMeans(std::vector<int> * const pindices) 00121 { 00122 init_indices_ = pindices; 00123 predefined_initial_centers_ = true; 00124 k_ = pindices->size(); 00125 } 00126 00127 inline void 00128 resetInitialMeans() 00129 { 00130 predefined_initial_centers_ = false; 00131 } 00132 00133 void 00134 computeInitialMeans(std::vector<int> * const output_init_indices); 00135 00136 void 00137 computeDataPoints(std::vector<std::vector<float> > * const k_means); 00138 00139 protected: 00140 void 00141 computeKmeans(); 00142 00143 int 00144 eStep(); 00145 00146 void 00147 mStep(); 00148 00149 bool predefined_initial_centers_; 00150 size_t k_; 00151 size_t m_; // size of a data point 00152 size_t n_; // number of data points 00153 const std::vector<std::vector<float> > *pdata_; // n x m 00154 std::vector<std::vector<float> > *pmeans_; // k x m 00155 00156 std::vector<int> *init_indices_; 00157 std::vector<int> assigned_classes_; 00158 std::vector<int> count_; 00159 00160 }; 00161 } 00162 00163 #endif // __MOST_DISCRIMINATING_DATA_POINTS_H__