IMP  2.3.1
The Integrative Modeling Platform
PartitionalClusteringWithCenter.h
Go to the documentation of this file.
1 /**
2  * \file IMP/statistics/PartitionalClusteringWithCenter.h
3  * \brief Cluster sets of points.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPSTATISTICS_PARTITIONAL_CLUSTERING_WITH_CENTER_H
10 #define IMPSTATISTICS_PARTITIONAL_CLUSTERING_WITH_CENTER_H
11 
12 #include <IMP/statistics/statistics_config.h>
13 #include "PartitionalClustering.h"
14 
15 IMPSTATISTICS_BEGIN_NAMESPACE
16 /** In addition to the information in the Clustering base class,
17  PartitionalClusteringWithCenter stores a cluster center for
18  each cluster.
19  The cluster center is a point in the space defined by the
20  embedding.
21 
22  The representative for each cluster is the member whose
23  location in the embedding is closest to the cluster center.
24 */
25 class IMPSTATISTICSEXPORT PartitionalClusteringWithCenter
26  : public PartitionalClustering {
27  IMP::base::Vector<Ints> clusters_;
28  Ints reps_;
29  algebra::VectorKDs centers_;
30 
31  public:
32 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
33  template <int D>
35  const IMP::base::Vector<Ints> &clusters,
36  const IMP::base::Vector<algebra::VectorD<D> > &centers, const Ints &reps)
37  : PartitionalClustering("k-means"),
38  clusters_(clusters),
39  reps_(reps),
40  centers_(reps.size()) {
41  for (unsigned int i = 0; i < centers_.size(); ++i) {
42  centers_[i] = algebra::VectorKD(centers[i].begin(), centers[i].end());
43  }
44  }
45 #endif
46  const algebra::VectorKD &get_cluster_center(unsigned int i) const {
47  return centers_[i];
48  }
49  unsigned int get_number_of_clusters() const IMP_OVERRIDE;
50  const Ints &get_cluster(unsigned int i) const IMP_OVERRIDE;
51  int get_cluster_representative(unsigned int i) const IMP_OVERRIDE;
52 
53  IMP_OBJECT_METHODS(PartitionalClusteringWithCenter);
54 };
55 
56 IMPSTATISTICS_END_NAMESPACE
57 
58 #endif /* IMPSTATISTICS_PARTITIONAL_CLUSTERING_WITH_CENTER_H */
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
virtual int get_cluster_representative(unsigned int cluster_index) const =0
Return the index of an item that "typifies" the ith cluster.
Compute a distance metric between two points.
virtual const Ints & get_cluster(unsigned int cluster_index) const =0
Return the list of indexes in the ith cluster.
A Cartesian vector in D-dimensions.
Definition: VectorD.h:52
VectorD<-1 > VectorKD
Definition: VectorD.h:411
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
A base class for clustering results where each item is in one cluster.