kaira.models.fec.encoders.ReedMullerCodeEncoder

Inheritance diagram of ReedMullerCodeEncoder

Inheritance diagram for ReedMullerCodeEncoder

class kaira.models.fec.encoders.ReedMullerCodeEncoder(order: int, length_param: int, *args: Any, **kwargs: Any)[source]

Bases: LinearBlockCodeEncoder

Encoder 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].

order

The order r of the Reed-Muller code (0 ≤ r < m)

Type:

int

length_param

The length parameter m (code length will be 2^m)

Type:

int

minimum_distance

The minimum Hamming distance of the code (2^(m-r))

Type:

int

Parameters:
  • order (int) – The order r of the Reed-Muller code (0 ≤ r < m)

  • length_param (int) – The length parameter m

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

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

Methods

__init__

Initialize the Reed-Muller encoder.

calculate_syndrome

Return the syndrome (error pattern) for given codeword(s).

extract_message

Extract the message bits from a codeword.

forward

Applies the encoding mapping Enc: B^k → B^n of the code.

from_parameters

Create a Reed-Muller encoder from parameters.

get_reed_partitions

Get the Reed partitions of the code.

inverse_encode

Decode codeword(s) by brute-force nearest-codeword search.

Attributes

code_dimension

Get the code dimension (k).

code_length

Get the codeword length (n).

code_rate

Get the rate of the code (k/n).

parity_bits

Get the number of parity bits (synonym for redundancy).

parity_check_matrix

Get the check matrix H of the code.

redundancy

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

property parity_check_matrix: Tensor

Get the check matrix H of the code.

The check matrix H satisfies the property: GH^T = 0

Returns:

The check matrix H of the code

property redundancy: int

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

Returns:

The number of redundant bits added during encoding