K-means batch/online update kernels, replicate driver and empty-cluster handling. More...
#include "kmeans.h"#include <cmath>#include <iostream>#include <algorithm>#include <vector>#include <QDebug>
Go to the source code of this file.
K-means batch/online update kernels, replicate driver and empty-cluster handling.
SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2026 MNE-CPP Authors
This translation unit implements the inner loop of UTILSLIB::KMeans: the batch Lloyd phase (compute pairwise distances, reassign points, recompute centroids), the optional online single-point refinement phase used to break out of shallow local minima, and the empty-cluster dispatch (error / drop / singleton-from-farthest-point) driven by the KMeansEmptyAction enum. Distance evaluation is factored per metric (squared Euclidean, city-block, cosine, correlation, Hamming) so that each replicate pays only for the metric the caller actually selected.
The driver runs m_iReps independent replicates seeded according to KMeansStart, keeps the one with the smallest total within-cluster distortion and returns its labels and centroids, matching the convention used by MATLAB's kmeans.
Definition in file kmeans.cpp.