kaira.channels.LambdaChannel

Inheritance diagram for LambdaChannel
- class kaira.channels.LambdaChannel(fn: Callable, *args: Any, **kwargs: Any)[source]
Bases:
BaseChannelCustomizable 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
Initialize the Lambda channel.
Apply the custom function to the input signal.
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: