Skip to content

Add ergodic chain summaries: sojourn_time(), first_passage(), mobility_index() - #2

Merged
dshkol merged 2 commits into
mainfrom
feature/ergodic-measures
Aug 2, 2026
Merged

Add ergodic chain summaries: sojourn_time(), first_passage(), mobility_index()#2
dshkol merged 2 commits into
mainfrom
feature/ergodic-measures

Conversation

@dshkol

@dshkol dshkol commented Jul 28, 2026

Copy link
Copy Markdown
Owner

First tranche of the 0.2.0 feature work: scalar and matrix summaries derived from transition probability matrices, extending the family steady_state() started.

New functions

  • sojourn_time() — expected consecutive periods in each class, 1/(1 - p_ii); Inf for absorbing classes
  • first_passage() — Kemeny–Snell mean first-passage times; diagonal is mean recurrence time 1/π; rejects non-ergodic chains with an informative error
  • mobility_index() — Prais–Shorrocks trace, determinant, Sommers–Conlisk eigenvalue, and both Bartholomew indices (Formby, Smith & Zheng 2004)

All are generics with grd_markov and default (matrix/table) methods, so they work both on fitted objects and on transition_matrix() output (including per-lag-class spatial matrices).

Validation

  • Exact agreement with PySAL giddy 2.3.9 (ergodic.mfpt, markov.sojourn_time, mobility.markov_mobility) on the usjoin classic Markov matrix; fixtures generated by the extended tools/oracle/pysal_giddy_oracle.py (existing fixtures regenerated byte-identical)
  • Oracle comparisons live in the Rbuildignored dev-only test file, per the existing fixture policy; shipped tests cover closed forms (2×2 analytic results), identity-matrix invariants, absorbing-state behaviour, and error paths
  • devtools::check(): 0 errors, 0 warnings, 0 notes

🤖 Generated with Claude Code

Ergodic chain summaries computed from grd_markov objects or raw
transition probability matrices:

- sojourn_time(): expected consecutive periods per class, 1/(1 - p_ii)
- first_passage(): Kemeny-Snell mean first-passage times
- mobility_index(): Prais-Shorrocks, determinant, Sommers-Conlisk
  eigenvalue, and Bartholomew mobility indices (Formby et al. 2004)

All three match PySAL giddy (ergodic.mfpt, markov.sojourn_time,
mobility.markov_mobility) exactly on the usjoin classic Markov matrix;
fixtures generated by tools/oracle/pysal_giddy_oracle.py with giddy
2.3.9 and compared in the dev-only oracle test file. Shipped tests
cover closed forms, invariants, and error paths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@dshkol
dshkol merged commit 501e49c into main Aug 2, 2026
6 checks passed
@dshkol
dshkol deleted the feature/ergodic-measures branch August 2, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant