KrisLibrary  1.0.0
HierarchicalClustering.h
1 #ifndef HIERARCHICAL_CLUSTERING_H
2 #define HIERARCHICAL_CLUSTERING_H
3 
4 #include "statistics.h"
5 
6 namespace Statistics {
7 
9 {
10  public:
11  struct distances
12  {
13  Real dist;
14  int index;
15  };
16 
17  // comparing operator for struct distances
18  struct Cmp{
19  bool operator()(const distances d1, const distances d2)
20  const
21  {
22  if(d1.dist == d2.dist)
23  {
24  return d1.index < d2.index;
25  }
26  return d1.dist < d2.dist;
27  }
28  };
29 
30  enum Type { SingleLinkage, CompleteLinkage, AverageLinkage };
31 
33  void Build(const std::vector<Vector>& data,int K,Type type = SingleLinkage);
34 
36  void Build(const Matrix& dist,int K,Type type = SingleLinkage);
37 
39  const std::vector<int>& Cluster(int i) const { return A[i]; }
40 
41  // 2d vector for storing lists of items in clusters
42  std::vector<std::vector<int> > A;
43 
44 };
45 
46 
47 
48 } //namespace Statistics
49 
50 #endif
Contains all definitions in the statistics directory.
Definition: BernoulliDistribution.h:6
Basic statistical utilities.
Definition: HierarchicalClustering.h:8
Definition: HierarchicalClustering.h:11
const std::vector< int > & Cluster(int i) const
Returns the indices of the data elements in the i&#39;th cluster.
Definition: HierarchicalClustering.h:39
void Build(const std::vector< Vector > &data, int K, Type type=SingleLinkage)
Builds the clustering using standard Euclidean distance.
Definition: HierarchicalClustering.cpp:7
Definition: HierarchicalClustering.h:18