pysiglib.log_sig

Contents

pysiglib.log_sig#

Added in version v1.0.0.

log_sig(path, degree, *, time_aug=False, lead_lag=False, end_time=1.0, method=1, scalar_term=False, n_jobs=1)[source]#

Computes the log signature using the specified method. For details, see the page Computing Log Signatures.

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) – Truncation degree of the (log) signature(s).

  • time_aug (bool) – If set to True, will compute the log 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 log signature of the path after applying the lead-lag transformation.

  • end_time (float) – End time for time-augmentation, \(t_L\).

  • method (int) – Method to use for the log signature computation (0, 1, 2 or 3). Methods 0-2 first compute the full signature and then project to the log signature. Method 3 uses the Baker-Campbell-Hausdorff formula to compute the log signature directly from the path without ever computing the full signature. This uses less memory but is slower than methods 0-2 for typical dimensions and degrees.

  • 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. Only affects method 0 (expanded) output; methods 1 and 2 produce log-sig-shaped output with no scalar term.

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

Log signature or a batch of log signatures.

Return type:

numpy.ndarray | torch.tensor

Example usage:#

import torch
import pysiglib

pysiglib.prepare_log_sig(5, 3, lead_lag=True, method=2)

X = torch.rand((32,100,5))
X_log_sig = pysiglib.log_sig(X, 3, lead_lag=True, method=2)

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