Skip to content

WindowedLogSignature

from tensorsig.classical.windows import WindowedLogSignature

Bases: Module

A windowed logsignature transform for torch.nn.Sequential.

Compose arbitrary path augmentations before this module, for example nn.Sequential(fir, products, WindowedLogSignature(2, 5)). Augmentations see the full path before windows are extracted. The transform itself does not impose causality on preceding modules.

Parameters:

Name Type Description Default
depth int

Positive logsignature truncation depth.

required
window_size int

Number of path points per window (at least two).

required
hop_size int

Number of points between window starts.

1
mode (words, hall)

Logsignature coordinate basis.

"words"
Source code in src/tensorsig/classical/windows.py
def __init__(
    self,
    depth: int,
    window_size: int,
    hop_size: int = 1,
    mode: str = "words",
) -> None:
    super().__init__()
    for name, value, minimum in (
        ("depth", depth, 1),
        ("window_size", window_size, 2),
        ("hop_size", hop_size, 1),
    ):
        if not isinstance(value, int) or isinstance(value, bool) or value < minimum:
            raise ValueError(f"{name} must be an integer of at least {minimum}.")
    if not isinstance(mode, str):
        raise TypeError("mode must be a string.")
    mode = mode.lower()
    if mode not in {"words", "hall"}:
        raise ValueError("mode must be either 'words' or 'hall'.")
    self.depth = depth
    self.window_size = window_size
    self.hop_size = hop_size
    self.mode = mode

forward

forward(path: Tensor) -> Tensor

Map path points (B, L, C) to window coordinates (B, N, D).

Source code in src/tensorsig/classical/windows.py
def forward(self, path: Tensor) -> Tensor:
    """Map path points ``(B, L, C)`` to window coordinates ``(B, N, D)``."""
    return windowed_log_signature(
        path,
        depth=self.depth,
        window_size=self.window_size,
        hop_size=self.hop_size,
        mode=self.mode,
    )