sdr.dmc(x: ArrayLike, P: ArrayLike, X: ArrayLike | None = None, Y: ArrayLike | None = None, seed: int | None = None) NDArray[int_]

Passes the input sequence \(x\) through a discrete memoryless channel (DMC) with transition probability matrix \(P\).

Parameters:
x: ArrayLike

The input sequence \(x\) with \(x_i \in \mathcal{X}\).

P: ArrayLike

The \(m \times n\) transition probability matrix \(P\), where \(P_{i,j} = \Pr(Y = y_j | X = x_i)\).

X: ArrayLike | None = None

The input alphabet \(\mathcal{X}\) of size \(m\). If None, it is assumed that \(\mathcal{X} = \{0, 1, \ldots, m-1\}\).

Y: ArrayLike | None = None

The output alphabet \(\mathcal{Y}\) of size \(n\). If None, it is assumed that \(\mathcal{Y} = \{0, 1, \ldots, n-1\}\).

seed: int | None = None

The seed for the random number generator. This is passed to numpy.random.default_rng().

Returns:

The output sequence \(y\) with \(y_i \in \mathcal{Y}\).

Examples

Define the binary symmetric channel (BSC) with transition probability \(p=0.25\).

In [1]: p = 0.25

In [2]: x = np.random.randint(0, 2, 20); x
Out[2]: array([0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1])

In [3]: P = [[1 - p, p], [p, 1 - p]]

In [4]: y = sdr.dmc(x, P); y
Out[4]: array([0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1])

In [5]: x == y
Out[5]: 
array([ True,  True, False,  True,  True,  True,  True, False,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
       False,  True])

Define the binary erasure channel (BEC) with erasure probability \(p=0.25\).

In [6]: p = 0.25

In [7]: x = np.random.randint(0, 2, 20); x
Out[7]: array([0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1])

In [8]: P = [[1 - p, 0, p], [0, 1 - p, p]]

# Specify the erasure as -1
In [9]: y = sdr.dmc(x, P, Y=[0, 1, -1]); y
Out[9]: 
array([ 0,  1, -1,  0,  1, -1,  1,  1,  1, -1,  1,  0,  0,  1, -1, -1,  0,
        0,  0,  1])

In [10]: x == y
Out[10]: 
array([ True,  True, False,  True,  True, False,  True,  True,  True,
       False,  True,  True,  True,  True, False, False,  True,  True,
        True,  True])