kaira.channels.LambdaChannel

Inheritance diagram of LambdaChannel

Inheritance diagram for LambdaChannel

class kaira.channels.LambdaChannel(fn: Callable, *args: Any, **kwargs: Any)[source]

Bases: BaseChannel

Customizable channel that applies user-defined functions to signals.

This channel provides a flexible way to implement custom channel behavior by wrapping any arbitrary function. It can be used to model specific distortions, transformations, or to combine multiple channel effects into a single model.

Mathematical Model:

y = f(x) where f is any user-defined function

Parameters:

fn (callable) – The function to apply to the input signal. Must accept a torch.Tensor and return a torch.Tensor of compatible shape.

Example

>>> # Create a custom channel that doubles the amplitude
>>> amplifier = LambdaChannel(lambda x: 2 * x)
>>> x = torch.ones(10)
>>> y = amplifier(x)  # y will contain all 2's
>>> # Create a channel that adds specific frequency distortion
>>> def distort(x):
...     return x + 0.1 * torch.sin(2 * math.pi * 0.05 * torch.arange(len(x)))
>>> channel = LambdaChannel(distort)

Methods

__init__

Initialize the Lambda channel.

forward

Apply the custom function to the input signal.

get_config

Get a dictionary of the channel's configuration.

__init__(fn: Callable, *args: Any, **kwargs: Any)[source]

Initialize the Lambda channel.

Parameters:
  • fn (callable) – The function to apply to the input signal.

  • *args – Variable length argument list passed to the base class.

  • **kwargs – Arbitrary keyword arguments passed to the base class.

forward(x: Tensor, *args: Any, **kwargs: Any) Tensor[source]

Apply the custom function to the input signal.

Parameters:
  • x (torch.Tensor) – The input tensor.

  • *args – Additional positional arguments passed to the custom function.

  • **kwargs – Additional keyword arguments passed to the custom function.

Returns:

The output tensor after applying the custom function.

Return type:

torch.Tensor

get_config() Dict[str, Any]

Get a dictionary of the channel’s configuration.

This method returns a dictionary containing the channel’s parameters, which can be used to recreate the channel instance.

Returns:

Dictionary of parameter names and values

Return type:

Dict[str, Any]