kaira.models.binary.soft_bit_thresholding.DynamicThresholder

Inheritance diagram for DynamicThresholder
- class kaira.models.binary.soft_bit_thresholding.DynamicThresholder(decay: float = 0.9, initial_threshold: float = 0.5, input_type: InputType = InputType.PROBABILITY, adaptation_method: str = 'mean', bias: float = 0.0, min_threshold: float = 0.1, max_threshold: float = 0.9, *args: Any, **kwargs: Any)[source]
Bases:
SoftBitThresholderThresholder with dynamically adjusting threshold for non-stationary signals.
This thresholder adapts to changing signal conditions over time using exponential moving averages. It’s particularly useful for systems with time-varying noise or signal characteristics.
The dynamic threshold is computed as a weighted average of past input statistics and can adapt to gradual changes in the signal distribution.
Example
With decay=0.9, initial_threshold=0.5: The threshold will gradually adapt to the mean of the input signal.
Methods
Initialize the dynamic thresholder.
Apply dynamic thresholding to convert soft bit values to hard decisions.
Create model instance from configuration.
Create model from Hydra DictConfig.
Create model from Hugging Face PretrainedConfig.
Reset the running statistics.
Move the model to the specified device.
- __init__(decay: float = 0.9, initial_threshold: float = 0.5, input_type: InputType = InputType.PROBABILITY, adaptation_method: str = 'mean', bias: float = 0.0, min_threshold: float = 0.1, max_threshold: float = 0.9, *args: Any, **kwargs: Any)[source]
Initialize the dynamic thresholder.
- Parameters:
decay – Exponential decay factor (0-1) controlling adaptation speed. Higher values make adaptation slower but more stable.
initial_threshold – Starting threshold value.
input_type – Type of input values (‘prob’ or ‘llr’).
adaptation_method – Method to adapt threshold (‘mean’, ‘median’, ‘percentile’).
bias – Fixed bias to add to computed threshold.
min_threshold – Minimum allowed threshold value.
max_threshold – Maximum allowed threshold value.
*args – Variable positional arguments passed to the base class.
**kwargs – Variable keyword arguments passed to the base class.
- classmethod from_config(config, **kwargs)
Create model instance from configuration.
- Parameters:
config – Configuration object (PretrainedConfig, DictConfig, or dict)
**kwargs – Additional parameters to override config
- Returns:
Model instance
- classmethod from_hydra_config(config: DictConfig, **kwargs)
Create model from Hydra DictConfig.
- Parameters:
config – Hydra configuration
**kwargs – Additional parameters
- Returns:
Model instance
- classmethod from_pretrained_config(config: PretrainedConfig, **kwargs)
Create model from Hugging Face PretrainedConfig.
- Parameters:
config – PretrainedConfig instance
**kwargs – Additional parameters
- Returns:
Model instance
- to(device: str | device, *args, **kwargs) SoftBitThresholder
Move the model to the specified device.
- Parameters:
device – The device to move the model to.
*args – Additional positional arguments for nn.Module.to().
**kwargs – Additional keyword arguments for nn.Module.to().
- Returns:
Self for method chaining.
- reset_stats(initial_threshold: float | None = None)[source]
Reset the running statistics.
- Parameters:
initial_threshold – New initial threshold to use. If None, keeps the current threshold.
- forward(x: Tensor, reset: bool = False, percentile: float = 50.0, *args: Any, **kwargs: Any) Tensor[source]
Apply dynamic thresholding to convert soft bit values to hard decisions.
- Parameters:
x – Input tensor of soft bit values.
reset – If True, reset running statistics.
percentile – Percentile to use if adaptation_method is ‘percentile’.
*args – Additional positional arguments (unused).
**kwargs – Additional keyword arguments (unused).
- Returns:
Tensor of hard bit decisions (0.0 or 1.0).