mlpack
Public Member Functions | List of all members
mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType > Class Template Reference

The rules class for the single-tree Pelleg-Moore kd-tree traversal for k-means clustering. More...

#include <pelleg_moore_kmeans_rules.hpp>

Public Member Functions

 PellegMooreKMeansRules (const typename TreeType::Mat &dataset, const arma::mat &centroids, arma::mat &newCentroids, arma::Col< size_t > &counts, MetricType &metric)
 Create the PellegMooreKMeansRules object. More...
 
double BaseCase (const size_t queryIndex, const size_t referenceIndex)
 The BaseCase() function for this single-tree algorithm does nothing. More...
 
double Score (const size_t queryIndex, TreeType &referenceNode)
 Determine if a cluster can be pruned, and if not, perform point-to-cluster comparisons. More...
 
double Rescore (const size_t queryIndex, TreeType &referenceNode, const double oldScore)
 Rescore to determine if a node can be pruned. More...
 
size_t DistanceCalculations () const
 Get the number of distance calculations that have been performed.
 
size_t & DistanceCalculations ()
 Modify the number of distance calculations that have been performed.
 

Detailed Description

template<typename MetricType, typename TreeType>
class mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >

The rules class for the single-tree Pelleg-Moore kd-tree traversal for k-means clustering.

Although TreeType is a free template parameter, this particular implementation is specialized to trees with hyper-rectangle bounds due to the pruning rule used to determine if one cluster dominates a node with respect to another cluster.

Our implementation here abuses the single-tree algorithm abstractions a little bit. Instead of doing a traversal for a particular query point, in this case we consider all clusters at once—so the query point is entirely ignored during in BaseCase() and Score().

Constructor & Destructor Documentation

◆ PellegMooreKMeansRules()

template<typename MetricType , typename TreeType >
mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::PellegMooreKMeansRules ( const typename TreeType::Mat &  dataset,
const arma::mat &  centroids,
arma::mat &  newCentroids,
arma::Col< size_t > &  counts,
MetricType &  metric 
)

Create the PellegMooreKMeansRules object.

Parameters
datasetThe dataset that the tree is built on.
centroidsThe current centroids.
newCentroidsNew centroids after this iteration (output).
countsCurrent cluster counts, to be replaced with new cluster counts.
metricInstantiated metric.

Member Function Documentation

◆ BaseCase()

template<typename MetricType , typename TreeType >
force_inline double mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::BaseCase ( const size_t  queryIndex,
const size_t  referenceIndex 
)
inline

The BaseCase() function for this single-tree algorithm does nothing.

Instead, point-to-cluster comparisons are handled as necessary in Score().

Parameters
queryIndexIndex of query point (fake, will be ignored).
referenceIndexIndex of reference point.

◆ Rescore()

template<typename MetricType , typename TreeType >
double mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::Rescore ( const size_t  queryIndex,
TreeType &  referenceNode,
const double  oldScore 
)

Rescore to determine if a node can be pruned.

In this case, a node can never be pruned during rescoring, so this just returns oldScore.

Parameters
queryIndexIndex of query point (fake, will be ignored).
referenceNodeNode containing points in the dataset.
oldScoreResulting score from Score().

◆ Score()

template<typename MetricType , typename TreeType >
double mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::Score ( const size_t  queryIndex,
TreeType &  referenceNode 
)

Determine if a cluster can be pruned, and if not, perform point-to-cluster comparisons.

The point-to-cluster comparisons are performed here and not in BaseCase() because of the complexity of managing the blacklist.

Parameters
queryIndexIndex of query point (fake, will be ignored).
referenceNodeNode containing points in the dataset.

The documentation for this class was generated from the following files: