Signature
polars_ts.imaging.signature
Path signature features and signature image visualization.
Computes truncated path signatures as feature vectors for time series, and reshapes them into 2D images for vision-based analysis.
Uses iisignature when available for fast computation; falls back to
a pure-numpy implementation for basic signatures.
_time_augment(x)
Prepend a normalised time channel: path becomes 2D (t, x).
_leadlag_augment(x)
Lead-lag transform: (x_t, x_{t-1}) for richer path structure.
_basepoint_augment(path)
Prepend the origin as basepoint.
_apply_augmentations(x, augmentations)
Build a multi-dimensional path from a 1D series via augmentations.
_sig_numpy(path, depth)
Compute truncated signature using pure numpy (iterated integrals).
This is a reference implementation; for production use install iisignature.
_compute_signature(path, depth)
Compute the truncated signature, using iisignature if available.
signature_features(df, depth=3, augmentations=None, id_col='unique_id', target_col='y')
Extract truncated path signature features for each time series.
The signature is a sequence of iterated integrals that captures the
shape of a path up to reparametrisation. Truncating at depth d
gives a finite-dimensional feature vector.
Parameters
df
DataFrame with columns id_col and target_col.
depth
Truncation depth. Controls feature dimensionality:
depth 1 → d features, depth 2 → d + d², depth 3 → d + d² + d³.
augmentations
List of path augmentations to apply before computing the
signature. Options: "time" (prepend time channel),
"leadlag" (lead-lag transform), "basepoint" (prepend origin).
Default: ["time"].
id_col
Column identifying each time series.
target_col
Column with the time series values.
Returns
pl.DataFrame
DataFrame with columns [id_col, sig_0, sig_1, ..., sig_d].
to_signature_image(df, depth=2, augmentations=None, id_col='unique_id', target_col='y')
Convert time series to signature images.
Computes the depth-2 signature and reshapes the d² terms into a d × d matrix for visualization. Higher-depth terms are discarded.
Parameters
df
DataFrame with columns id_col and target_col.
depth
Signature depth (must be >= 2). Only the depth-2 terms are
used for the image; depth-1 terms are discarded.
augmentations
Path augmentations. Default: ["time"].
id_col
Column identifying each time series.
target_col
Column with the time series values.
Returns
dict[str, np.ndarray] Mapping from series ID to a d × d matrix of depth-2 signature terms.