pysiglib.branched_sig_backprop

pysiglib.branched_sig_backprop#

branched_sig_backprop(path, bsig, bsig_derivs, degree, *, time_aug=False, lead_lag=False, end_time=1.0, planar=False, correction=None, n_jobs=1)[source]#

Backpropagates through the branched signature computation.

Given the forward branched signature bsig = branched_sig(path, degree, correction=correction) and upstream derivatives bsig_derivs = dF/d(bsig), computes dF/d(path).

Parameters:
  • path (numpy.ndarray | torch.tensor) – Input path, shape (length, dimension) or (batch, length, dimension).

  • bsig (numpy.ndarray | torch.tensor) – Forward branched signature output.

  • bsig_derivs (numpy.ndarray | torch.tensor) – Upstream derivatives w.r.t. the branched signature.

  • degree (int) – Maximum order (must match forward call).

  • time_aug (bool) – Whether time augmentation was used in the forward pass.

  • lead_lag (bool) – Whether lead-lag was used in the forward pass.

  • end_time (float) – End time for time augmentation.

  • planar (bool) – If True, backpropagate through planar branched signature.

  • correction (numpy.ndarray | torch.tensor | None) – The same correction supplied to the forward call (see branched_sig() for layout and semantics). Treated as a constant: no derivatives are returned with respect to correction. Cannot be combined with lead_lag=True.

  • n_jobs (int) – Number of parallel threads for batch processing.

Returns:

Path derivatives, same shape as path.

Example usage:#

Forward and backward pass through the Ito-lifted branched signature of a sampled Brownian path. The same correction array must be passed to both calls.

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)).copy()

pysiglib.prepare_branched_sig(d, N)
bsig = pysiglib.branched_sig(
    path, N, correction=correction, end_time=T)
bsig_derivs = np.ones_like(bsig)
grad = pysiglib.branched_sig_backprop(
    path, bsig, bsig_derivs, N, correction=correction, end_time=T)
print(grad.shape)

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