Skip to content

komm.NaturalLabeling

Natural binary labeling. It is a binary labeling in which integer $i \in [0 : 2^m)$ is mapped to its base-$2$ representation (MSB-first).

matrix NDArray[integer] cached property

The labeling matrix $\mathbf{Q}$.

Examples:

>>> labeling = komm.NaturalLabeling(2)
>>> labeling.matrix
array([[0, 0],
       [0, 1],
       [1, 0],
       [1, 1]])

num_bits int property

The number $m$ of bits per index of the labeling.

Examples:

>>> labeling = komm.NaturalLabeling(2)
>>> labeling.num_bits
2

cardinality int property

The cardinality $2^m$ of the labeling.

Examples:

>>> labeling = komm.NaturalLabeling(2)
>>> labeling.cardinality
4

inverse_mapping dict[tuple[int, ...], int] cached property

The inverse mapping of the labeling. It is a dictionary that maps each binary tuple to the corresponding index.

Examples:

>>> labeling = komm.NaturalLabeling(2)
>>> labeling.inverse_mapping
{(0, 0): 0, (0, 1): 1, (1, 0): 2, (1, 1): 3}

indices_to_bits()

Returns the binary representation of the given indices.

Parameters:

  • indices (ArrayLike)

    The indices to be converted to bits. Must be an array of integers in $[0:2^m)$.

Returns:

  • bits (NDArray[integer])

    The binary representations of the given indices. Has the same shape as indices, but with the last dimension expanded by a factor of $m$.

Examples:

>>> labeling = komm.NaturalLabeling(2)
>>> labeling.indices_to_bits([2, 0])
array([1, 0, 0, 0])
>>> labeling.indices_to_bits([[2, 0], [3, 3]])
array([[1, 0, 0, 0],
       [1, 1, 1, 1]])

bits_to_indices()

Returns the indices corresponding to a given sequence of bits.

Parameters:

  • bits (ArrayLike)

    The bits to be converted to indices. Must be an array with elements in $\mathbb{B}$ whose last dimension is a multiple $m$.

Returns:

  • indices (NDArray[integer])

    The indices corresponding to the given bits. Has the same shape as bits, but with the last dimension contracted by a factor of $m$.

Examples:

>>> labeling = komm.NaturalLabeling(2)
>>> labeling.bits_to_indices([1, 0, 0, 0])
array([2, 0])
>>> labeling.bits_to_indices([[1, 0, 0, 0], [1, 1, 1, 1]])
array([[2, 0],
       [3, 3]])

marginalize()

Marginalize metrics over the bits of the labeling. The metrics may represent likelihoods or probabilities, for example. The marginalization is done by computing the L-values of the bits, which are defined as $$ L(\mathtt{b}_i) = \log \frac{\Pr[\mathtt{b}_i = 0]}{\Pr[\mathtt{b}_i = 1]}. $$

Parameters:

  • metrics (ArrayLike)

    The metrics for each index of the labeling. Must be an array whose last dimension is a multiple of $2^m$.

Returns:

  • lvalues (NDArray[floating])

    The marginalized metrics over the bits of the labeling. Has the same shape as metrics, but with the last dimension changed by a factor of $m / 2^m$.

Examples:

>>> labeling = komm.NaturalLabeling(2)
>>> labeling.marginalize([0.1, 0.2, 0.3, 0.4, 0.25, 0.25, 0.25, 0.25])
array([-0.84729786, -0.40546511,  0.        ,  0.        ])
>>> labeling.marginalize([[0.1, 0.2, 0.3, 0.4], [0.25, 0.25, 0.25, 0.25]])
array([[-0.84729786, -0.40546511],
       [ 0.        ,  0.        ]])