pysiglib.transform_path

pysiglib.transform_path#

Added in version v0.2.

transform_path(path, *, time_aug=False, lead_lag=False, end_time=1.0, n_jobs=1)[source]#

This function applies time-augmentation and/or the lead-lag transformation to a path. Given a \(d\)-dimensional path \((X_{t_i})_{i=1}^L\), the time-augmented path is formed by adding time as the last channel of the path,

\[\widehat{X}_{t_i} := (X_{t_i}, t_i).\]

The lead-lag transformation is defined by

\[X^{LL}_{t_i} := (X^{\text{Lag}}_{t_i}, X^{\text{Lead}}_{t_i})\]
\[\begin{split}X^{\text{Lead}}_{t_i} := \begin{cases} X_{t_k} & \text{if } i = 2k, \\ X_{t_k} & \text{if } i = 2k - 1, \end{cases}\end{split}\]
\[\begin{split}X^{\text{Lag}}_{t_i} := \begin{cases} X_{t_k} & \text{if } i = 2k, \\ X_{t_k} & \text{if } i = 2k + 1, \end{cases}\end{split}\]

so that

\[(X^{\text{Lag}}_{t_i})_{i=0}^L = (X_{t_0}, X_{t_0}, X_{t_1}, X_{t_1}, X_{t_2}, \ldots),\]
\[(X^{\text{Lead}}_{t_i})_{i=0}^L = (X_{t_0}, X_{t_1}, X_{t_1}, X_{t_2}, X_{t_2}, \ldots).\]

When both time_aug and lead_lag are set to True, time-augmentation is applied after the lead-lag transformation.

Parameters:
  • path (numpy.ndarray | torch.tensor) – The underlying path or batch of paths, of shape (..., length, dimension).

  • time_aug (bool) – If True, applies time-augmentation by adding a linear channel to the path spanning \([0, t_L]\). \(t_L\) is given by the parameter end_time and defaults to 1.

  • lead_lag (bool) – If True, applies the lead-lag transform.

  • end_time (float) – End time for time-augmentation, \(t_L\).

  • n_jobs (int) – Number of threads to run in parallel. If n_jobs = 1, the computation is run serially. If set to -1, all available threads are used. For n_jobs below -1, (max_threads + 1 + n_jobs) threads are used. For example if n_jobs = -2, all threads but one are used.

Returns:

Transformed paths.

Return type:

numpy.ndarray | torch.tensor

Note

Note that in the definition of the lead-lag transformation, we have intentionally chosen \(X^{LL} := (X^{\text{Lag}}, X^{\text{Lead}})\) rather than the more commonly used order of channels \(X^{LL} := (X^{\text{Lead}}, X^{\text{Lag}})\).

Important

This function is provided for convenience only, and one should prefer the in-built flags for these transformations within pysiglib functions where available. For example, running pysiglib.sig with lead_lag=True will be faster and more memory-efficient than pre-computing the lead-lag transform and passing it to pysiglib.sig, as the former method will never explicitly compute or store the lead-lag transform, and will instead modify the signature computation directly.

Example:#

import torch
import pysiglib

path = torch.tensor([[0., 1.], [2., 3.]])
transformed = pysiglib.transform_path(path, time_aug=True, lead_lag=True)
print(transformed)

Citation#

If you found this library useful in your research, please consider citing the paper:

@article{shmelev2025pysiglib,
  title={pySigLib-Fast Signature-Based Computations on CPU and GPU},
  author={Shmelev, Daniil and Salvi, Cristopher},
  journal={arXiv preprint arXiv:2509.10613},
  year={2025}
}