Skip to content

BCH Coefficients

log_signatures_pytorch.bch_coefficients.bch_coeffs(width, depth)

Coefficients for log(prod_{i=1}^width exp(e_i)) truncated to depth.

Computes the exact rational coefficients for the Baker-Campbell-Hausdorff expansion of the product of exponentials of generators, truncated to the specified depth.

Parameters:

Name Type Description Default
width int

Number of generators (path dimension). Must be >= 1.

required
depth int

Truncation depth. Must be >= 1.

required

Returns:

Type Description
CoeffMap

Dictionary mapping tensor-algebra words (tuples of generator indices) to rational coefficients (Fraction objects) in the series expansion. Words are tuples of integers from 1 to width, representing the generators in order.

Examples:

>>> from log_signatures_pytorch.bch_coefficients import bch_coeffs
>>> from fractions import Fraction
>>>
>>> # BCH coefficients for width=2, depth=2
>>> coeffs = bch_coeffs(2, 2)
>>> # Check some expected coefficients
>>> coeffs[(1,)] == Fraction(1, 1)
True
>>> coeffs[(2,)] == Fraction(1, 1)
True
>>> # The bracket [1, 2] has coefficient 1/2, split across (1, 2) and (2, 1)
>>> coeffs.get((1, 2), 0) == Fraction(1, 2)
True
>>> coeffs.get((2, 1), 0) == Fraction(-1, 2)
True
>>> coeffs.get((1, 2), 0) - coeffs.get((2, 1), 0) == Fraction(1, 1)
True
>>>
>>> # BCH coefficients for width=3, depth=2
>>> coeffs = bch_coeffs(3, 2)
>>> # Three degree-1 generators
>>> len([w for w in coeffs.keys() if len(w) == 1])
3
Source code in src/log_signatures_pytorch/bch_coefficients.py
def bch_coeffs(width: int, depth: int) -> CoeffMap:
    """Coefficients for log(prod_{i=1}^width exp(e_i)) truncated to `depth`.

    Computes the exact rational coefficients for the Baker-Campbell-Hausdorff
    expansion of the product of exponentials of generators, truncated to the
    specified depth.

    Parameters
    ----------
    width : int
        Number of generators (path dimension). Must be >= 1.
    depth : int
        Truncation depth. Must be >= 1.

    Returns
    -------
    CoeffMap
        Dictionary mapping tensor-algebra words (tuples of generator indices)
        to rational coefficients (Fraction objects) in the series expansion.
        Words are tuples of integers from 1 to width, representing the
        generators in order.

    Examples
    --------
    >>> from log_signatures_pytorch.bch_coefficients import bch_coeffs
    >>> from fractions import Fraction
    >>>
    >>> # BCH coefficients for width=2, depth=2
    >>> coeffs = bch_coeffs(2, 2)
    >>> # Check some expected coefficients
    >>> coeffs[(1,)] == Fraction(1, 1)
    True
    >>> coeffs[(2,)] == Fraction(1, 1)
    True
    >>> # The bracket [1, 2] has coefficient 1/2, split across (1, 2) and (2, 1)
    >>> coeffs.get((1, 2), 0) == Fraction(1, 2)
    True
    >>> coeffs.get((2, 1), 0) == Fraction(-1, 2)
    True
    >>> coeffs.get((1, 2), 0) - coeffs.get((2, 1), 0) == Fraction(1, 1)
    True
    >>>
    >>> # BCH coefficients for width=3, depth=2
    >>> coeffs = bch_coeffs(3, 2)
    >>> # Three degree-1 generators
    >>> len([w for w in coeffs.keys() if len(w) == 1])
    3
    """
    if depth < 1 or width < 1:
        return {}
    # Multiply exp of each generator in order
    prod: CoeffMap = {(): Fraction(1)}
    for letter in range(1, width + 1):
        prod = _mul_series(prod, _exp_single(letter, depth), depth)
    log_series = _log_series(prod, depth)
    return {w: c for w, c in log_series.items() if len(w) <= depth and c != 0}