Cluster kmeansoptions - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Cluster is 0.1.0 — read its documentation.

HomeClusterPartitioning

KMeansOptions

Where KMeans.Fit starts, and when it stops.

public sealed record KMeansOptions

PropertiesMaxIterations caps the Lloyd loop (max_iter, default 300). Tolerance is the convergence threshold before scaling (tol, default 1e-4). Seed drives this package's own generator when no centres are given. InitialCentres is the starting block itself, row-major and clusterCount × featureCount, or null to choose one.

Example — the same data, started two ways.

using Lodestar.Cluster;

double[] samples = [0.0, 0.0, 0.0, 1.0, 10.0, 10.0, 10.0, 11.0, 5.0, 5.0];

// Given centres: reproducible anywhere, and comparable against Python.
KMeans given = KMeans.Fit(samples, featureCount: 2, clusterCount: 3,
    new KMeansOptions { InitialCentres = [0.0, 0.0, 10.0, 10.0, 5.0, 5.0] });

// Drawn centres: reproducible run to run here, and nowhere else.
KMeans drawn = KMeans.Fit(samples, featureCount: 2, clusterCount: 3,
    new KMeansOptions { Seed = 11 });

double reachedTheSamePartition = drawn.Inertia - given.Inertia;  // => 0

RemarksSeed and InitialCentres answer different questions, and only one of them travels. A seed reproduces a run of Lodestar: the two libraries draw from different generators, so a shared seed shares nothing. InitialCentres is what the oracle corpus passes, and what a caller comparing against Python must pass too.

Tolerance is multiplied by the mean feature variance before use, so it is scale-free; 0 removes the shift test and iterates until the labels settle. A negative, infinite or NaN tolerance is refused by KMeans.Fit with ArgumentOutOfRangeException, as scikit-learn refuses a tol outside [0, inf) — a NaN would otherwise switch the shift test off without a word.

Applies to — net10.0, netstandard2.0.

See alsoKMeans.Fit, KMeans, decisions/0004.

Members

member what it does
KMeansOptions.Equals Value equality, the centres element by element.
KMeansOptions.GetHashCode A hash consistent with it.