Each patient is a point in a 2D biomarker plane (axes: e.g. gene-expression score vs. protein biomarker level). This is the core mechanic behind stratified / precision medicine: instead of one protocol for everyone, patients are grouped by similarity so each group can receive the therapy that historically works best for that biomarker profile.
The grouping is unsupervised k-means clustering, run live via Lloyd's algorithm:
1. Assign: each patient → nearest centroid
cluster(i) = argmin_k ||x_i − μ_k||²
2. Update: each centroid → mean of its patients
μ_k = (1/|S_k|) Σ_{i∈S_k} x_i
3. Repeat until assignments stop changing
The algorithm provably decreases (never increases) the total inertia — the sum of squared distances from each patient to its assigned centroid — every iteration; the inertia chart under the plane tracks this fall live. Convergence means every patient's nearest centroid is the one it is already assigned to.
The faint colour wash across the plane is the Voronoi decision map: at every point it shows which centroid is nearest right now, i.e. which cohort a brand-new patient dropped there would be triaged into. It is recomputed from the same distance test as the assignment step, not a separate approximation, so it always matches the dot colours exactly at convergence.
- K slider — how many candidate therapy cohorts to stratify into.
- Run clustering — animates Lloyd's algorithm iteration by iteration until it converges.
- Click the plane — adds a new "patient" at that position and instantly assigns them to whichever existing group is nearest, exactly like triaging a new patient against an already-fitted stratification model.
- Drag / scroll — pan and zoom the biomarker plane; the Voronoi map and patients redraw at the new view.
Real precision-medicine pipelines use the same idea with dozens of dimensions (genomic variants, protein biomarkers, imaging features) instead of two, and richer clustering (Gaussian mixtures, spectral clustering) instead of plain k-means — but the loop of assign → average → repeat is the same one running here.