kaira.models.fec.decoders.SuccessiveCancellationDecoder

Inheritance diagram of SuccessiveCancellationDecoder

Inheritance diagram for SuccessiveCancellationDecoder

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

Bases: BaseBlockDecoder[PolarCodeEncoder]

Decoder for Polar code using Successive Cancellation (SC) method [Arıkan, 2009].

This class implements the Successive Cancellation algorithm for decoding Polar codes. It processes the received codeword and estimates the transmitted message bits. The SC method is a recursive decoding algorithm that leverages the structure of Polar codes for efficient decoding.

encoder

The Polar code encoder used for encoding messages.

Type:

PolarCodeEncoder

info_indices

Indices of information bits in the Polar code.

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

regime

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

Type:

str

clip

Clipping value for numerical stability.

Type:

float

Methods

__init__

bitnode

Bit node operation for Successive Cancellation decoding.

checknode

Check node operation (sum-product or min-sum) for Successive Cancellation decoding.

decode_recursive

Decodes the received codeword using the Successive Cancellation algorithm.

f2

Combine two binary vectors using XOR operation.

forward

Decode the received codeword using Successive Cancellation 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: PolarCodeEncoder, *args: Any, **kwargs: Any)[source]
f2(x: Tuple[Tensor, Tensor]) Tensor[source]

Combine two binary vectors using XOR operation.

Parameters:

x (Tuple[torch.Tensor, torch.Tensor]) – Tuple of two binary tensors of shape (batch_size, n).

Returns:

Combined binary tensor of shape (batch_size, n).

Return type:

torch.Tensor

checknode(y: Tuple[Tensor, Tensor]) Tensor[source]

Check node operation (sum-product or min-sum) for Successive Cancellation decoding.

Parameters:

y (Tuple[torch.Tensor, torch.Tensor]) – Tuple of two tensors representing the received codeword.

Returns:

Processed tensor after check node operation.

Return type:

torch.Tensor

bitnode(y: Tuple[Tensor, Tensor, Tensor]) Tensor[source]

Bit node operation for Successive Cancellation decoding.

Parameters:

y (Tuple[torch.Tensor, torch.Tensor, torch.Tensor]) – Tuple containing: - y_even: Tensor of shape (batch_size, n/2) for even positions. - y_odd: Tensor of shape (batch_size, n/2) for odd positions. - x: Tensor of shape (batch_size, n) representing the current estimate.

Returns:

Processed tensor after bit node operation.

Return type:

torch.Tensor

decode_recursive(y: Tensor, info_indices: Tensor, *args: Any, **kwargs: Any) Tensor[source]

Decodes the received codeword using the Successive Cancellation algorithm.

This method recursively processes the received codeword to estimate the transmitted message bits. It splits the input into even and odd positions, applies check node and bit node operations, and combines the results using the Polar code structure.

Parameters:
  • y (torch.Tensor) – Received codeword tensor of shape (batch_size, code_length).

  • info_indices (torch.Tensor) – Boolean array indicating positions of information bits.

Returns:

  • Estimated message bits tensor of shape (batch_size, code_dimension).

  • Estimated codeword bits tensor of shape (batch_size, code_length).

  • Log-likelihood ratio (LLR) tensor of shape (batch_size, code_length).

Return type:

Tuple[torch.Tensor, torch.Tensor, torch.Tensor]

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

Decode the received codeword using Successive Cancellation algorithm.

Parameters:
  • received (torch.Tensor) – Received codeword tensor of shape (batch_size, n).

  • return_for_loss (bool) – If True, returns the log-likelihood ratio (LLR) values for loss calculation. If False, returns the estimated message bits.

Returns:

Estimated message bits of shape (batch_size, k) if return_for_loss is False,

or LLR values of shape (batch_size, n) if return_for_loss is True.

Return type:

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)

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)