learn_markov_chains

learn_markov_chains(n_units=100, n_periods=30, p=_DEFAULT_P, seed=0)

Plant a transition matrix, then watch the estimated chain recover it.

Simulates n_units independent chains from the planted row-stochastic p (started at its ergodic distribution), maps states to well-separated continuous values, and estimates the chain with :func:geometrics.analyze_markov_transitions using explicit class bins so the discretization is exact. The figure compares every estimated transition probability with its planted value; the summary reports the largest cell error and the ergodic-distribution error.

Requires the dynamics extra (pip install "geometrics[dynamics]").

Parameters

Name Type Description Default
n_units int Number of independent chains (entities). 100
n_periods int Chain length; n_units * (n_periods - 1) transitions are observed. 30
p tuple[tuple[float, …], …] The planted k x k row-stochastic transition matrix (k >= 2). _DEFAULT_P
seed int Random seed. 0

Returns

Name Type Description
SandboxResult df (one row per matrix cell, planted vs estimated), fig, summary, topic and the simulated panel in data.

Examples

import geometrics as gm

res = gm.learn_markov_chains(n_units=200)
print(res.summary["max_abs_error"])