WeightedBPCallback#
- class sionna.phy.fec.ldpc.WeightedBPCallback(num_edges: int, pcm: numpy.ndarray | scipy.sparse._matrix.spmatrix | None = None, precision: str | None = None, device: str | None = None, **kwargs)[source]#
Bases:
sionna.phy.object.ObjectCallback for the LDPCBPDecoder to enable weighted BP [Nachmani].
The BP decoder is fully differentiable and can be made trainable by following the concept of weighted BP [Nachmani] leading to
\[y_{j \to i} = 2 \operatorname{tanh}^{-1} \left( \prod_{i' \in \mathcal{N}(j) \setminus i} \operatorname{tanh} \left( \frac{\textcolor{red}{w_{i' \to j}} \cdot x_{i' \to j}}{2} \right) \right)\]where \(w_{i \to j}\) denotes the trainable weight of message \(x_{i \to j}\). Please note that the training of some check node types may be not supported.
Can be registered as
c2v_callbacksandv2c_callbacksin theLDPCBPDecoderand theLDPC5GDecoder.- Parameters:
num_edges (int) – Number of edges in the decoding graph.
pcm (numpy.ndarray | scipy.sparse._matrix.spmatrix | None) – Optional parity-check matrix. If provided, enables weighted BP in padded message format used by the decoder.
precision (str | None) – Precision used for internal calculations and outputs. If set to None,
precisionis used.device (str | None) – Device for computation (e.g., ‘cpu’, ‘cuda:0’).
- Inputs:
msg – [batch_size, num_vns, max_degree], torch.float. v2c messages.
- Outputs:
msg – torch.float. Same as
msg.
Examples
from sionna.phy.fec.ldpc import LDPCBPDecoder from sionna.phy.fec.ldpc.utils import WeightedBPCallback import numpy as np # Create a simple parity-check matrix pcm = np.array([[1, 1, 0, 1], [0, 1, 1, 1]]) # Create callback with trainable weights weighted_cb = WeightedBPCallback(num_edges=np.sum(pcm), pcm=pcm) # Create decoder with callback decoder = LDPCBPDecoder(pcm, v2c_callbacks=[weighted_cb]) # Access trainable weights print(weighted_cb.weights)
Attributes
- property weights: torch.Tensor#
Trainable edge weights
Methods