template<typename Index_, typename Data_, typename Cluster_, typename Float_, typename Matrix_ = Matrix<Index_, Data_>>
class kmeans::RefineLloyd< Index_, Data_, Cluster_, Float_, Matrix_ >
Implements the Lloyd algorithm for k-means clustering.
The Lloyd algorithm is the simplest k-means clustering algorithm, involving several iterations of batch assignments and center calculations. Specifically, we assign each observation to its closest cluster, and once all points are assigned, we recompute the cluster centroids. This is repeated until there are no reassignments or the maximum number of iterations is reached.
In the Details::status
returned by run()
, the status code is either 0 (success) or 2 (maximum iterations reached without convergence). Previous versions of the library would report a status code of 1 upon encountering an empty cluster, but these are now just ignored.
- Template Parameters
-
Index_ | Integer type for the observation indices. |
Data_ | Numeric type for the data. |
Cluster_ | Integer type for the cluster assignments. |
Float_ | Floating-point type for the centroids. This will also be used for any internal distance calculations. |
Matrix_ | Type for the input data matrix. This should satisfy the Matrix interface. |
- See also
- Lloyd, S. P. (1982).
Least squares quantization in PCM. IEEE Transactions on Information Theory 28, 128-137.