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