KMeans
Namespace: MATHLIB · Library: Math Library
#include <math/kmeans.h>
class UTILSLIB::KMeans
Lloyd-style K-means partitional clustering with configurable distance metric, seeding strategy, replicate count, empty-cluster policy and optional online refinement phase.
Lloyd-style K-means clustering with configurable metric, seeding and replicates.
Public Methods
KMeans(distance, start, replicates, emptyact, online, maxit)
Constructs a KMeans algorithm object.
Parameters:
-
distance : QString (optional) K-Means distance measure: "sqeuclidean" (default), "cityblock" , "cosine", "correlation", "hamming".
-
start : QString (optional) Cluster initialization: "sample" (default), "uniform", "cluster".
-
replicates : qint32 (optional) Number of K-Means replicates, which are generated. Best is returned.
-
emptyact : QString (optional) What happens if a cluster goes empty: "error" (default), "drop", "singleton".
-
online : bool (optional) If centroids should be updated during iterations: true (default), false.
-
maxit : qint32 (optional) Maximal number of iterations per replicate; 100 by default.
KMeans(distance, start, replicates, emptyact, online, maxit)
Constructs a KMeans algorithm object using enum parameters (preferred for performance).
Parameters:
-
distance : KMeansDistance Distance metric.
-
start : KMeansStart Cluster initialization strategy.
-
replicates : qint32 Number of K-Means replicates. Best is returned.
-
emptyact : KMeansEmptyAction What happens if a cluster goes empty.
-
online : bool If centroids should be updated during iterations.
-
maxit : qint32 Maximal number of iterations per replicate.
calculate(X, kClusters, idx, C, sumD, D)
Clusters input data X.
Parameters:
-
X : const Eigen::MatrixXd & Input data (rows = points; cols = p dimensional space).
-
kClusters : qint32 Number of k clusters.
-
idx : Eigen::VectorXi & The cluster indices to which cluster the input points belong to.
-
C : Eigen::MatrixXd & Cluster centroids k x p.
-
sumD : Eigen::VectorXd & Summation of the distances to the centroid within one cluster.
-
D : Eigen::MatrixXd & Cluster distances to the centroid.
Returns:
- bool — true if clustering succeeded, false otherwise.
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>