IMP  2.2.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].coordinates_begin(),
43  centers[i].coordinates_end());
44  }
45  }
46 #endif
47  const algebra::VectorKD &get_cluster_center(unsigned int i) const {
48  return centers_[i];
49  }
50  unsigned int get_number_of_clusters() const IMP_OVERRIDE;
51  const Ints &get_cluster(unsigned int i) const IMP_OVERRIDE;
52  int get_cluster_representative(unsigned int i) const IMP_OVERRIDE;
53 
54  IMP_OBJECT_METHODS(PartitionalClusteringWithCenter);
55 };
56 
57 IMPSTATISTICS_END_NAMESPACE
58 
59 #endif /* IMPSTATISTICS_PARTITIONAL_CLUSTERING_WITH_CENTER_H */
virtual int get_cluster_representative(unsigned int cluster_index) const =0
Compute a distance metric between two points.
virtual const Ints & get_cluster(unsigned int cluster_index) const =0
A Cartesian vector in D-dimensions.
Definition: VectorD.h:52
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
VectorD<-1 > VectorKD
Definition: VectorD.h:411
A base class for clustering results where each item is in one cluster.