pysiglib.sig

Contents

pysiglib.sig#

sig(path, degree, *, time_aug=False, lead_lag=False, end_time=1.0, horner=True, scalar_term=False, n_jobs=1)[source]#

Computes the truncated signature of single path or a batch of paths. For a single path \(x\), the signature is given by

\[S(x)_{[s,t]} := \left( 1, S(x)^{(1)}_{[s,t]}, \ldots, S(x)^{(N)}_{[s,t]}\right) \in T((\mathbb{R}^d)),\]
\[S(x)^{(k)}_{[s,t]} := \int_{s < t_1 < \cdots < t_k < t} dx_{t_1} \otimes dx_{t_2} \otimes \cdots \otimes dx_{t_k} \in \left(\mathbb{R}^d\right)^{\otimes k}.\]
Parameters:
  • path (numpy.ndarray | torch.tensor) – The underlying path or batch of paths, given as a numpy.ndarray or torch.tensor. For a single path, this must be of shape (length, dimension). For a batch of paths, this must be of shape (batch_size, length, dimension).

  • degree (int) – The truncation level of the signature, \(N\).

  • time_aug (bool) – If set to True, will compute the signature of the time-augmented path, \(\hat{x}_t := (t, x_t)\), defined as the original path with an extra channel set to time, \(t\). This channel spans \([0, t_L]\), where \(t_L\) is given by the parameter end_time.

  • lead_lag (bool) – If set to True, will compute the signature of the path after applying the lead-lag transformation.

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

  • horner (bool) – If True, will use Horner’s algorithm for polynomial multiplication.

  • scalar_term (bool) – If True, the output includes the leading constant 1 at index 0 (the empty-word term). If False (default), this leading element is stripped from the output.

  • 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:

Truncated signature, or a batch of truncated signatures.

Return type:

numpy.ndarray | torch.tensor

Note

pysiglib.signature is an alias of pysiglib.sig included for backward compatibility with versions < 1.0.0.

Example:#

import torch
import pysiglib

path = torch.rand((10, 100, 5))
sigs = pysiglib.sig(path, degree=4)
print(sigs)
# Using time augmentation, lead-lag, and parallel threads
import torch
import pysiglib

path = torch.rand((10, 100, 5))
sigs = pysiglib.sig(
    path,
    degree=4,
    time_aug=True,
    lead_lag=True,
    end_time=2.0,
    n_jobs=-1,
)
print(sigs)

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}
}