kaira.models.fec.decoders.BeliefPropagationPolarDecoder

Inheritance diagram of BeliefPropagationPolarDecoder

Inheritance diagram for BeliefPropagationPolarDecoder

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

Bases: BaseBlockDecoder[PolarCodeEncoder]

Decoder for Polar code using Belief Propagation (BP) method.

This class implements the Belief Propagation algorithm for decoding Polar codes. It processes the received codeword and estimates the transmitted message bits. The decoder supports two regimes: ‘sum_product’ and ‘min_sum’, and provides options for early stopping and cyclic permutations.

encoder

The Polar code encoder used for encoding messages.

Type:

PolarCodeEncoder

info_indices

Indices of information bits in the Polar code.

Type:

torch.Tensor

frozen_ind

Boolean array indicating frozen bits.

Type:

torch.Tensor

device

Device on which the decoder operates (e.g., CPU or GPU).

Type:

torch.device

dtype

Data type used for computations.

Type:

torch.dtype

polar_i

Indicates whether polar_i is enabled in the encoder.

Type:

bool

frozen_zeros

Indicates whether frozen bits are initialized to zeros.

Type:

bool

m

Number of stages in the Polar code.

Type:

int

iteration_num

Number of iterations for decoding.

Type:

int

mask_dict

Mask dictionary for the Polar code structure.

Type:

torch.Tensor

early_stop

Whether to use early stopping during decoding.

Type:

bool

regime

Decoding regime (‘sum_product’ or ‘min_sum’).

Type:

str

clip

Clipping value for numerical stability.

Type:

float

perm

Type of permutation of the factor graph used (‘cycle’ or None).

Type:

str or None

permutations

Array of cyclic permutations.

Type:

torch.Tensor

R_all

List of R matrices for each iteration.

Type:

list

L_all

List of L matrices for each iteration.

Type:

list

Methods

__init__

Initializes the BeliefPropagationPolarDecoder.

checknode

Check node operation for the Belief Propagation Polar Decoder.

decode_iterative

Performs iterative decoding using the Belief Propagation algorithm.

forward

Decodes the received codeword using the Belief Propagation algorithm.

get_cyclic_permutations

Generates cyclic permutations for decoding.

print_decoder_type

Prints the type of decoder being used, along with its configuration.

update_left

Updates the left messages in the decoding graph.

update_right

Updates the right messages in the decoding graph.

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: PolarCodeEncoder, *args: Any, **kwargs: Any)[source]

Initializes the BeliefPropagationPolarDecoder.

Args: encoder (PolarCodeEncoder): The Polar code encoder used for encoding messages. bp_iters (int): Number of iterations for decoding. early_stop (bool): Whether to use early stopping during decoding. regime (str): Decoding regime (‘sum_product’ or ‘min_sum’). clip (float): Clipping value for numerical stability. perm (str or None): Type of permutation of the factor graph used (‘cycle’ or None).

print_decoder_type()[source]

Prints the type of decoder being used, along with its configuration.

get_cyclic_permutations(perm=None)[source]

Generates cyclic permutations for decoding.

Parameters:

perm (str or None) – Type of permutation (‘cycle’ or None).

checknode(y1, y2)[source]

Check node operation for the Belief Propagation Polar Decoder.

Parameters:
Returns:

Output message after applying the check node operation.

Return type:

torch.Tensor

update_right(R, L, perm)[source]

Updates the right messages in the decoding graph.

Parameters:
Returns:

Updated right message tensor.

Return type:

torch.Tensor

update_left(R, L, perm)[source]

Updates the left messages in the decoding graph.

Parameters:
Returns:

Updated left message tensor.

Return type:

torch.Tensor

decode_iterative(llr: Tensor)[source]

Performs iterative decoding using the Belief Propagation algorithm.

Parameters:

llr (torch.Tensor) – Log-likelihood ratio tensor of shape (batch_size, N).

Returns:

Decoded message bits and codeword bits.

Return type:

Tuple[torch.Tensor, torch.Tensor]

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)

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

Decodes the received codeword using the Belief Propagation algorithm.

Parameters:

received (torch.Tensor) – Received codeword tensor of shape (batch_size, code_length).

Returns:

Estimated message bits of shape (batch_size, code_dimension).

Return type:

torch.Tensor

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)