Skip to content

CausalFIRAugmentation

from tensorsig.augmentations import CausalFIRAugmentation

Bases: Module

Append learned causal FIR channels to a path.

Each learned filter mixes all input channels and lags from zero through max_lag. The output is concat(path, filtered_path) and therefore has in_channels + num_filters channels.

A filter bias translates its output channel. Signatures and logsignatures directly following this augmentation are translation invariant, so the bias only affects them when an intervening nonlinear augmentation, such as pairwise products, converts absolute levels into increments.

Parameters:

Name Type Description Default
in_channels int

Input path width.

required
num_filters int

Number of learned FIR channels to append.

required
max_lag int

Largest causal lag included by each filter.

required
bias bool

Whether the learned FIR channels have additive biases.

True
padding ('repeat', 'zero')

Left-boundary values before the first path point.

"repeat"
init ('uniform', 'normal', 'zeros')

FIR weight initialization.

"uniform"
Source code in src/tensorsig/augmentations/__init__.py
def __init__(
    self,
    in_channels: int,
    num_filters: int,
    max_lag: int,
    *,
    bias: bool = True,
    padding: str = "repeat",
    init: str = "uniform",
) -> None:
    super().__init__()
    self.in_channels = _validate_integer("in_channels", in_channels, minimum=1)
    self.num_filters = _validate_integer("num_filters", num_filters, minimum=1)
    self.max_lag = _validate_integer("max_lag", max_lag, minimum=0)
    if not isinstance(bias, bool):
        raise TypeError("bias must be a bool.")
    self.padding = _normalize_padding(padding)
    self.init = _normalize_init(init)
    self.out_channels = self.in_channels + self.num_filters

    self.weight = torch.nn.Parameter(
        torch.empty(self.num_filters, self.in_channels, self.max_lag + 1)
    )
    if bias:
        self.bias = torch.nn.Parameter(torch.empty(self.num_filters))
    else:
        self.register_parameter("bias", None)
    self.reset_parameters()

reset_parameters

reset_parameters() -> None

Initialize the filters and optional bias.

Source code in src/tensorsig/augmentations/__init__.py
def reset_parameters(self) -> None:
    """Initialize the filters and optional bias."""
    fan_in = self.in_channels * (self.max_lag + 1)
    if self.init == "zeros":
        torch.nn.init.zeros_(self.weight)
    elif self.init == "normal":
        torch.nn.init.normal_(self.weight, mean=0.0, std=fan_in**-0.5)
    else:
        bound = fan_in**-0.5
        torch.nn.init.uniform_(self.weight, -bound, bound)

    if self.bias is not None:
        bound = fan_in**-0.5
        torch.nn.init.uniform_(self.bias, -bound, bound)

filtered

filtered(path: Tensor) -> Tensor

Return only the learned FIR channels.

Source code in src/tensorsig/augmentations/__init__.py
def filtered(self, path: Tensor) -> Tensor:
    """Return only the learned FIR channels."""
    _validate_sequence(path, in_channels=self.in_channels)
    if path.device != self.weight.device or path.dtype != self.weight.dtype:
        raise RuntimeError(
            "path dtype/device must match the augmentation parameters; move "
            "the module and input explicitly"
        )
    return causal_fir(path, self.weight, self.bias, padding=self.padding)

forward

forward(path: Tensor) -> Tensor

Return the input path followed by its learned FIR channels.

Source code in src/tensorsig/augmentations/__init__.py
def forward(self, path: Tensor) -> Tensor:
    """Return the input path followed by its learned FIR channels."""
    return torch.cat((path, self.filtered(path)), dim=-1)