For a row-stochastic transition matrix \(P\) and stationary distribution
\(\pi\), the entropy rate is
$$H = -\sum_i \pi_i \sum_j p_{ij}\log_b(p_{ij}),$$
with zero-probability transitions contributing zero by continuity.
For a stationary first-order Markov chain, the entropy rate equals the
conditional entropy \(H(X_{t+1}\mid X_t)\). Irreducibility guarantees a
unique stationary distribution; aperiodicity is not required.
Reducible chains may admit multiple stationary distributions and therefore
different entropy rates. This method rejects them rather than silently
selecting one stationary distribution.
Transitions with probability zero are ignored, implementing the standard
convention \(0\log(0)=0\) without evaluating log(0).
The stationary-distribution computation dominates the running time. Once
the stationary distribution is available, evaluating the entropy rate takes
\(O(n^2)\) time and \(O(n^2)\) temporary memory for a dense \(n\)-state
transition matrix.