pysiglib.sig_coef_backprop#
Added in version v1.1.0.
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_coef_backprop(path, words, coefs, derivs, *, time_aug=False, lead_lag=False, end_time=1.0, n_jobs=1)[source]#
This function is required to backpropagate through signature coefficient computation. Given the derivatives of a scalar function \(F\) with respect to the signature coefficients, \(\partial F / \partial S(x)^I\), returns the derivatives of \(F\) with respect to the underlying path, \(\partial F / \partial x\). Note that
coefsmust be generated usingpysiglib.sig_coefusingprefixes=True, andderivsmust be the derivatives with respect to this extended array.- Parameters:
path (numpy.ndarray | torch.tensor) – The underlying path or batch of paths, of shape
(..., length, dimension).words (tuple[int, ...] | list[tuple[int, ...]]) – Multi-indices \(I\) indexing the signature coefficients, given as a list of lists of integers in \([0, d-1]\), where \(d\) is the dimension of the path(s).
coefs (numpy.ndarray | torch.tensor) – Signature coefficients of the path or batch of paths, generated using
pysiglib.sig_coefusingprefixes=True.derivs (numpy.ndarray | torch.tensor) – Derivatives of the scalar function \(F\) with respect to the signature coefficients, \(\partial F / \partial S(x)^I\). This must be an array of the same shape as the provided coefficients. On CPU, this buffer is modified in-place.
time_aug (bool) – Whether the signature coefficients were computed with
time_aug=True.lead_lag (bool) – Whether the signature coefficients 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)) words = [(0,), (1, 0), (1, 2, 3)] # Must generate coefs with prefixes=True for backprop coefs = pysiglib.sig_coef(path, words, prefixes=True) derivs = torch.ones_like(coefs) path_derivs = pysiglib.sig_coef_backprop(path, words, coefs, derivs) print(path_derivs)
# Backprop with time augmentation and lead-lag import torch import pysiglib path = torch.rand((10, 100, 5)) words = [(0,), (1, 2)] # Must generate coefs with prefixes=True for backprop coefs = pysiglib.sig_coef(path, words, time_aug=True, lead_lag=True, prefixes=True) derivs = torch.ones_like(coefs) path_derivs = pysiglib.sig_coef_backprop( path, words, coefs, derivs, time_aug=True, lead_lag=True, ) 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}
}