Skip to content

PairwiseProductAugmentation

from tensorsig.augmentations import PairwiseProductAugmentation

Bases: Module

Append all distinct pairwise channel products to a path.

Parameters:

Name Type Description Default
in_channels int

Input path width.

required
include_inputs bool

Whether the input channels precede the product channels in the output.

True
Source code in src/tensorsig/augmentations/__init__.py
def __init__(self, in_channels: int, *, include_inputs: bool = True) -> None:
    super().__init__()
    self.in_channels = _validate_integer("in_channels", in_channels, minimum=1)
    if not isinstance(include_inputs, bool):
        raise TypeError("include_inputs must be a bool.")
    self.include_inputs = include_inputs
    products = self.in_channels * (self.in_channels - 1) // 2
    self.out_channels = products + (self.in_channels if include_inputs else 0)

forward

forward(path: Tensor) -> Tensor

Return distinct products, optionally preceded by the input channels.

Source code in src/tensorsig/augmentations/__init__.py
def forward(self, path: Tensor) -> Tensor:
    """Return distinct products, optionally preceded by the input channels."""
    _validate_sequence(path, in_channels=self.in_channels)
    first, second = torch.triu_indices(
        self.in_channels,
        self.in_channels,
        offset=1,
        device=path.device,
    )
    products = path[..., first] * path[..., second]
    return torch.cat((path, products), dim=-1) if self.include_inputs else products