pysiglib.sig_backprop

pysiglib.sig_backprop#

Added in version v0.2.

Warning

Where possible, pysiglib.torch_api should be used rather than explicitly calling backpropagation functions. Explicit backpropagation can introduce subtle errors if called incorrectly. In addition, some pysiglib functions can only be backpropagated through using their pysiglib.torch_api variants and do not expose explicit backpropagation functions.

sig_backprop(path, sig, sig_derivs, degree, *, time_aug=False, lead_lag=False, end_time=1.0, n_jobs=1)[source]#

This function is required to backpropagate through the signature computation. Given the derivatives of a scalar function \(F\) with respect to the signature, \(\partial F / \partial S(x)\), returns the derivatives of \(F\) with respect to the underlying path, \(\partial F / \partial x\).

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

  • sig (numpy.ndarray | torch.tensor) – Signature(s) of the path or batch of paths.

  • sig_derivs (numpy.ndarray | torch.tensor) – Derivatives of the scalar function \(F\) with respect to the signature(s), \(\partial F / \partial S(x)\). This must be an array of the same shape as the provided signature(s).

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

  • time_aug (bool) – Whether the signatures were computed with time_aug=True.

  • lead_lag (bool) – Whether the signatures were computed with lead_lag=True.

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

Derivatives of the scalar function \(F\) with respect to the path(s), \(\partial F / \partial x\). This is an array of the same shape as the provided path(s).

Return type:

numpy.ndarray | torch.tensor

Example:#

import torch
import pysiglib

path = torch.rand((10, 100, 5))
degree = 4
sigs = pysiglib.sig(path, degree)
sig_derivs = torch.ones_like(sigs)
path_derivs = pysiglib.sig_backprop(path, sigs, sig_derivs, degree)
print(path_derivs)
# Backprop with time augmentation and lead-lag
import torch
import pysiglib

path = torch.rand((10, 100, 5))
degree = 4
sigs = pysiglib.sig(path, degree, time_aug=True, lead_lag=True, end_time=2.0)
sig_derivs = torch.ones_like(sigs)
path_derivs = pysiglib.sig_backprop(
    path, sigs, sig_derivs, degree,
    time_aug=True, lead_lag=True, end_time=2.0,
)
print(path_derivs)

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