v2.0.0
Loading...
Searching...
No Matches
kmeans.cpp File Reference

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>
Include dependency graph for kmeans.cpp:

Go to the source code of this file.

Detailed Description

K-means batch/online update kernels, replicate driver and empty-cluster handling.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2026 MNE-CPP Authors

Author
Christoph Dinh chris.nosp@m.toph.nosp@m..dinh.nosp@m.@mne.nosp@m.-cpp..nosp@m.org
Since
2.0.0
Date
March 2026

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.