comnum.Ccdm#

class comnum.Ccdm(composition)#

Constant-composition distribution matching (Schulte & Böcherer 2016): k uniform bits to a sequence of n symbols of a fixed composition, by enumerative coding.

Parameters:

composition (list[int]) – occurrences of every symbol in a block.

Raises:

ValueError – for an invalid parameter (the message names it).

Examples

>>> import comnum, numpy as np
>>> m = comnum.Ccdm([2, 1, 1])
>>> b = np.zeros(m.k, dtype=np.uint8)
>>> m.dematch(m.match_bits(b)).tolist() == b.tolist()
True
static from_distribution(p, n)#

The matcher of blocks of n symbols nearest to a distribution.

Parameters:
  • p (array_like) – the target distribution of the symbols.

  • n (int) – symbols per block.

Returns:

the matcher.

Return type:

Ccdm

Raises:

ValueError – for an invalid parameter or input (the message names it).

dematch(symbols)#

The bits of a block of symbols (a used-up symbol is replaced by the nearest available one).

Parameters:

symbols (array_like) – n symbol indices.

Returns:

k bits (uint8).

Return type:

numpy.ndarray

Raises:

ValueError – for an invalid parameter or input (the message names it).

match_bits(bits)#

The symbols of one block of bits.

Parameters:

bits (array_like) – k bits.

Returns:

n symbol indices (int64).

Return type:

numpy.ndarray

Raises:

ValueError – for an invalid parameter or input (the message names it).

composition#

Occurrences of every symbol in a block (int64).

Type:

numpy.ndarray

distribution#

The distribution of the symbols, composition / n (float64).

Type:

numpy.ndarray

k#

Bits per block.

Type:

int

n#

Symbols per block.

Type:

int

rate#

Bits per symbol, k / n.

Type:

float