Skip to content

windowed_signature

from tensorsig.classical.windows import windowed_signature

Sliding-window signatures using Chen's identity.

Each window signature is computed from streaming prefix signatures: Sig(path[s:e]) = Sig(path[:s])^{-1} ⊗ Sig(path[:e]) where e = s + window_size - 1.

Parameters:

Name Type Description Default
path Tensor

Tensor of shape (batch, length, dim) representing batched paths.

required
depth int

Maximum depth to truncate signature computation.

required
window_size int

Number of path points per window.

required
hop_size int

Step between consecutive window starts (>=1).

required

Returns:

Type Description
Tensor

Tensor of shape (batch, num_windows, dim + dim² + ... + dim^depth), where num_windows = 1 + (length - window_size) // hop_size, containing the signature of each window, flattened level-wise.

Raises:

Type Description
ValueError

If path is not three-dimensional or if windowing parameters are invalid.

Notes
  • Implements the Signatory-style streaming reuse (Chen) without materializing every window explicitly.
  • Provides the building block for windowed_log_signature; both share identical window indexing and batching semantics.
Source code in src/tensorsig/classical/signature.py
def windowed_signature(
    path: Tensor,
    depth: int,
    window_size: int,
    hop_size: int,
) -> Tensor:
    """Sliding-window signatures using Chen's identity.

    Each window signature is computed from streaming prefix signatures:
    ``Sig(path[s:e]) = Sig(path[:s])^{-1} ⊗ Sig(path[:e])`` where ``e = s + window_size - 1``.

    Parameters
    ----------
    path : Tensor
        Tensor of shape ``(batch, length, dim)`` representing batched paths.
    depth : int
        Maximum depth to truncate signature computation.
    window_size : int
        Number of path points per window.
    hop_size : int
        Step between consecutive window starts (``>=1``).

    Returns
    -------
    Tensor
        Tensor of shape ``(batch, num_windows, dim + dim² + ... + dim^depth)``,
        where ``num_windows = 1 + (length - window_size) // hop_size``,
        containing the signature of each window, flattened level-wise.

    Raises
    ------
    ValueError
        If ``path`` is not three-dimensional or if windowing parameters are invalid.

    Notes
    -----
    - Implements the Signatory-style streaming reuse (Chen) without materializing
      every window explicitly.
    - Provides the building block for
      [`windowed_log_signature`][tensorsig.classical.windows.windowed_log_signature];
      both share identical window indexing and batching semantics.
    """
    if path.ndim != 3:
        msg = (
            f"Path must be of shape (batch, path_length, path_dim); got {path.shape}. "
            "Wrap a single path with path.unsqueeze(0)."
        )
        raise ValueError(msg)

    batch_size, seq_len, width = path.shape

    if window_size < 2:
        raise ValueError("window_size must be at least 2 to form non-empty increments.")
    if hop_size < 1:
        raise ValueError("hop_size must be positive.")
    if seq_len < window_size:
        raise ValueError("window_size cannot exceed the path length.")

    stream = signature(path, depth=depth, stream=True)

    return stream_to_window_signatures(stream, depth, window_size, hop_size)