12 #ifndef MLPACK_METHODS_KMEANS_KMEANS_HPP 13 #define MLPACK_METHODS_KMEANS_KMEANS_HPP 69 typename InitialPartitionPolicy = SampleInitialization,
70 typename EmptyClusterPolicy = MaxVarianceNewCluster,
71 template<
class,
class>
class LloydStepType = NaiveKMeans,
72 typename MatType = arma::mat>
89 KMeans(
const size_t maxIterations = 1000,
90 const MetricType metric = MetricType(),
91 const InitialPartitionPolicy partitioner = InitialPartitionPolicy(),
92 const EmptyClusterPolicy emptyClusterAction = EmptyClusterPolicy());
108 void Cluster(
const MatType& data,
109 const size_t clusters,
110 arma::Row<size_t>& assignments,
111 const bool initialGuess =
false);
126 void Cluster(
const MatType& data,
128 arma::mat& centroids,
129 const bool initialGuess =
false);
151 void Cluster(
const MatType& data,
152 const size_t clusters,
153 arma::Row<size_t>& assignments,
154 arma::mat& centroids,
155 const bool initialAssignmentGuess =
false,
156 const bool initialCentroidGuess =
false);
164 const MetricType&
Metric()
const {
return metric; }
169 const InitialPartitionPolicy&
Partitioner()
const {
return partitioner; }
175 {
return emptyClusterAction; }
180 template<
typename Archive>
181 void serialize(Archive& ar,
const uint32_t version);
185 size_t maxIterations;
189 InitialPartitionPolicy partitioner;
191 EmptyClusterPolicy emptyClusterAction;
198 #include "kmeans_impl.hpp" 200 #endif // MLPACK_METHODS_KMEANS_KMEANS_HPP void serialize(Archive &ar, const uint32_t version)
Serialize the k-means object.
void Cluster(const MatType &data, const size_t clusters, arma::Row< size_t > &assignments, const bool initialGuess=false)
Perform k-means clustering on the data, returning a list of cluster assignments.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
InitialPartitionPolicy & Partitioner()
Modify the initial partitioning policy.
KMeans(const size_t maxIterations=1000, const MetricType metric=MetricType(), const InitialPartitionPolicy partitioner=InitialPartitionPolicy(), const EmptyClusterPolicy emptyClusterAction=EmptyClusterPolicy())
Create a K-Means object and (optionally) set the parameters which K-Means will be run with...
const InitialPartitionPolicy & Partitioner() const
Get the initial partitioning policy.
size_t & MaxIterations()
Set the maximum number of iterations.
const MetricType & Metric() const
Get the distance metric.
MetricType & Metric()
Modify the distance metric.
const EmptyClusterPolicy & EmptyClusterAction() const
Get the empty cluster policy.
size_t MaxIterations() const
Get the maximum number of iterations.
EmptyClusterPolicy & EmptyClusterAction()
Modify the empty cluster policy.
LMetric< 2, true > EuclideanDistance
The Euclidean (L2) distance.
This class implements K-Means clustering, using a variety of possible implementations of Lloyd's algo...