Skip to main content

Module distance

Module distance 

Source
Expand description

Shapelet distance core: per-window z-normalization and the sliding-window minimum z-normalized Euclidean distance (sdist), plus the Shapelet type.

This module provides the atomic numerical primitive that every downstream shapelet phase (discovery, transform, classifier) builds on. It is pure &[f64] arithmetic — no nalgebra conversion, no integration weights.

§Shapelet distance definition

Given a length-L shapelet S (stored already z-normalized) and a series T of length M ≥ L, the shapelet distance is the minimum over all M - L + 1 sliding windows of the Euclidean distance between the shapelet and the (independently, per-window) z-normalized window:

sdist(S, T) = min_{t = 0 .. M-L}  || z(T[t : t+L]) - S ||_2

Each window is z-normalized independently at comparison time — never the whole series once up front. This is what makes the distance scale- and offset-invariant (it captures shape, not amplitude/offset).

§z-normalization convention

Z-normalization here uses the population standard deviation (ddof = 0), matching the pyts convention. (sktime/aeon variants may use ddof = 1; that divergence is intentional and noted here.) A constant or near-constant window (population std ≤ 1e-12) normalizes to the zero vector rather than producing NaN/Inf.

Structs§

Shapelet
A discovered shapelet: a z-normalized discriminative subsequence plus its provenance in the training set.

Functions§

shapelet_distance
Shapelet distance sdist: the minimum over sliding windows of the z-normalized Euclidean distance between the (pre-normalized) shapelet and each per-window-normalized window of series.
z_normalize_into
Z-normalize src into dst in place (population std, ddof = 0).
z_normalize_window
Z-normalize a window slice, returning a freshly allocated vector.