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, correction=None, 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.

  • correction (numpy.ndarray | torch.tensor | None) – Optional per-segment correction of level \(\geq 2\) added locally before exponentiating each path segment. See sig() for the accepted constant, shared per-segment, and batch-specific layouts. For non-Lie correction such as Ito level-2 diagonal terms, use method=0 to retain the full tensor logarithm. Cannot be combined with lead_lag=True.

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

Ito-lifted log signature of a sampled Brownian path. For Brownian motion with instantaneous covariance \(\Sigma\), setting the level-2 correction to \(c^{(2)}_{ij} = \Sigma_{ij}\,\Delta t\) per segment gives the Ito correction. The Ito level-2 term is not Lie-valued (its symmetric part is not in the free Lie algebra), so method=0 is used to retain the full tensor logarithm.

import numpy as np
import pysiglib

d, N, T = 2, 3, 1.0
n_steps = 100
dt = T / n_steps
rng = np.random.default_rng(42)

# 2D standard Brownian motion sample (Sigma = I)
path = np.zeros((n_steps + 1, d))
path[1:] = np.cumsum(rng.normal(0, np.sqrt(dt), (n_steps, d)), axis=0)

# Ito level-2 correction: one dt * Sigma row per path segment.
correction = np.broadcast_to((np.eye(d) * dt).reshape(1, -1), (n_steps, d * d))

ito_log_sig = pysiglib.log_sig(
    path, N, correction=correction, end_time=T, method=0)
print(ito_log_sig)

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