Change DistanceMetric to MetricType to be more in line with the rest of the
mlpack codebase.
This commit is contained in:
@@ -43,7 +43,7 @@ namespace kmeans /** K-Means clustering. */ {
|
||||
* k.Cluster(data, 6, assignments); // 6 clusters.
|
||||
* @endcode
|
||||
*
|
||||
* @tparam DistanceMetric The distance metric to use for this KMeans; see
|
||||
* @tparam MetricType The distance metric to use for this KMeans; see
|
||||
* metric::LMetric for an example.
|
||||
* @tparam InitialPartitionPolicy Initial partitioning policy; must implement a
|
||||
* default constructor and 'void Cluster(const arma::mat&, const size_t,
|
||||
@@ -54,7 +54,7 @@ namespace kmeans /** K-Means clustering. */ {
|
||||
*
|
||||
* @see RandomPartition, RefinedStart, AllowEmptyClusters, MaxVarianceNewCluster
|
||||
*/
|
||||
template<typename DistanceMetric = metric::SquaredEuclideanDistance,
|
||||
template<typename MetricType = metric::SquaredEuclideanDistance,
|
||||
typename InitialPartitionPolicy = RandomPartition,
|
||||
typename EmptyClusterPolicy = MaxVarianceNewCluster>
|
||||
class KMeans
|
||||
@@ -75,7 +75,7 @@ class KMeans
|
||||
* (0 is valid, but the algorithm may never terminate).
|
||||
* @param overclusteringFactor Factor controlling how many extra clusters are
|
||||
* found and then merged to get the desired number of clusters.
|
||||
* @param metric Optional DistanceMetric object; for when the metric has state
|
||||
* @param metric Optional MetricType object; for when the metric has state
|
||||
* it needs to store.
|
||||
* @param partitioner Optional InitialPartitionPolicy object; for when a
|
||||
* specially initialized partitioning policy is required.
|
||||
@@ -84,7 +84,7 @@ class KMeans
|
||||
*/
|
||||
KMeans(const size_t maxIterations = 1000,
|
||||
const double overclusteringFactor = 1.0,
|
||||
const DistanceMetric metric = DistanceMetric(),
|
||||
const MetricType metric = MetricType(),
|
||||
const InitialPartitionPolicy partitioner = InitialPartitionPolicy(),
|
||||
const EmptyClusterPolicy emptyClusterAction = EmptyClusterPolicy());
|
||||
|
||||
@@ -158,9 +158,9 @@ class KMeans
|
||||
size_t& MaxIterations() { return maxIterations; }
|
||||
|
||||
//! Get the distance metric.
|
||||
const DistanceMetric& Metric() const { return metric; }
|
||||
const MetricType& Metric() const { return metric; }
|
||||
//! Modify the distance metric.
|
||||
DistanceMetric& Metric() { return metric; }
|
||||
MetricType& Metric() { return metric; }
|
||||
|
||||
//! Get the initial partitioning policy.
|
||||
const InitialPartitionPolicy& Partitioner() const { return partitioner; }
|
||||
@@ -179,7 +179,7 @@ class KMeans
|
||||
//! Maximum number of iterations before giving up.
|
||||
size_t maxIterations;
|
||||
//! Instantiated distance metric.
|
||||
DistanceMetric metric;
|
||||
MetricType metric;
|
||||
//! Instantiated initial partitioning policy.
|
||||
InitialPartitionPolicy partitioner;
|
||||
//! Instantiated empty cluster policy.
|
||||
|
||||
@@ -19,16 +19,16 @@ namespace kmeans {
|
||||
/**
|
||||
* Construct the K-Means object.
|
||||
*/
|
||||
template<typename DistanceMetric,
|
||||
template<typename MetricType,
|
||||
typename InitialPartitionPolicy,
|
||||
typename EmptyClusterPolicy>
|
||||
KMeans<
|
||||
DistanceMetric,
|
||||
MetricType,
|
||||
InitialPartitionPolicy,
|
||||
EmptyClusterPolicy>::
|
||||
KMeans(const size_t maxIterations,
|
||||
const double overclusteringFactor,
|
||||
const DistanceMetric metric,
|
||||
const MetricType metric,
|
||||
const InitialPartitionPolicy partitioner,
|
||||
const EmptyClusterPolicy emptyClusterAction) :
|
||||
maxIterations(maxIterations),
|
||||
@@ -49,12 +49,12 @@ KMeans(const size_t maxIterations,
|
||||
}
|
||||
}
|
||||
|
||||
template<typename DistanceMetric,
|
||||
template<typename MetricType,
|
||||
typename InitialPartitionPolicy,
|
||||
typename EmptyClusterPolicy>
|
||||
template<typename MatType>
|
||||
void KMeans<
|
||||
DistanceMetric,
|
||||
MetricType,
|
||||
InitialPartitionPolicy,
|
||||
EmptyClusterPolicy>::
|
||||
FastCluster(MatType& data,
|
||||
@@ -488,12 +488,12 @@ FastCluster(MatType& data,
|
||||
* centroids too. If this is properly inlined, there shouldn't be any
|
||||
* performance penalty whatsoever.
|
||||
*/
|
||||
template<typename DistanceMetric,
|
||||
template<typename MetricType,
|
||||
typename InitialPartitionPolicy,
|
||||
typename EmptyClusterPolicy>
|
||||
template<typename MatType>
|
||||
inline void KMeans<
|
||||
DistanceMetric,
|
||||
MetricType,
|
||||
InitialPartitionPolicy,
|
||||
EmptyClusterPolicy>::
|
||||
Cluster(const MatType& data,
|
||||
@@ -509,12 +509,12 @@ Cluster(const MatType& data,
|
||||
* Perform k-means clustering on the data, returning a list of cluster
|
||||
* assignments and the centroids of each cluster.
|
||||
*/
|
||||
template<typename DistanceMetric,
|
||||
template<typename MetricType,
|
||||
typename InitialPartitionPolicy,
|
||||
typename EmptyClusterPolicy>
|
||||
template<typename MatType>
|
||||
void KMeans<
|
||||
DistanceMetric,
|
||||
MetricType,
|
||||
InitialPartitionPolicy,
|
||||
EmptyClusterPolicy>::
|
||||
Cluster(const MatType& data,
|
||||
|
||||
Reference in New Issue
Block a user