kaira.models.fec.encoders.BaseBlockCodeEncoder

Inheritance diagram of BaseBlockCodeEncoder

Inheritance diagram for BaseBlockCodeEncoder

class kaira.models.fec.encoders.BaseBlockCodeEncoder(code_length: int, code_dimension: int, *args: Any, **kwargs: Any)[source]

Bases: BaseModel, ABC

Base class for block code encoders.

This abstract class provides a common interface and functionality for all types of block code encoders. It serves as a foundation for specific implementations like linear block codes, cyclic codes, BCH codes, etc.

Block codes transform k information bits into n coded bits (n > k), providing error detection and correction capabilities. The redundancy added during encoding enables the receiver to detect and possibly correct errors introduced by the channel.

Parameters:
  • code_length (int) – The length of the codeword (n)

  • code_dimension (int) – The dimension of the code (k)

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

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

Raises:

ValueError – If code parameters are invalid (e.g., non-positive or dimension > length)

Note

All concrete implementations must override the forward method to provide specific encoding behavior. The inverse_encode and calculate_syndrome methods are available in LinearBlockCodeEncoder for codes that support these operations.

Methods

__init__

Initialize the block code encoder with specified parameters.

extract_message

Extract the message bits from a codeword.

forward

Apply the encoding operation to the input tensor.

from_config

Create model instance from configuration.

from_hydra_config

Create model from Hydra DictConfig.

from_pretrained_config

Create model from Hugging Face PretrainedConfig.

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).

redundancy

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

Examples using kaira.models.fec.encoders.BaseBlockCodeEncoder

Original DeepJSCC Model (Bourtsoulatze 2019) with Training

Original DeepJSCC Model (Bourtsoulatze 2019) with Training

Advanced LDPC Code Visualization with Belief Propagation Animation

Advanced LDPC Code Visualization with Belief Propagation Animation

LDPC Coding and Belief Propagation Decoding

LDPC Coding and Belief Propagation Decoding
__init__(code_length: int, code_dimension: int, *args: Any, **kwargs: Any)[source]

Initialize the block code encoder with specified parameters.

Sets up the basic code parameters and validates that they meet the requirements for a valid block code (positive length, positive dimension, dimension <= length).

property code_length: int

Get the codeword length (n).

Returns:

The number of bits in each codeword after encoding

property code_dimension: int

Get the code dimension (k).

Returns:

The number of information bits encoded in each codeword

property redundancy: int

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

Returns:

The number of redundant bits added during encoding

property parity_bits: int

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

Returns:

The number of parity/check bits in each codeword

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[source]

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.

abstractmethod forward(x: Tensor, *args: Any, **kwargs: Any) Tensor[source]

Apply the encoding operation to the input tensor.

Transforms message bits into codewords by adding redundancy according to the specific encoding scheme implemented by the subclass.

Parameters:
  • x – Input tensor containing message bits. The last dimension should be a multiple of the code dimension (k).

  • *args – Additional positional arguments for specific encoder implementations.

  • **kwargs – Additional keyword arguments for specific encoder implementations.

Returns:

Encoded tensor with codewords. Has the same shape as the input except the last dimension is expanded by a factor of n/k.

Raises:

ValueError – If the last dimension of x is not a multiple of k.

Note

The specific encoding method depends on the subclass implementation. For example, linear codes use matrix multiplication, while other codes may use different algorithms.

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