13 #ifndef MLPACK_METHODS_KMEANS_PELLEG_MOORE_KMEANS_STATISTIC_HPP 14 #define MLPACK_METHODS_KMEANS_PELLEG_MOORE_KMEANS_STATISTIC_HPP 32 template<
typename TreeType>
35 centroid.zeros(node.Dataset().n_rows);
39 for (
size_t i = 0; i < node.NumChildren(); ++i)
41 centroid += node.Child(i).NumDescendants() *
42 node.Child(i).Stat().Centroid();
45 for (
size_t i = 0; i < node.NumPoints(); ++i)
47 centroid += node.Dataset().col(node.Point(i));
50 if (node.NumDescendants() > 0)
51 centroid /= node.NumDescendants();
53 centroid.fill(DBL_MAX);
57 const arma::uvec&
Blacklist()
const {
return blacklist; }
62 const arma::vec&
Centroid()
const {
return centroid; }
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.
const arma::vec & Centroid() const
Get the node's centroid.
A statistic for trees which holds the blacklist for Pelleg-Moore k-means clustering (which represents...
arma::vec & Centroid()
Modify the node's centroid (be careful!).
const arma::uvec & Blacklist() const
Get the cluster blacklist.
arma::uvec & Blacklist()
Modify the cluster blacklist.
PellegMooreKMeansStatistic()
Initialize the statistic without a node (this does nothing).