kaira.models.fec.decoders.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:
- info_indices
Indices of information bits in the Polar code.
- Type:
- device
Device on which the decoder operates (e.g., CPU or GPU).
- Type:
- dtype
Data type used for computations.
- Type:
Methods
Bit node operation for Successive Cancellation decoding.
Check node operation (sum-product or min-sum) for Successive Cancellation decoding.
Decodes the received codeword using the Successive Cancellation algorithm.
Combine two binary vectors using XOR operation.
Decode the received codeword using Successive Cancellation algorithm.
Attributes
Get the code dimension (k).
Get the code length (n).
Get the code rate (k/n).
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:
- 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:
- 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:
- 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:
- 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)