Skip to content

Basis Functions

Hall basis (classical)

log_signatures_pytorch.hall_projection.hall_basis(width, depth)

Return Hall basis elements up to depth over an alphabet of size width.

The Hall basis is a particular basis for the free Lie algebra. Elements are ordered first by depth, then lexicographically by the recursive Hall ordering. Degree-1 elements are labeled 1..width and higher degrees are nested tuples representing Lie brackets.

Parameters:

Name Type Description Default
width int

Size of the alphabet (path dimension). Must be >= 1.

required
depth int

Maximum depth to generate basis elements. Must be >= 1.

required

Returns:

Type Description
List[HallBasisElement]

Hall basis elements, where each element is either an integer (degree 1) or a nested tuple representing a Lie bracket (higher degrees).

Raises:

Type Description
ValueError

If width < 1 or depth < 1.

Source code in src/log_signatures_pytorch/hall_projection.py
def hall_basis(width: int, depth: int) -> List[HallBasisElement]:
    """Return Hall basis elements up to ``depth`` over an alphabet of size ``width``.

    The Hall basis is a particular basis for the free Lie algebra. Elements are
    ordered first by depth, then lexicographically by the recursive Hall ordering.
    Degree-1 elements are labeled 1..width and higher degrees are nested tuples
    representing Lie brackets.

    Parameters
    ----------
    width : int
        Size of the alphabet (path dimension). Must be >= 1.
    depth : int
        Maximum depth to generate basis elements. Must be >= 1.

    Returns
    -------
    List[HallBasisElement]
        Hall basis elements, where each element is either an integer (degree 1)
        or a nested tuple representing a Lie bracket (higher degrees).

    Raises
    ------
    ValueError
        If ``width < 1`` or ``depth < 1``.
    """
    if width < 1:
        raise ValueError("width must be >= 1")
    if depth < 1:
        raise ValueError("depth must be >= 1")

    depth_groups: Dict[int, List[HallBasisElement]] = {}
    letters = list(range(1, width + 1))
    depth_groups[1] = letters
    basis: List[HallBasisElement] = list(letters)

    for current_depth in range(2, depth + 1):
        candidates: List[HallBasisElement] = []
        for left_depth in range(1, current_depth):
            right_depth = current_depth - left_depth
            for left in depth_groups[left_depth]:
                for right in depth_groups[right_depth]:
                    if _hall_is_valid_pair(left, right):
                        candidates.append((left, right))
        candidates.sort(key=_hall_basis_key)
        depth_groups[current_depth] = candidates
        basis.extend(candidates)

    return basis

log_signatures_pytorch.hall_projection.logsigdim(width, depth)

Dimension of the truncated log-signature in the Hall basis.

Source code in src/log_signatures_pytorch/hall_projection.py
def logsigdim(width: int, depth: int) -> int:
    """Dimension of the truncated log-signature in the Hall basis."""

    return len(hall_basis(width, depth))

log_signatures_pytorch.hall_projection.logsigkeys(width, depth)

Human-readable labels for Hall basis elements (esig-compatible).

Source code in src/log_signatures_pytorch/hall_projection.py
def logsigkeys(width: int, depth: int) -> List[str]:
    """Human-readable labels for Hall basis elements (esig-compatible)."""

    def _to_str(elem: HallBasisElement) -> str:
        if isinstance(elem, int):
            return str(elem)
        left, right = elem
        return f"[{_to_str(left)},{_to_str(right)}]"

    return [_to_str(elem) for elem in hall_basis(width, depth)]

Lyndon “words” basis (default for log_signature)

log_signatures_pytorch.lyndon_words.lyndon_words(width, depth) cached

Lyndon words up to depth in Signatory-compatible ordering.

Source code in src/log_signatures_pytorch/lyndon_words.py
@lru_cache(maxsize=None)
def lyndon_words(width: int, depth: int) -> Tuple[WordsBasisElement, ...]:
    """Lyndon words up to ``depth`` in Signatory-compatible ordering."""
    if width < 1:
        raise ValueError("width must be >= 1")
    if depth < 1:
        raise ValueError("depth must be >= 1")

    words: List[WordsBasisElement] = []
    for length in range(1, depth + 1):
        words.extend(_lyndon_fixed_length(width, length))
    return tuple(words)

log_signatures_pytorch.lyndon_words.logsigdim_words(width, depth)

Dimension of the truncated log-signature in the Lyndon "words" basis.

Source code in src/log_signatures_pytorch/lyndon_words.py
def logsigdim_words(width: int, depth: int) -> int:
    """Dimension of the truncated log-signature in the Lyndon \"words\" basis."""
    return len(lyndon_words(width, depth))

log_signatures_pytorch.lyndon_words.logsigkeys_words(width, depth)

Human-readable labels for the Lyndon "words" basis (Signatory style).

Source code in src/log_signatures_pytorch/lyndon_words.py
def logsigkeys_words(width: int, depth: int) -> List[str]:
    """Human-readable labels for the Lyndon \"words\" basis (Signatory style)."""

    def _to_str(word: WordsBasisElement) -> str:
        return ",".join(str(x) for x in word)

    return [_to_str(word) for word in lyndon_words(width, depth)]