Skip to main content

Module markov

Expand description

Discrete-time Markov chain core.

Implements transition-matrix validation, stationary-distribution power iteration, deterministic seeded simulation, and mean first-passage-time solves. Part of the QualiaDB computational economics library (plan §5.3 / P3).

§Allocation class: HotZeroHeap

Every public kernel operates on caller-owned slices and fixed-capacity stack arrays ([0.0f64; MAX_STATES]). No Vec, String, or Box is constructed on the hot path. The only heap traffic is whatever the caller chose to allocate for the input/output buffers.

§Assumptions

stationary_distribution_into assumes the chain is ergodic (aperiodic and irreducible). Power iteration converges to the unique stationary distribution only under that assumption; otherwise the kernel returns MarkovError::NonConverged once the iteration budget is exhausted.

mean_first_passage_time_into likewise assumes the target state is reachable from every other state (irreducibility); unreachable states produce divergent hitting times and surface as NonConverged.

Enums§

MarkovError
Markov-chain kernel error.

Constants§

MAX_STATES
Maximum number of states supported by the stack-array kernels.

Functions§

expected_holding_time
Expected holding time for state: 1 / (1 - P[state][state]).
mean_first_passage_time_into
Iterative solve for the mean first-passage time to target.
simulate_chain_into
Deterministic seeded simulation of a Markov chain.
stationary_distribution_into
Compute the stationary distribution of an ergodic Markov chain via power iteration: pi_{t+1} = pi_t * P.
transition_probability
Look up P[from][to] with bounds checking.
validate_transition_matrix
Validate that p is a row-stochastic n x n transition matrix.