mlpack 3.4.2
kill_empty_clusters.hpp
Go to the documentation of this file.
1
13#ifndef __MLPACK_METHODS_KMEANS_KILL_EMPTY_CLUSTERS_HPP
14#define __MLPACK_METHODS_KMEANS_KILL_EMPTY_CLUSTERS_HPP
15
16#include <mlpack/prereqs.hpp>
17
18namespace mlpack {
19namespace kmeans {
20
26{
27 public:
30
48 template<typename MetricType, typename MatType>
49 static inline force_inline void EmptyCluster(
50 const MatType& /* data */,
51 const size_t emptyCluster,
52 const arma::mat& /* oldCentroids */,
53 arma::mat& newCentroids,
54 arma::Col<size_t>& clusterCounts,
55 MetricType& /* metric */,
56 const size_t /* iteration */)
57{
58 // Remove the empty cluster.
59 if (emptyCluster < newCentroids.n_cols)
60 {
61 newCentroids.shed_col(emptyCluster);
62 clusterCounts.shed_row(emptyCluster);
63 }
64}
65
67 template<typename Archive>
68 void serialize(Archive& /* ar */, const unsigned int /* version */) { }
69};
70
71} // namespace kmeans
72} // namespace mlpack
73
74#endif
Policy which allows K-Means to "kill" empty clusters without any error being reported.
static force_inline void EmptyCluster(const MatType &, const size_t emptyCluster, const arma::mat &, arma::mat &newCentroids, arma::Col< size_t > &clusterCounts, MetricType &, const size_t)
This function sets an empty cluster found during k-means to all DBL_MAX (i.e.
KillEmptyClusters()
Default constructor required by EmptyClusterPolicy policy.
void serialize(Archive &, const unsigned int)
Serialize the empty cluster policy (nothing to do).
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.
#define force_inline
Definition: prereqs.hpp:55