mlpack  2.0.1
pelleg_moore_kmeans_statistic.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_KMEANS_PELLEG_MOORE_KMEANS_STATISTIC_HPP
16 #define __MLPACK_METHODS_KMEANS_PELLEG_MOORE_KMEANS_STATISTIC_HPP
17 
18 namespace mlpack {
19 namespace kmeans {
20 
27 {
28  public:
31 
34  template<typename TreeType>
36  {
37  centroid.zeros(node.Dataset().n_rows);
38 
39  // Hope it's a depth-first build procedure. Also, this won't work right for
40  // trees that have self-children or stuff like that.
41  for (size_t i = 0; i < node.NumChildren(); ++i)
42  {
43  centroid += node.Child(i).NumDescendants() *
44  node.Child(i).Stat().Centroid();
45  }
46 
47  for (size_t i = 0; i < node.NumPoints(); ++i)
48  {
49  centroid += node.Dataset().col(node.Point(i));
50  }
51 
52  if (node.NumDescendants() > 0)
53  centroid /= node.NumDescendants();
54  else
55  centroid.fill(DBL_MAX); // Invalid centroid. What else can we do?
56  }
57 
59  const arma::uvec& Blacklist() const { return blacklist; }
61  arma::uvec& Blacklist() { return blacklist; }
62 
64  const arma::vec& Centroid() const { return centroid; }
66  arma::vec& Centroid() { return centroid; }
67 
68  private:
70  arma::uvec blacklist;
72  arma::vec centroid;
73 };
74 
75 } // namespace kmeans
76 } // namespace mlpack
77 
78 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
PellegMooreKMeansStatistic(TreeType &node)
Initialize the statistic for a node; this calculates the centroid and caches it.
arma::vec & Centroid()
Modify the node's centroid (be careful!).
A statistic for trees which holds the blacklist for Pelleg-Moore k-means clustering (which represents...
const arma::uvec & Blacklist() const
Get the cluster blacklist.
arma::uvec blacklist
The cluster blacklist for the node.
arma::uvec & Blacklist()
Modify the cluster blacklist.
const arma::vec & Centroid() const
Get the node's centroid.
arma::vec centroid
The centroid of the node, cached for use during prunes.
PellegMooreKMeansStatistic()
Initialize the statistic without a node (this does nothing).