nirs4all.analysis.playground_distances module

Paired-spectrum and repetition distances for exploratory analysis.

Definitions originate in Studio 0.9.1 shared/metrics_computer.py. The historical small-sample approximations remain available, but are explicitly identified by effective_metric and diagnostics instead of mislabeled. This module neither trains predictive models nor imports Studio.

nirs4all.analysis.playground_distances.paired_spectral_distances(reference: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], final: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], *, metric: str = 'euclidean', scale: str = 'linear') → dict[str, Any][source]

Compute row-aligned before/after distances and their actual provenance.

mahalanobis uses Ledoit-Wolf on combined observations when at least n_features + 2 pairs exist. The historical smaller-sample Euclidean approximation is explicit. PCA uses at most ten components of the combined data, capped at n_pairs - 1; a single pair similarly reports Euclidean. Unexpected estimator failures propagate: they never trigger another metric. Cosine of a zero vector remains undefined, not a fabricated zero distance.

nirs4all.analysis.playground_distances.repetition_variance(values: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], group_ids: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str], *, reference: str = 'group_mean', metric: str = 'euclidean') → dict[str, Any][source]

Preserve historical sorted-group ordering and original sample indices.

Singletons are excluded. selected retains the old group-mean alias, explicitly recorded. The historically unsupported repetition Mahalanobis and PCA metrics report the actual Euclidean calculation, not a false name.