kaira.models.fec.decoders.ReedMullerDecoder

Inheritance diagram of ReedMullerDecoder

Inheritance diagram for ReedMullerDecoder

class kaira.models.fec.decoders.ReedMullerDecoder(encoder: ReedMullerCodeEncoder, input_type: Literal['hard', 'soft'] = 'hard', *args: Any, **kwargs: Any)[source]

Bases: BaseBlockDecoder[ReedMullerCodeEncoder]

Reed-Muller decoder using majority-logic decoding.

This decoder implements the majority-logic decoding algorithm developed by Reed for Reed-Muller codes [Reed, 1954]. It works by recursively decoding the received word using a series of majority-logic decisions based on special partitions of the code that correspond to geometrical subspaces in the finite geometry interpretation.

For an RM(r,m) code, the algorithm can correct up to 2^(m-r-1) - 1 errors, which is optimal for first-order Reed-Muller codes (r=1) [MacWilliams and Sloane, 1977].

The decoder supports both hard-decision and soft-decision decoding, with the soft-decision variant offering better performance in the presence of noise by taking into account reliability information from the channel.

encoder

The Reed-Muller encoder instance providing code parameters and encoding functionality

Type:

ReedMullerCodeEncoder

input_type

The type of input the decoder accepts: ‘hard’ for binary inputs (0s and 1s) ‘soft’ for real-valued inputs with reliability information

Type:

str

_reed_partitions

Precomputed Reed partitions for efficient decoding, where each partition corresponds to a specific information bit

Type:

List[List[int]]

Parameters:
  • encoder (ReedMullerCodeEncoder) – The encoder for the Reed-Muller code being decoded

  • input_type (Literal["hard", "soft"]) – The type of input the decoder accepts. Default is “hard”.

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

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

Examples

>>> from kaira.models.fec.encoders import ReedMullerCodeEncoder
>>> from kaira.models.fec.decoders import ReedMullerDecoder
>>> import torch
>>>
>>> # Create a RM(1,3) code encoder and decoder
>>> encoder = ReedMullerCodeEncoder(r=1, m=3)
>>> decoder = ReedMullerDecoder(encoder)
>>>
>>> # Encode a message
>>> message = torch.tensor([1., 0., 1., 0.])
>>> codeword = encoder(message)
>>>
>>> # Introduce an error
>>> received = codeword.clone()
>>> received[2] = 1 - received[2]
>>>
>>> # Decode using majority-logic decoding
>>> decoded = decoder(received)
>>> print(torch.all(decoded == message))
True

Methods

__init__

Initialize the Reed-Muller decoder.

forward

Decode received values using the Reed majority-logic 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: ReedMullerCodeEncoder, input_type: Literal['hard', 'soft'] = 'hard', *args: Any, **kwargs: Any)[source]

Initialize the Reed-Muller decoder.

Sets up the decoder with a Reed-Muller encoder instance and computes the Reed partitions needed for majority-logic decoding.

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

  • input_type – The type of decoder input, either “hard” for binary inputs or “soft” for real-valued inputs with reliability information

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

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

Note

The Reed partitions are precomputed during initialization to make the decoding process more efficient. These partitions depend on the specific parameters of the Reed-Muller code (r,m).

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

Decode received values using the Reed majority-logic algorithm.

This method implements the majority-logic decoding process for Reed-Muller codes. For each information bit, it computes a set of check sums based on the Reed partitions and then makes a decision based on the majority value of these sums.

For soft-decision decoding, it also takes into account the reliability information of each received bit, which can significantly improve performance in AWGN channels.

Parameters:
  • received – Received tensor with shape (…, n) or (…, m*n) where n is the code length. For hard inputs, values should be 0 or 1. For soft inputs, positive values represent likelihood of 0 bits and negative values represent likelihood of 1 bits (e.g., LLR values).

  • *args – Additional positional arguments

  • **kwargs – Additional keyword arguments return_errors: If True, also return the estimated error patterns

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

For first-order Reed-Muller codes (r=1), this decoder can correct up to 2^(m-2) errors, which matches the code’s error-correcting capability. For higher-order RM codes, the performance may not be optimal but the algorithm provides an efficient decoding approach.

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)