PellegMooreKMeansRules< MetricType, TreeType > Class Template Reference

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

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...

 
size_t DistanceCalculations () const
 Get the number of distance calculations that have been performed. More...

 
size_t & DistanceCalculations ()
 Modify the number of distance calculations that have been performed. More...

 
double Rescore (const size_t queryIndex, TreeType &referenceNode, const double oldScore)
 Rescore to determine if a node can be pruned. 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...

 

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().

Definition at line 33 of file pelleg_moore_kmeans_rules.hpp.

Constructor & Destructor Documentation

◆ PellegMooreKMeansRules()

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()

double BaseCase ( const size_t  queryIndex,
const size_t  referenceIndex 
)

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.

◆ DistanceCalculations() [1/2]

size_t DistanceCalculations ( ) const
inline

Get the number of distance calculations that have been performed.

Definition at line 84 of file pelleg_moore_kmeans_rules.hpp.

◆ DistanceCalculations() [2/2]

size_t& DistanceCalculations ( )
inline

Modify the number of distance calculations that have been performed.

Definition at line 86 of file pelleg_moore_kmeans_rules.hpp.

◆ Rescore()

double 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()

double 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 file: