pysiglib.sig_coef#
Added in version v1.1.0.
- sig_coef(path, words, *, time_aug=False, lead_lag=False, end_time=1.0, prefixes=False, n_jobs=1)[source]#
Computes specific signature coefficients for a single path or a batch of paths. For a single path \(x\), the signature coefficient at a multi-index \(I = (i_1, i_2, \ldots, i_k)\) is given by
\[S(x)^I_{[s,t]} := \int_{s < t_1 < \cdots < t_k < t} dx^{i_1}_{t_1} \otimes dx^{i_2}_{t_2} \otimes \cdots \otimes dx^{i_k}_{t_k}.\]- 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\) at which to evaluate signature coefficients, given as a list of lists of integers in \([0, d-1]\), where \(d\) is the dimension of the path(s). For example, for a 2-dimensional path, one could pass
[(0,), (1,0), (0,1,1)]to compute the coefficients at the three multi-indices \(I = (0), (1,0), (0,1,1)\).time_aug (bool) – If set to True, will compute signature coefficients 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 signature coefficients of the path after applying the lead-lag transformation.
end_time (float) – End time for time-augmentation, \(t_L\).
prefixes (bool) – If
True, will additionally return all prefixes of signature coefficients. These prefixes are extracted for free as a by-product of the computation. For example, passingword=[(1,2), (3,2,1)]withprefixes=Truereturns an output equivalent to passingword=[(1,), (1,2), (3,), (3,2), (3,2,1)]withprefixes=False.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:
Signature coefficients of shape
(..., num_words), matching the leading batch dimensions ofpath.- Return type:
numpy.ndarray | torch.tensor
Note
If the number of requested coefficients is large relative to the size of the full truncated signature, it is usually faster to call
pysiglib.signatureand extract the required coefficients usingpysiglib.extract_sig_coefs. This function is only faster when a very sparse collection of coefficients is required.Example:#
import torch import pysiglib path = torch.rand((10, 100, 5)) words = [(0,), (1,0), (1,2,3)] coefs = pysiglib.sig_coef(path, words)
# Using prefixes to return all prefix coefficients import torch import pysiglib path = torch.rand((10, 100, 5)) words = [(4, 3), (1, 2, 3)] coefs = pysiglib.sig_coef(path, words, prefixes=True) # Returns coefficients for (4,), (4,3), (1,), (1,2), and (1,2,3) print(coefs)
# Computing specific coefficients with time_aug and lead_lag import torch import pysiglib path = torch.rand((10, 100, 5)) # With lead_lag the dimension doubles (10), and time_aug adds one (11). # Words now index into the augmented dimension. words = [(6,), (10, 9)] coefs = pysiglib.sig_coef(path, words, lead_lag=True, time_aug=True, end_time=2.0) print(coefs)
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}
}