komm.DiscreteMemorylessSource
Discrete memoryless source. It is defined by a finite source alphabet $\mathcal{X}$ and a pmf $p$ over $\mathcal{X}$. The value of $p(x)$ gives the probability of the source emitting symbol $x \in \mathcal{X}$, with the probability of emitting a symbol being independent of all previously emitted symbols. Here, for simplicity, the alphabet is taken as $\mathcal{X} = [0 : |\mathcal{X}|)$, where $|\mathcal{X}|$ is called the source cardinality.
Parameters:
-
pmf
(ArrayLike | int
) –Either a one-dimensional array of floats representing the source pmf $p$, or a positive integer $M$, in which case a uniform pmf over $[0 : M)$ is assumed.
Note
The cardinality $|\mathcal{X}|$ is inferred from the length of the pmf
array.
pmf
Array1D[floating]
cached
property
The source pmf $p$ over $\mathcal{X}$.
Examples:
>>> source = komm.DiscreteMemorylessSource([1/2, 1/4, 1/8, 1/8])
>>> source.pmf
array([0.5 , 0.25 , 0.125, 0.125])
>>> source = komm.DiscreteMemorylessSource(4)
>>> source.pmf
array([0.25, 0.25, 0.25, 0.25])
cardinality
int
cached
property
The source cardinality $|\mathcal{X}|$.
Examples:
>>> source = komm.DiscreteMemorylessSource([1/2, 1/4, 1/8, 1/8])
>>> source.cardinality
4
>>> source = komm.DiscreteMemorylessSource(4)
>>> source.cardinality
4
entropy_rate()
Computes the source entropy rate. For a discrete memoryless source, this is simply the entropy of the pmf $p$.
Parameters:
-
base
(float | Literal['e']
) –See
komm.entropy
. The default value is2.0
.
Returns:
-
entropy_rate
(floating
) –The source entropy rate.
Examples:
>>> source = komm.DiscreteMemorylessSource([1/2, 1/4, 1/8, 1/8])
>>> source.entropy_rate()
np.float64(1.75)
>>> source.entropy_rate(base=4)
np.float64(0.875)
>>> source = komm.DiscreteMemorylessSource(4)
>>> source.entropy_rate()
np.float64(2.0)
>>> source.entropy_rate(base=4)
np.float64(1.0)
emit()
Returns random symbols from the source.
Parameters:
-
shape
(tuple[int, ...] | int | None
) –The shape of the output array. The default value corresponds to a single symbol.
Returns:
-
symbols
(NDArray[integer]
) –The emitted symbols from the source. It is an array with elements in $\mathcal{X}$ and the given shape.
Examples:
>>> source = komm.DiscreteMemorylessSource([1/2, 1/4, 1/8, 1/8])
>>> source.emit()
array([2])
>>> source.emit(10)
array([0, 2, 1, 0, 3, 2, 2, 0, 0, 0])
>>> source.emit((2, 5))
array([[3, 1, 2, 0, 0],
[1, 0, 2, 1, 2]])