Skip to content

komm.ReflectedRectangularLabeling

Reflected rectangular binary labeling. It is the Cartesian product of two reflected binary labelings, possibly with distinct number of bits.

matrix NDArray[integer] cached property

The labeling matrix $\mathbf{Q}$.

Examples:

>>> labeling = komm.ReflectedRectangularLabeling(4)
>>> labeling.matrix
array([[0, 0, 0, 0],
       [0, 0, 0, 1],
       [0, 0, 1, 1],
       [0, 0, 1, 0],
       [0, 1, 0, 0],
       [0, 1, 0, 1],
       [0, 1, 1, 1],
       [0, 1, 1, 0],
       [1, 1, 0, 0],
       [1, 1, 0, 1],
       [1, 1, 1, 1],
       [1, 1, 1, 0],
       [1, 0, 0, 0],
       [1, 0, 0, 1],
       [1, 0, 1, 1],
       [1, 0, 1, 0]])

num_bits int property

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

Examples:

>>> labeling = komm.ReflectedRectangularLabeling(4)
>>> labeling.num_bits
4

cardinality int property

The cardinality $2^m$ of the labeling.

Examples:

>>> labeling = komm.ReflectedRectangularLabeling(4)
>>> labeling.cardinality
16

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

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

Examples:

>>> labeling = komm.ReflectedRectangularLabeling(4  )
>>> labeling.inverse_mapping
{(0, 0, 0, 0): 0,
 (0, 0, 0, 1): 1,
 (0, 0, 1, 1): 2,
 (0, 0, 1, 0): 3,
 (0, 1, 0, 0): 4,
 (0, 1, 0, 1): 5,
 (0, 1, 1, 1): 6,
 (0, 1, 1, 0): 7,
 (1, 1, 0, 0): 8,
 (1, 1, 0, 1): 9,
 (1, 1, 1, 1): 10,
 (1, 1, 1, 0): 11,
 (1, 0, 0, 0): 12,
 (1, 0, 0, 1): 13,
 (1, 0, 1, 1): 14,
 (1, 0, 1, 0): 15}

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.ReflectedRectangularLabeling(4)
>>> labeling.indices_to_bits([8, 13])
array([1, 1, 0, 0, 1, 0, 0, 1])
>>> labeling.indices_to_bits([[8, 13], [0, 1]])
array([[1, 1, 0, 0, 1, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 0, 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.ReflectedRectangularLabeling(4)
>>> labeling.bits_to_indices([1, 1, 0, 0, 1, 0, 0, 1])
array([ 8, 13])
>>> labeling.bits_to_indices([
...     [1, 1, 0, 0, 1, 0, 0, 1],
...     [0, 0, 0, 0, 0, 0, 0, 1],
... ])
array([[ 8, 13],
       [ 0,  1]])

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$.