KrisLibrary  1.0.0
KMeans.h
1 #ifndef STAT_KMEANS_H
2 #define STAT_KMEANS_H
3 
4 #include <KrisLibrary/math/vector.h>
5 #include <vector>
6 
7 namespace Statistics {
8  using namespace Math;
9 
15 class KMeans
16 {
17  public:
18  KMeans(const std::vector<Vector>& data);
19  KMeans(const std::vector<Vector>& data,int k);
20  virtual ~KMeans() {}
21  int GetK() const { return (int)centers.size(); }
22  void SetK(int k);
24  void RandomInitialCenters();
25  void ClearLabels();
27  void Iterate(int& maxIters);
28 
29  //Individual steps of the iteration
31  bool CalcLabelsFromCenters();
33  void CalcCentersFromLabels();
34 
36  Real AverageDistance(int c);
38  void AverageDistance(std::vector<Real>& dist);
39 
41  virtual Real Distance(const Vector& a,const Vector& b)
42  { return a.distance(b); }
43 
44  const std::vector<Vector>& data;
45  const std::vector<Real>* weights;
46  std::vector<int> labels;
47  std::vector<Vector> centers;
48 };
49 
50 }
51 
52 #endif
virtual Real Distance(const Vector &a, const Vector &b)
Overrideable: distance metric.
Definition: KMeans.h:41
Contains all definitions in the statistics directory.
Definition: BernoulliDistribution.h:6
A simple clustering method to choose k clusters from a set of data.
Definition: KMeans.h:15
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12