comnum.LdpcCode#
- class comnum.LdpcCode(n, rows)#
An LDPC code:
LdpcCode.peg(n, k, var_degree=…, seed=…)(progressive edge growth, Hu, Eleftheriou & Arnold 2005) orLdpcCode(n, rows)from the rows of a parity-check matrix. Decoded by belief propagation (seeset_decoder):ruleis"sum_product"(the default, as in the specifications),"min_sum","normalized_min_sum"(scaled byalpha, 0.8 by default) or"offset_min_sum"(offsetalpha);layeredselects the layered schedule (Hocevar 2004, the default); 50 iterations at most by default. The PEG construction uses the variable degree 3 and the seed 1 by default.- Parameters:
- Raises:
ValueError – for an invalid parameter (the message names it).
- static peg(n, k, *, var_degree=Ellipsis, seed=Ellipsis)#
A code built by progressive edge growth.
- Parameters:
- Returns:
the code.
- Return type:
- Raises:
ValueError – for an invalid parameter (the message names it).
Examples
>>> import comnum >>> code = comnum.LdpcCode.peg(96, 48) >>> code.n, code.k, code.girth() >= 6 (96, 48, True)
- decode(llr)#
Decode whole blocks of LLRs (belief propagation).
- Parameters:
llr (array_like) – a multiple of
nLLRs (positive for a 0).- Returns:
kbits per block (uint8).- Return type:
- Raises:
ValueError – for an input that is not an array of numbers of the expected shape.
Examples
>>> import comnum, numpy as np >>> code = comnum.LdpcCode.peg(96, 48) >>> b = comnum.bits(48, comnum.Rng(1)) >>> bool(np.array_equal(code.decode(2.0 - 4.0 * code.encode(b)), b)) True
- decode_llr(llr)#
Decode one block into the a posteriori LLRs of the coded bits.
- Parameters:
llr (array_like) –
nLLRs (positive for a 0).- Returns:
the
na posteriori LLRs and the iterations run.- Return type:
- Raises:
ValueError – for an invalid parameter or input (the message names it).
- encode(bits)#
Encode whole blocks.
- Parameters:
bits (array_like) – a multiple of
kbits.- Returns:
ncoded bits per block (uint8).- Return type:
- Raises:
ValueError – for an input that is not an array of numbers of the expected shape.
Examples
>>> import comnum >>> comnum.LdpcCode.peg(96, 48).encode(comnum.bits(96, comnum.Rng(1))).size 192
- is_codeword(c)#
Whether
H c = 0.- Parameters:
c (array_like) –
nbits.- Returns:
every parity check holds.
- Return type:
- Raises:
ValueError – unless
chasnbits.
- set_decoder(rule=Ellipsis, *, alpha=Ellipsis, layered=Ellipsis, max_iterations=Ellipsis)#
Choose the decoder.
- Parameters:
rule (str) – the check-node rule,
"sum_product","min_sum","normalized_min_sum"(scaled byalpha) or"offset_min_sum"(with the offsetalpha), as the specifications.alpha (float) – the scale or the offset of the min-sum rules.
layered (bool) – the layered schedule (else flooding).
max_iterations (int) – iterations at most.
- Raises:
ValueError – for an invalid parameter (the message names it).