komm.BlockCode
General binary linear block code. It is characterized by its generator matrix $G \in \mathbb{B}^{k \times n}$, and by its check matrix $H \in \mathbb{B}^{m \times n}$, which are related by $G H^\transpose = 0$. The parameters $n$, $k$, and $m$ are called the code length, dimension, and redundancy, respectively, and are related by $k + m = n$. For more details, see LC04, Ch. 3.
The constructor expects either the generator matrix or the check matrix.
Attributes:
-
generator_matrix
(NDArray[integer]
) –The generator matrix $G$ of the code, which is a $k \times n$ binary matrix.
-
check_matrix
(NDArray[integer]
) –The check matrix $H$ of the code, which is a $m \times n$ binary matrix.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> (code.length, code.dimension, code.redundancy)
(5, 2, 3)
>>> code.generator_matrix
array([[1, 0, 0, 1, 1],
[0, 1, 1, 1, 0]])
>>> code.check_matrix
array([[0, 1, 1, 0, 0],
[1, 1, 0, 1, 0],
[1, 0, 0, 0, 1]])
>>> code = komm.BlockCode(check_matrix=[[0, 1, 1, 0, 0], [1, 1, 0, 1, 0], [1, 0, 0, 0, 1]])
>>> (code.length, code.dimension, code.redundancy)
(5, 2, 3)
>>> code.generator_matrix
array([[1, 0, 0, 1, 1],
[0, 1, 1, 1, 0]])
>>> code.check_matrix
array([[0, 1, 1, 0, 0],
[1, 1, 0, 1, 0],
[1, 0, 0, 0, 1]])
length: int
property
The length $n$ of the code.
dimension: int
property
The dimension $k$ of the code.
redundancy: int
property
The redundancy $m$ of the code.
rate: float
property
The rate $R = k/n$ of the code.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.rate
0.4
encode
Applies the encoding mapping $\Enc : \mathbb{B}^k \to \mathbb{B}^n$ of the code. This method takes one or more sequences of messages and returns their corresponding codeword sequences.
Parameters:
-
input
(ArrayLike
) –The input sequence(s). Can be either a single sequence whose length is a multiple of $k$, or a multidimensional array where the last dimension is a multiple of $k$.
Returns:
-
output
(NDArray[integer]
) –The output sequence(s). Has the same shape as the input, with the last dimension expanded from $bk$ to $bn$, where $b$ is a positive integer.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.encode([0, 0]) # Sequence with single message
array([0, 0, 0, 0, 0])
>>> code.encode([0, 0, 1, 1]) # Sequence with two messages
array([0, 0, 0, 0, 0, 1, 1, 1, 0, 1])
>>> code.encode([[0, 0], [1, 1]]) # 2D array of single messages
array([[0, 0, 0, 0, 0],
[1, 1, 1, 0, 1]])
>>> code.encode([[0, 0, 1, 1], [1, 1, 1, 0]]) # 2D array of two messages
array([[0, 0, 0, 0, 0, 1, 1, 1, 0, 1],
[1, 1, 1, 0, 1, 1, 0, 0, 1, 1]])
inverse_encode
Applies the inverse encoding mapping $\Enc^{-1} : \mathbb{B}^n \to \mathbb{B}^k$ of the code. This method takes one or more sequences of codewords and returns their corresponding message sequences.
Parameters:
-
input
(ArrayLike
) –The input sequence(s). Can be either a single sequence whose length is a multiple of $n$, or a multidimensional array where the last dimension is a multiple of $n$.
Returns:
-
output
(NDArray[integer]
) –The output sequence(s). Has the same shape as the input, with the last dimension contracted from $bn$ to $bk$, where $b$ is a positive integer.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.inverse_encode([0, 0, 0, 0, 0]) # Sequence with single codeword
array([0, 0])
>>> code.inverse_encode([0, 0, 0, 0, 0, 1, 1, 1, 0, 1]) # Sequence with two codewords
array([0, 0, 1, 1])
>>> code.inverse_encode([[0, 0, 0, 0, 0], [1, 1, 1, 0, 1]]) # 2D array of single codewords
array([[0, 0],
[1, 1]])
>>> code.inverse_encode([[0, 0, 0, 0, 0, 1, 1, 1, 0, 1], [1, 1, 1, 0, 1, 1, 0, 0, 1, 1]]) # 2D array of two codewords
array([[0, 0, 1, 1],
[1, 1, 1, 0]])
check
Applies the check mapping $\mathrm{Chk}: \mathbb{B}^n \to \mathbb{B}^m$ of the code. This method takes one or more sequences of received words and returns their corresponding syndrome sequences.
Parameters:
-
input
(ArrayLike
) –The input sequence(s). Can be either a single sequence whose length is a multiple of $n$, or a multidimensional array where the last dimension is a multiple of $n$.
Returns:
-
output
(NDArray[integer]
) –The output sequence(s). Has the same shape as the input, with the last dimension contracted from $bn$ to $bm$, where $b$ is a positive integer.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.check([1, 1, 1, 0, 1]) # Sequence with single received word
array([0, 0, 0])
>>> code.check([1, 1, 1, 0, 1, 1, 1, 1, 1, 1]) # Sequence with two received words
array([0, 0, 0, 0, 1, 0])
>>> code.check([[1, 1, 1, 0, 1], [1, 1, 1, 1, 1]]) # 2D array of single received words
array([[0, 0, 0],
[0, 1, 0]])
>>> code.check([[1, 1, 1, 0, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 0, 0, 0, 1, 1]]) # 2D array of two received words
array([[0, 0, 0, 0, 1, 0],
[0, 1, 0, 0, 1, 1]])
codewords
cached
Returns the codewords of the code. This is a $2^k \times n$ matrix whose rows are all the codewords. The codeword in row $i$ corresponds to the message obtained by expressing $i$ in binary with $k$ bits (MSB in the right).
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.codewords()
array([[0, 0, 0, 0, 0],
[1, 0, 0, 1, 1],
[0, 1, 1, 1, 0],
[1, 1, 1, 0, 1]])
codeword_weight_distribution
cached
Returns the codeword weight distribution of the code. This is an array of shape $(n + 1)$ in which element in position $w$ is equal to the number of codewords of Hamming weight $w$, for $w \in [0 : n]$.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.codeword_weight_distribution()
array([1, 0, 0, 2, 1, 0])
minimum_distance
cached
Returns the minimum distance $d$ of the code. This is equal to the minimum Hamming weight of the non-zero codewords.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.minimum_distance()
3
coset_leaders
cached
Returns the coset leaders of the code. This is a $2^m \times n$ matrix whose rows are all the coset leaders. The coset leader in row $i$ corresponds to the syndrome obtained by expressing $i$ in binary with $m$ bits (MSB in the right), and whose Hamming weight is minimal. This may be used as a LUT for syndrome-based decoding.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.coset_leaders()
array([[0, 0, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 0],
[0, 1, 0, 0, 0],
[0, 0, 0, 0, 1],
[1, 1, 0, 0, 0],
[1, 0, 0, 0, 0],
[1, 0, 1, 0, 0]])
coset_leader_weight_distribution
cached
Returns the coset leader weight distribution of the code. This is an array of shape $(n + 1)$ in which element in position $w$ is equal to the number of coset leaders of weight $w$, for $w \in [0 : n]$.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.coset_leader_weight_distribution()
array([1, 5, 2, 0, 0, 0])
packing_radius
cached
Returns the packing radius of the code. This is also called the error-correcting capability of the code, and is equal to $\lfloor (d - 1) / 2 \rfloor$.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.packing_radius()
1
covering_radius
cached
Returns the covering radius of the code. This is equal to the maximum Hamming weight of the coset leaders.
Examples:
>>> code = komm.BlockCode(generator_matrix=[[1, 0, 0, 1, 1], [0, 1, 1, 1, 0]])
>>> code.covering_radius()
2