pysiglib.sig_kernel_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_kernel_backprop(derivs, path1, path2, dyadic_order, *, static_kernel=None, time_aug=False, lead_lag=False, end_time=1.0, left_deriv=True, right_deriv=False, k_grid=None, n_jobs=1, return_grid=False)[source]#
This function is required to backpropagate through
pysiglib.sig_kernel. Given the derivatives of a scalar function \(F\) with respect to a signature kernel, \(\partial F / \left< S(x), S(y) \right>\), returns the derivatives of \(F\) with respect to one or both of the underlying paths, \(\{\partial F / x_{t_i}\}_{i=0}^{L_1}\) and \(\{\partial F / y_{t_i}\}_{i=0}^{L_2}\).- Parameters:
derivs (numpy.ndarray | torch.tensor) – Derivatives with respect to a signature kernel or batch of signature kernels, \(\partial F / \left< S(x), S(y) \right>\). If
return_grid=False, this should be of shape(...)matching the leading batch dimensions of the paths. Ifreturn_grid=True, this should have the same shape as the PDE grid returned bypysiglib.sig_kernel(..., return_grid=True).path1 (numpy.ndarray | torch.tensor) – The first underlying path or batch of paths, of shape
(..., length_1, dimension).path2 (numpy.ndarray | torch.tensor) – The second underlying path or batch of paths, of shape
(..., length_2, dimension). Leading batch dimensions must match those ofpath1.dyadic_order (int | tuple) – The dyadic order(s) used to compute the signature kernels.
static_kernel (None | pysiglib.StaticKernel) – Static kernel. If
None(default), the linear kernel will be used. For details, see the documentation on static kernels.time_aug (bool) – Whether the signature kernels were computed with
time_aug=True.lead_lag (bool) – Whether the signature kernels were computed with
lead_lag=True.end_time (float) – End time for time-augmentation, \(t_L\).
left_deriv (bool) – If
True, returns \(\{\partial F / x_{t_i}\}_{i=0}^{L_1}\). At least one ofleft_derivandright_derivmust beTrue. If both areTrue, returns both derivatives as a tuple.right_deriv (bool) – If
True, returns \(\{\partial F / y_{t_i}\}_{i=0}^{L_2}\). At least one ofleft_derivandright_derivmust beTrue. If both areTrue, returns both derivatives as a tuple.k_grid (numpy.ndarray | torch.tensor) – Signature kernel PDE grid. If
None, the grid will be recomputed.n_jobs (int) – (Only applicable to CPU computation) 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.
return_grid (bool) – If
True, backpropagates derivatives with respect to the entire PDE grid.
- Returns:
Tuple of derivatives of \(F\) with respect to one or both of the underlying paths. If
left_derivisTrue, the first element of this tuple is \(\{\partial F / x_{t_i}\}_{i=0}^{L_1}\), otherwise it isNone. Similarly forright_derivand \(\{\partial F / y_{t_i}\}_{i=0}^{L_2}\).- Return type:
numpy.ndarray | torch.tensor | Tuple[numpy.ndarray | numpy.ndarray] | Tuple[torch.tensor | torch.tensor]
Example:#
import torch import pysiglib path1 = torch.rand((10, 100, 5)) path2 = torch.rand((10, 100, 5)) k = pysiglib.sig_kernel(path1, path2, dyadic_order=2) derivs = torch.ones_like(k) dpath1, _ = pysiglib.sig_kernel_backprop(derivs, path1, path2, dyadic_order=2) print(dpath1)
# Backprop with a static kernel and time augmentation import torch import pysiglib path1 = torch.rand((10, 100, 5)) path2 = torch.rand((10, 100, 5)) rbf = pysiglib.RBFKernel(sigma=1.0) k = pysiglib.sig_kernel( path1, path2, dyadic_order=2, static_kernel=rbf, time_aug=True, ) derivs = torch.ones_like(k) dpath1, _ = pysiglib.sig_kernel_backprop( derivs, path1, path2, dyadic_order=2, static_kernel=rbf, time_aug=True, ) print(dpath1)
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}
}