pysiglib.sig

Contents

pysiglib.sig#

sig(path, degree, *, time_aug=False, lead_lag=False, end_time=1.0, horner=True, scalar_term=False, correction=None, 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.

  • correction (numpy.ndarray | torch.tensor | None) –

    Optional per-segment correction of level \(\geq 2\) added to each path increment before exponentiation. The level-1 part of the local lift is the segment’s path increment \(\Delta x\), the higher levels come from the corresponding correction row, and the local signature on each segment is

    \[\exp \left( \sum_i \Delta x_i\, e_i + \sum_{k=2}^{m} \sum_{i_1, \ldots, i_k} c^{(k)}_{i_1 \ldots i_k}\, e_{i_1} \otimes \cdots \otimes e_{i_k} \right),\]

    where \((e_{i_1} \otimes \cdots \otimes e_{i_k})\) is the tensor basis. A non-empty correction may have shape (C,) for one constant correction shared by every segment and batch item, (path.shape[-2] - 1, C) for one correction row per segment shared by the batch, or path.shape[:-2] + (path.shape[-2] - 1, C) for batch-specific segment corrections. Here C is the correction width, with \(C = d^2 + d^3 + \cdots + d^m\), where \(d\) is the original path dimension and \(2 \leq m \leq N\) is the highest correction level supplied (missing higher levels are zero). Levels are concatenated in each row, and within level \(k\) the entry for index tuple \((i_1, \ldots, i_k)\) lives at flat index \(i_1 d^{k-1} + i_2 d^{k-2} + \cdots + i_k\). Passing None or an empty array is equivalent to all-zero correction. With time_aug=True, the appended time channel contributes no correction entries. Cannot be combined with lead_lag=True.

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

Ito-lifted signature of a sampled Brownian path. For Brownian motion with instantaneous covariance \(\Sigma\), setting the level-2 correction to \(c^{(2)}_{ij} = \Sigma_{ij}\,\Delta t\) per segment gives the Ito correction.

import numpy as np
import pysiglib

d, N, T = 2, 3, 1.0
n_steps = 100
dt = T / n_steps
rng = np.random.default_rng(42)

# 2D standard Brownian motion sample (Sigma = I)
path = np.zeros((n_steps + 1, d))
path[1:] = np.cumsum(rng.normal(0, np.sqrt(dt), (n_steps, d)), axis=0)

# Ito level-2 correction: one dt * Sigma row per path segment.
correction = np.broadcast_to((np.eye(d) * dt).reshape(1, -1), (n_steps, d * d))

ito_sig = pysiglib.sig(path, N, correction=correction, end_time=T)
print(ito_sig)

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