Pure-Python path signature and log signature computation
Project description
sig-light
Pure-Python path signature and log signature computation, mirroring the iisignature API.
sig-light computes signatures and log signatures of multidimensional piecewise-linear paths using Chen's identity and truncated tensor algebra operations. No C extensions or compilation required — just numpy.
Installation
pip install sig-light
Or with uv:
uv add sig-light
Quick Start
import numpy as np
import sig_light
# Define a 2D path
path = np.array([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [0.0, 0.0]])
# Compute signature at depth 3
signature = sig_light.sig(path, 3)
# Compute log signature
s = sig_light.prepare(2, 3)
log_signature = sig_light.logsig(path, s)
# Backpropagation
deriv = np.ones_like(signature)
grad = sig_light.sigbackprop(deriv, path, 3) # gradient w.r.t. path
# Batching: process multiple paths at once
paths = np.random.randn(10, 50, 2) # 10 paths, 50 points, 2D
sigs = sig_light.sig(paths, 3) # shape (10, siglength(2, 3))
API Reference
Signature
sig(path, m, format=0)
Compute the signature of a path truncated at depth m.
- path: numpy array of shape
(..., n, d). Extra leading dims are batched. - m: truncation depth (positive integer).
- format: output format.
0: flat array of shape(..., siglength(d, m)).1: list ofmarrays, one per level.2: cumulative prefix signatures, shape(..., n-1, siglength(d, m)).
- Returns: the path signature, excluding the level-0 term (always 1).
siglength(d, m)
Length of the signature output: d + d^2 + ... + d^m.
sigcombine(sig1, sig2, d, m)
Combine two signatures via Chen's identity. Supports batching.
Backpropagation
sigbackprop(deriv, path, m)
Compute gradient of a loss w.r.t. the path, given gradient w.r.t. the signature.
- deriv: shape
(..., siglength(d, m)). - path: shape
(..., n, d). - Returns: shape
(..., n, d).
sigjacobian(path, m)
Full Jacobian matrix of sig() w.r.t. the path.
- Returns: shape
(n, d, siglength(d, m)).
logsigbackprop(deriv, path, s)
Compute gradient of a loss w.r.t. the path, given gradient w.r.t. the log signature.
- deriv: shape
(..., logsiglength(d, m)). - path: shape
(..., n, d). - s: prepared data from
prepare(d, m). - Returns: shape
(..., n, d).
Log Signature
prepare(d, m)
Precompute data for log signature computation.
logsig(path, s)
Compute the log signature in the Lyndon basis. Supports batching.
logsig_expanded(path, s)
Compute the log signature in the full tensor expansion. Supports batching.
logsiglength(d, m)
Length of the log signature output (Witt's formula).
basis(s)
Get the Lyndon bracket labels for the log signature basis elements.
Transforms
sigjoin(sig, segment, d, m, fixedLast=nan)
Extend a signature by appending a linear segment. Equivalent to sigcombine(sig, sig_of_segment(segment), d, m).
sigjoinbackprop(deriv, sig, segment, d, m, fixedLast=nan)
Gradient through sigjoin. Returns (dsig, dsegment) or (dsig, dsegment, dfixedLast).
sigscale(sig, scales, d, m)
Rescale a signature as if each path dimension were multiplied by a factor. At level k, the multi-index (i1,...,ik) component is multiplied by scales[i1] * ... * scales[ik].
sigscalebackprop(deriv, sig, scales, d, m)
Gradient through sigscale. Returns (dsig, dscales).
Rotation Invariants (2D paths)
rotinv2dprepare(m, type="a")
Precompute rotation-invariant features for 2D paths.
- m: depth (should be even).
- type:
"a"for all invariants.
rotinv2d(path, s)
Compute rotation-invariant features of a 2D path signature.
rotinv2dlength(s) / rotinv2dcoeffs(s)
Get the number of invariants and their coefficient matrices.
Utility
version()
Return the sig-light version string.
Algorithm
sig-light uses the standard approach for computing signatures of piecewise-linear paths:
-
Segment signature: for each linear segment with displacement
h, the signature is the truncated exponentialexp(h) = 1 + h + h^2/2! + h^3/3! + ...in the tensor algebra. -
Chen's identity: the signature of a concatenated path equals the tensor product of the individual segment signatures:
S(path) = S(seg_1) * S(seg_2) * ... * S(seg_n). -
Log signature: computed by taking the tensor logarithm
log(S) = (S-1) - (S-1)^2/2 + (S-1)^3/3 - ...and projecting onto the Lyndon word basis. -
Backpropagation: reverse-mode differentiation through the Chen's identity chain using adjoint operations on the tensor algebra.
This approach is exact for piecewise-linear paths (no numerical approximation from ODE solvers).
Comparison with iisignature
| Feature | sig-light | iisignature |
|---|---|---|
| Language | Pure Python + numpy | C++ with Python bindings |
| Installation | pip install (no compilation) |
Requires C++ compiler |
| Performance | Slower (~7-25x for sig) | Faster |
| API | Full parity | Full |
| Backpropagation | Yes | Yes |
| Batching | Yes | Yes |
| Rotation invariants | Yes (type "a") | Yes (types a/s/q/k) |
sig-light implements the full iisignature API with an identical interface. It trades performance for portability and simplicity.
Development
Requires just for task running.
# Clone and install
git clone https://github.com/yousif-toama/sig-light.git
cd sig-light
just sync
# Run tests
just test
# Code quality (lint + format check + type check)
just check
# Run tests with coverage
just test-cov
# Run benchmark
just bench
# Install iisignature for cross-validation testing (requires C++ compiler)
uv pip install setuptools
uv pip install iisignature --no-build-isolation
uv run pytest tests/test_api_compat.py
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sig_light-0.2.4.tar.gz.
File metadata
- Download URL: sig_light-0.2.4.tar.gz
- Upload date:
- Size: 66.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b3a932f64f84d068ec47edac2e449107a149ed77d23f9f44433e0b534cf7162
|
|
| MD5 |
a5c8058453394d892fa4772fa701244d
|
|
| BLAKE2b-256 |
affe202e799697f7a83283a5ce6f7283bf77ef364e539d40aebb7dd4f6ad3970
|
File details
Details for the file sig_light-0.2.4-py3-none-any.whl.
File metadata
- Download URL: sig_light-0.2.4-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
835159ad768894a299c2576a3d54152f37db256f6af298b0d9dfa90bf4012353
|
|
| MD5 |
771e23d15718c03846579cd12418e5d6
|
|
| BLAKE2b-256 |
d68b5afa43f65f0ceb14e545502b6aabdf5d798182cc3e2c74143d245f52edc3
|