stress
function stress(m): MetricResult;Defined in: metrics/distance.ts:47
How far the projected distances are from the originals.
The classic distance-preservation measure. Sensitive to scale: a projection that halves every distance is perfect in shape but scores badly here. Use scaleNormalizedStress if the projection’s units are arbitrary, which they are for t-SNE, UMAP and most non-linear methods.
- Needs: high-dimensional data and projection. No labels.
- Range: [0, ∞), lower is better; 0 means the distances match exactly. Around 1 means the error is as large as the distances themselves.
- Cost: O(1), from an O(N²·D) pass.
Per-point values give each point’s share of the total squared error — useful for colouring, but a share rather than a score, so they sum to 1 instead of averaging to the stress. The one exception is an exactly perfect projection: with no error to apportion the array is all zeros and sums to 0, not 1.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
m | DistanceMoments |
Returns
Section titled “Returns”Kruskal, Psychometrika 29 (1964) https://doi.org/10.1007/BF02289565
Example
Section titled “Example”import { analyze, stress } from "@saehrimnir/sickle";
const a = analyze(data, projection);const s = stress(a.moments);
s.value; // 0.0807 — raw Kruskal stress, in the data's own unitss.localKind; // "share"s.local[0]; // 0.0104 — this point's share of the error; the array sums to 1