kaira.models.fec.decoders.WagnerSoftDecisionDecoder

Inheritance diagram of WagnerSoftDecisionDecoder

Inheritance diagram for WagnerSoftDecisionDecoder

class kaira.models.fec.decoders.WagnerSoftDecisionDecoder(encoder: BaseBlockCodeEncoder, *args: Any, **kwargs: Any)[source]

Bases: BaseBlockDecoder[BaseBlockCodeEncoder]

Wagner soft-decision decoder for single parity-check codes.

This decoder implements the Wagner algorithm [Wagner, 1986], which is designed specifically for single parity-check codes with soft-decision inputs. It leverages reliability information to make optimal decoding decisions under the assumption of an AWGN channel.

The Wagner algorithm works by: 1. Making initial hard decisions based on the sign of the received soft values 2. Checking if the parity constraint is satisfied by these decisions 3. If not, flipping the bit with the smallest absolute value (least reliable bit)

This simple but elegant approach achieves optimal maximum likelihood decoding for single parity-check codes with soft inputs [Hagenauer and Hoeher, 1996, Moon, 2005].

encoder

The encoder instance providing code parameters and encoding functionality

Type:

BaseBlockCodeEncoder

Parameters:
  • encoder (BaseBlockCodeEncoder) – The encoder for the code being decoded. Must represent a single parity-check code where code_length = code_dimension + 1

  • *args – Variable positional arguments passed to the base class

  • **kwargs – Variable keyword arguments passed to the base class

Raises:

ValueError – If the encoder does not represent a single parity-check code

Examples

>>> from kaira.models.fec.encoders import SingleParityCheckCodeEncoder
>>> from kaira.models.fec.decoders import WagnerSoftDecisionDecoder
>>> import torch
>>>
>>> # Create a (4,3) single parity-check code encoder and decoder
>>> encoder = SingleParityCheckCodeEncoder(code_dimension=3)
>>> decoder = WagnerSoftDecisionDecoder(encoder)
>>>
>>> # Encode a message
>>> message = torch.tensor([1., 0., 1.])
>>> codeword = encoder(message)
>>> print(codeword)  # Output: tensor([1., 0., 1., 0.])
>>>
>>> # Simulate soft decision values from AWGN channel
>>> # Positive values represent 0, negative values represent 1
>>> # The magnitudes represent reliability
>>> soft_received = torch.tensor([-2.1, 1.5, -1.8, 0.2])
>>>
>>> # Decode using the Wagner algorithm
>>> decoded = decoder(soft_received)
>>> print(decoded)  # Output: tensor([1, 0, 1])

Methods

__init__

Initialize the Wagner soft-decision decoder.

forward

Decode received soft values using the Wagner algorithm.

Attributes

code_dimension

Get the code dimension (k).

code_length

Get the code length (n).

code_rate

Get the code rate (k/n).

redundancy

Get the code redundancy (r = n - k).

__init__(encoder: BaseBlockCodeEncoder, *args: Any, **kwargs: Any)[source]

Initialize the Wagner soft-decision decoder.

Sets up the decoder with an encoder instance and verifies that it represents a single parity-check code, which is required for the Wagner algorithm.

Parameters:
  • encoder – The encoder instance for the code being decoded

  • *args – Variable positional arguments passed to the base class

  • **kwargs – Variable keyword arguments passed to the base class

Raises:

ValueError – If the encoder does not represent a single parity-check code, i.e., if code_length ≠ code_dimension + 1

forward(received: Tensor, *args: Any, **kwargs: Any) Tensor | Tuple[Tensor, Tensor][source]

Decode received soft values using the Wagner algorithm.

This method implements the complete Wagner soft-decision decoding process: 1. Make initial hard decisions based on the sign of received values 2. Check if the parity constraint is satisfied 3. If not, find the least reliable bit (smallest absolute value) and flip it 4. Extract the message bits from the corrected codeword

The algorithm assumes soft-input values where: - Positive values represent a likelihood of ‘0’ bits - Negative values represent a likelihood of ‘1’ bits - The magnitude of the value represents the reliability of the decision

Parameters:
  • received – Received soft-decision tensor with shape (…, n) or (…, m*n) where n is the code length and m is some multiple. Values represent soft bit likelihoods (e.g., LLRs) where: - Positive values suggest bit=0 - Negative values suggest bit=1 - Magnitude indicates reliability

  • *args – Additional positional arguments

  • **kwargs – Additional keyword arguments return_errors: If True, also return the estimated error patterns compared to the initial hard decisions

Returns:

  • Decoded tensor containing estimated messages with shape (…, k) or (…, m*k)

  • A tuple of (decoded tensor, error pattern tensor) if return_errors=True

Return type:

Either

Raises:

ValueError – If the last dimension of received is not a multiple of the code length

Note

This decoder provides optimal maximum likelihood performance for single parity-check codes under AWGN channels. It is computationally efficient, requiring only O(n) operations for an (n,n-1) single parity-check code.

property code_dimension: int

Get the code dimension (k).

The code dimension is the number of information bits in each codeword, representing the actual data being transmitted.

Returns:

The dimension of the code (number of information bits)

property code_length: int

Get the code length (n).

The code length is the total number of bits in each codeword, including both information bits and redundancy bits.

Returns:

The length of the code (number of bits in a codeword)

property code_rate: float

Get the code rate (k/n).

The code rate is the ratio of information bits to the total bits, indicating the coding efficiency. Higher rates mean more efficient use of the channel but typically lower error correction capability.

Returns:

The rate of the code (ratio of information bits to total bits)

property redundancy: int

Get the code redundancy (r = n - k).

The redundancy represents the number of parity or check bits added to the information bits to enable error detection and correction.

Returns:

The redundancy of the code (number of parity bits)