kaira.models.fec.encoders.ReedMullerCodeEncoder

Inheritance diagram for ReedMullerCodeEncoder
- class kaira.models.fec.encoders.ReedMullerCodeEncoder(order: int, length_param: int, *args: Any, **kwargs: Any)[source]
Bases:
LinearBlockCodeEncoderEncoder for Reed-Muller codes.
Reed-Muller codes are a family of linear error-correcting codes with parameters (r,m) where: - r is the order (0 ≤ r < m) - m is the length parameter
The resulting code has the following properties: - Length: n = 2^m - Dimension: k = sum_{i=0}^r (m choose i) - Minimum distance: d = 2^(m-r)
Special cases: - RM(0,m) is a repetition code - RM(m-1,m) is a single parity-check code - RM(1,m) is a first-order Reed-Muller code (also known as a lengthened simplex code) - RM(m-2,m) is an extended Hamming code
This implementation follows the standard approach to Reed-Muller coding described in error control coding literature [Lin and Costello, 2004, Moon, 2005].
- Parameters:
Methods
Initialize the Reed-Muller encoder.
Return the syndrome (error pattern) for given codeword(s).
Extract the message bits from a codeword.
Applies the encoding mapping Enc: B^k → B^n of the code.
Create a Reed-Muller encoder from parameters.
Get the Reed partitions of the code.
Decode codeword(s) by brute-force nearest-codeword search.
Attributes
Get the code dimension (k).
Get the codeword length (n).
Get the rate of the code (k/n).
Get the number of parity bits (synonym for redundancy).
Get the check matrix H of the code.
Get the code redundancy (r = n - k).
- __init__(order: int, length_param: int, *args: Any, **kwargs: Any)[source]
Initialize the Reed-Muller encoder.
- Parameters:
order – The order r of the Reed-Muller code (0 ≤ r < m)
length_param – The length parameter m (code length will be 2^m)
*args – Variable positional arguments passed to the base class.
**kwargs – Variable keyword arguments passed to the base class.
- Raises:
ValueError – If the parameters do not satisfy 0 ≤ r < m
- classmethod from_parameters(order: int, length_param: int, *args: Any, **kwargs: Any) ReedMullerCodeEncoder[source]
Create a Reed-Muller encoder from parameters.
This is an alternative constructor that creates the encoder directly from the Reed-Muller parameters.
- Parameters:
order – The order r of the Reed-Muller code (0 ≤ r < m)
length_param – The length parameter m
*args – Variable positional arguments passed to the constructor.
**kwargs – Variable keyword arguments passed to the constructor.
- Returns:
A ReedMullerCodeEncoder instance
- get_reed_partitions() List[Tensor][source]
Get the Reed partitions of the code.
Reed partitions are useful for certain decoding algorithms, particularly majority-logic decoding.
- Returns:
List of tensors representing the Reed partitions
- inverse_encode(x: Tensor, *args: Any, **kwargs: Any) Tuple[Tensor, Tensor][source]
Decode codeword(s) by brute-force nearest-codeword search.
This method implements a maximum-likelihood decoder for Reed-Muller codes by finding the closest valid codeword to the received word(s).
- Parameters:
x – The received codeword(s). Can be a single vector or a batch.
*args – Additional positional arguments (unused).
**kwargs – Additional keyword arguments (unused).
- Returns:
Decoded message(s)
Syndrome (difference between closest valid codeword and received word)
- Return type:
Tuple containing
- calculate_syndrome(y: Tensor)[source]
Return the syndrome (error pattern) for given codeword(s).
For Reed-Muller codes, we define the syndrome as the difference between the received word and the nearest valid codeword.
- Parameters:
y – The received codeword(s)
- Returns:
Syndrome tensor (difference between nearest valid codeword and received word)
- property code_dimension: int
Get the code dimension (k).
- Returns:
The number of information bits encoded in each codeword
- property code_length: int
Get the codeword length (n).
- Returns:
The number of bits in each codeword after encoding
- property code_rate: float
Get the rate of the code (k/n).
The code rate is a measure of efficiency, representing the proportion of the total bits that carry information (as opposed to redundancy).
- Returns:
The ratio of information bits to total bits (between 0 and 1)
- extract_message(codeword: Tensor) Tensor
Extract the message bits from a codeword.
By default, this calls inverse_encode and returns just the decoded message. Subclasses can override this method to provide more efficient implementations.
- Parameters:
codeword – Codeword tensor with shape (…, n) where n is the code length
- Returns:
Extracted message tensor with shape (…, k) where k is the code dimension
Note
This implementation assumes the inverse_encode method can handle a single codeword correctly. Specific code types may override this with more efficient implementations.
- forward(x: Tensor, *args: Any, **kwargs: Any) Tensor
Applies the encoding mapping Enc: B^k → B^n of the code.
This method takes one or more sequences of messages and returns their corresponding codeword sequences. The encoding process follows standard linear block code principles [Lin and Costello, 2004, Richardson and Urbanke, 2008].
- Parameters:
x – The input tensor. Can be either a single sequence whose length is a multiple of k, or a multidimensional tensor where the last dimension is a multiple of k.
*args – Additional positional arguments (unused).
**kwargs – Additional keyword arguments (unused).
- Returns:
The output tensor. Has the same shape as the input, with the last dimension expanded from b*k to b*n, where b is a positive integer.
- Raises:
ValueError – If the last dimension of the input is not a multiple of k.
- property parity_bits: int
Get the number of parity bits (synonym for redundancy).
- Returns:
The number of parity/check bits in each codeword