komm.ProductLabeling
Cartesian product of labelings.
Parameters:
-
*labelings
(Labeling
) –The labelings to be combined. At least one labeling is required.
-
repeat
(int
) –Number of times to repeat the full sequence of labelings. Must be a positive integer. Has the same semantics as
itertools.product
. The default value is1
.
Examples:
>>> labeling1 = komm.Labeling([[0, 0], [1, 1], [1, 0], [0, 1]])
>>> labeling2 = komm.Labeling([[1], [0]])
>>> labeling = komm.ProductLabeling(labeling1, labeling2)
>>> labeling.matrix
array([[0, 0, 1],
[0, 0, 0],
[1, 1, 1],
[1, 1, 0],
[1, 0, 1],
[1, 0, 0],
[0, 1, 1],
[0, 1, 0]])
>>> labeling = komm.ProductLabeling(
... komm.Labeling([[1, 0], [1, 1], [0, 1], [0, 0]]),
... repeat=2,
... )
>>> labeling.matrix
array([[1, 0, 1, 0],
[1, 0, 1, 1],
[1, 0, 0, 1],
[1, 0, 0, 0],
[1, 1, 1, 0],
[1, 1, 1, 1],
[1, 1, 0, 1],
[1, 1, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 1],
[0, 1, 0, 1],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 1, 1],
[0, 0, 0, 1],
[0, 0, 0, 0]])
from_matrices()
classmethod
Constructs a product labeling from labeling matrices.
Parameters:
-
*matrices
(ArrayLike
) –The labeling matrices. At least one matrix is required. See labeling documentation.
-
repeat
(int
) –Number of times to repeat the full sequence of matrices. Must be a positive integer. Has the same semantics as
itertools.product
. The default value is1
.
Examples:
>>> labeling = komm.ProductLabeling.from_matrices(
... [[0, 0], [1, 1], [1, 0], [0, 1]],
... [[1], [0]],
... )
>>> labeling.matrix
array([[0, 0, 1],
[0, 0, 0],
[1, 1, 1],
[1, 1, 0],
[1, 0, 1],
[1, 0, 0],
[0, 1, 1],
[0, 1, 0]])
>>> labeling = komm.ProductLabeling.from_matrices(
... [[1, 0], [1, 1], [0, 1], [0, 0]],
... repeat=2,
... )
>>> labeling.matrix
array([[1, 0, 1, 0],
[1, 0, 1, 1],
[1, 0, 0, 1],
[1, 0, 0, 0],
[1, 1, 1, 0],
[1, 1, 1, 1],
[1, 1, 0, 1],
[1, 1, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 1],
[0, 1, 0, 1],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 1, 1],
[0, 0, 0, 1],
[0, 0, 0, 0]])
matrix
NDArray[integer]
cached
property
The labeling matrix $\mathbf{Q}$.
num_bits
int
property
The number $m$ of bits per index of the labeling.
Examples:
>>> labeling = komm.ProductLabeling.from_matrices(
... [[0, 0], [1, 1], [1, 0], [0, 1]],
... [[1], [0]],
... )
>>> labeling.num_bits
3
cardinality
int
property
The cardinality $2^m$ of the labeling.
Examples:
>>> labeling = komm.ProductLabeling.from_matrices(
... [[0, 0], [1, 1], [1, 0], [0, 1]],
... [[1], [0]],
... )
>>> labeling.cardinality
8
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.ProductLabeling.from_matrices(
... [[0, 0], [1, 1], [1, 0], [0, 1]],
... [[1], [0]],
... )
>>> labeling.inverse_mapping
{(0, 0, 1): 0,
(0, 0, 0): 1,
(1, 1, 1): 2,
(1, 1, 0): 3,
(1, 0, 1): 4,
(1, 0, 0): 5,
(0, 1, 1): 6,
(0, 1, 0): 7}
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.ProductLabeling.from_matrices(
... [[0, 0], [1, 1], [1, 0], [0, 1]],
... [[1], [0]],
... )
>>> labeling.indices_to_bits([2, 0])
array([1, 1, 1, 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.ProductLabeling.from_matrices(
... [[0, 0], [1, 1], [1, 0], [0, 1]],
... [[1], [0]],
... )
>>> labeling.bits_to_indices([1, 1, 1, 0, 0, 1])
array([2, 0])
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$.