mlpack  master
Public Member Functions | Private Attributes | 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...

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

Private Attributes

const arma::mat & centroids
 The clusters. More...
 
arma::Col< size_t > & counts
 The counts of points in each cluster. More...
 
const TreeType::Mat & dataset
 The dataset. More...
 
size_t distanceCalculations
 The number of O(d) distance calculations that have been performed. More...
 
MetricType & metric
 Instantiated metric. More...
 
arma::mat & newCentroids
 The new centroids. 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

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

template<typename MetricType , typename TreeType >
double mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::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.
template<typename MetricType , typename TreeType >
size_t mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::DistanceCalculations ( ) const
inline

Get the number of distance calculations that have been performed.

Definition at line 84 of file pelleg_moore_kmeans_rules.hpp.

References mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::distanceCalculations.

template<typename MetricType , typename TreeType >
size_t& mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::DistanceCalculations ( )
inline

Modify the number of distance calculations that have been performed.

Definition at line 86 of file pelleg_moore_kmeans_rules.hpp.

References mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::distanceCalculations.

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

Member Data Documentation

template<typename MetricType , typename TreeType >
const arma::mat& mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::centroids
private

The clusters.

Definition at line 92 of file pelleg_moore_kmeans_rules.hpp.

template<typename MetricType , typename TreeType >
arma::Col<size_t>& mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::counts
private

The counts of points in each cluster.

Definition at line 96 of file pelleg_moore_kmeans_rules.hpp.

template<typename MetricType , typename TreeType >
const TreeType::Mat& mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::dataset
private

The dataset.

Definition at line 90 of file pelleg_moore_kmeans_rules.hpp.

template<typename MetricType , typename TreeType >
size_t mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::distanceCalculations
private

The number of O(d) distance calculations that have been performed.

Definition at line 101 of file pelleg_moore_kmeans_rules.hpp.

Referenced by mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::DistanceCalculations().

template<typename MetricType , typename TreeType >
MetricType& mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::metric
private

Instantiated metric.

Definition at line 98 of file pelleg_moore_kmeans_rules.hpp.

template<typename MetricType , typename TreeType >
arma::mat& mlpack::kmeans::PellegMooreKMeansRules< MetricType, TreeType >::newCentroids
private

The new centroids.

Definition at line 94 of file pelleg_moore_kmeans_rules.hpp.


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