Skip to content

Commit

Permalink
Update channel documentation to include input and output parameters f…
Browse files Browse the repository at this point in the history
…or AWGN, Binary Erasure, Binary Symmetric, and Discrete Memoryless channels
  • Loading branch information
rwnobrega committed Nov 4, 2024
1 parent 40c9ddf commit 5d4d4ea
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/komm/_channels/AWGNChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@ class AWGNChannel:
$$
where $P = \mathrm{E}[X^2_n]$ is the average power of the input signal, and $N = \mathrm{E}[Z^2_n]$ is the average power (and variance) of the noise. For more details, see <cite>CT06, Ch. 9</cite>.
To invoke the channel, call the object giving the input signal as parameter (see example below).
Attributes:
signal_power (float | str): The input signal power $P$. If equal to the string `'measured'`, then every time the channel is invoked the input signal power will be computed from the input itself (i.e., its squared Euclidean norm).
snr (Optional[float]): The channel signal-to-noise ratio $\snr$ (linear, not decibel). The default value is `np.inf`, which corresponds to a noiseless channel.
Parameters: Input:
in0 (Array1D[float]): The input signal $X_n$.
Parameters: Output:
out0 (Array1D[float]): The output signal $Y_n$.
Examples:
>>> np.random.seed(1)
>>> awgn = komm.AWGNChannel(signal_power=5.0, snr=200.0)
>>> x = [1.0, 3.0, -3.0, -1.0, -1.0, 1.0, 3.0, 1.0, -1.0, 3.0]
>>> y = awgn(x); np.around(y, decimals=2) # doctest: +NORMALIZE_WHITESPACE
>>> y = awgn(x)
>>> np.around(y, decimals=2) # doctest: +NORMALIZE_WHITESPACE
array([ 1.26, 2.9 , -3.08, -1.17, -0.86, 0.64, 3.28, 0.88, -0.95, 2.96])
"""

Expand Down
11 changes: 8 additions & 3 deletions src/komm/_channels/BinaryErasureChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ class BinaryErasureChannel(DiscreteMemorylessChannel):
$$
where the parameter $\epsilon$ is called the *erasure probability* of the channel. For more details, see <cite>CT06, Sec. 7.1.5</cite>.
To invoke the channel, call the object giving the input signal as parameter (see example below).
Attributes:
erasure_probability (Optional[float]): The channel erasure probability $\epsilon$. Must satisfy $0 \leq \epsilon \leq 1$. Default value is `0.0`, which corresponds to a noiseless channel.
Parameters: Input:
in0 (Array1D[int]): The input sequence.
Parameters: Output:
out0 (Array1D[int]): The output sequence.
Examples:
>>> np.random.seed(1)
>>> bec = komm.BinaryErasureChannel(0.1)
>>> bec.transition_matrix
array([[0.9, 0. , 0.1],
[0. , 0.9, 0.1]])
>>> x = [1, 1, 1, 0, 0, 0, 1, 0, 1, 0]
>>> y = bec(x); y
>>> y = bec(x)
>>> y
array([1, 1, 2, 0, 0, 2, 1, 0, 1, 0])
"""

Expand Down
11 changes: 8 additions & 3 deletions src/komm/_channels/BinarySymmetricChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@ class BinarySymmetricChannel(DiscreteMemorylessChannel):
$$
where $Z_n$ are iid Bernoulli random variables with $\Pr[Z_n = 1] = p$. For more details, see <cite>CT06, Sec. 7.1.4</cite>.
To invoke the channel, call the object giving the input signal as parameter (see example below).
Attributes:
crossover_probability (Optional[float]): The channel crossover probability $p$. Must satisfy $0 \leq p \leq 1$. The default value is `0.0`, which corresponds to a noiseless channel.
Parameters: Input:
in0 (Array1D[int]): The input sequence.
Parameters: Output:
out0 (Array1D[int]): The output sequence.
Examples:
>>> np.random.seed(1)
>>> bsc = komm.BinarySymmetricChannel(0.1)
>>> bsc.transition_matrix
array([[0.9, 0.1],
[0.1, 0.9]])
>>> x = [0, 1, 1, 1, 0, 0, 0, 0, 0, 1]
>>> y = bsc(x); y
>>> y = bsc(x)
>>> y
array([0, 1, 0, 1, 0, 1, 0, 0, 0, 1])
"""

Expand Down
11 changes: 8 additions & 3 deletions src/komm/_channels/DiscreteMemorylessChannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ class DiscreteMemorylessChannel:
r"""
Discrete memoryless channel (DMC). It is defined by an *input alphabet* $\mathcal{X}$, an *output alphabet* $\mathcal{Y}$, and a *transition probability matrix* $p_{Y \mid X}$. Here, for simplicity, the input and output alphabets are always taken as $\mathcal{X} = \\{ 0, 1, \ldots, |\mathcal{X}| - 1 \\}$ and $\mathcal{Y} = \\{ 0, 1, \ldots, |\mathcal{Y}| - 1 \\}$, respectively. The transition probability matrix $p_{Y \mid X}$, of size $|\mathcal{X}|$-by-$|\mathcal{Y}|$, gives the conditional probability of receiving $Y = y$ given that $X = x$ is transmitted. For more details, see <cite>CT06, Ch. 7</cite>.
To invoke the channel, call the object giving the input signal as parameter (see example below).
Attributes:
transition_matrix (Array2D[float]): The channel transition probability matrix $p_{Y \mid X}$. The element in row $x \in \mathcal{X}$ and column $y \in \mathcal{Y}$ must be equal to $p_{Y \mid X}(y \mid x)$.
Parameters: Input:
in0 (Array1D[int]): The input sequence.
Parameters: Output:
out0 (Array1D[int]): The output sequence.
Examples:
>>> np.random.seed(1)
>>> dmc = komm.DiscreteMemorylessChannel([[0.9, 0.05, 0.05], [0.0, 0.5, 0.5]])
>>> x = [0, 1, 0, 1, 1, 1, 0, 0, 0, 1]
>>> y = dmc(x); y
>>> y = dmc(x)
>>> y
array([0, 2, 0, 1, 1, 1, 0, 0, 0, 2])
"""

Expand Down

0 comments on commit 5d4d4ea

Please sign in to comment.