pathsig.Signature#

class pathsig.Signature(depth, projection=None, windows=None)#

Computes the signature of a path.

Parameters:
  • depth (int) – Truncation level.

  • projection (object | None) – (optional) Projection controlling which signature coordinates are computed and returned. See pathsig.projections for supported types.

  • windows (torch.Tensor | None) – (optional) Integer tensor of shape \((W,2)\) specifying windows \([start,end)\).

forward(x)#
Parameters:

x (torch.Tensor) – CUDA tensor of shape \((B,T,d)\) with dtype float32 or float64.

Returns:

Tensor of shape \((B,D)\) if windows is None, and \((B,W,D)\) otherwise.

Return type:

torch.Tensor

Here \(B\) is the batch size, \(T\) the sequence length, \(d\) the path dimension, \(W\) the number of windows, and \(D\) the output dimension. If no projection is provided then \(D=\sum_{k=1}^{\mathrm{depth}} d^k\). With a projection, \(D=\texttt{projection.sig\_size}\).

Notes

Autograd is supported for float32 and float64 in both windowed and non-windowed modes, with or without a projection.

Examples

import torch
import pathsig

x = torch.randn(32, 128, 8, device="cuda", dtype=torch.float32)

# Truncated signature
sig = pathsig.Signature(depth=4)
y = sig(x)  # (B, D)

# Windowed signature
windows = torch.tensor([[0, 32], [32, 64]], device="cuda") # (W, 2)
sig = pathsig.Signature(depth=4, windows=windows)
y = sig(x)  # (B, W, D)

# Signature with a word projection
proj = pathsig.projections.words(
   words=[(0, 1), (2, 2, 3)],
   depth=4,
   path_dim=8,
   full_levels=(1,),
)
sig = pathsig.Signature(depth=4, projection=proj)
y = sig(x)  # (B, proj.sig_size)