Skip to content

feat: add Kemeny's constant - #261

Draft
spedygiorgio wants to merge 4 commits into
masterfrom
agent/quick-win-kemeny
Draft

feat: add Kemeny's constant#261
spedygiorgio wants to merge 4 commits into
masterfrom
agent/quick-win-kemeny

Conversation

@spedygiorgio

Copy link
Copy Markdown
Owner

Summary

  • add kemenyConstant() as an S4 method for markovchain objects
  • compute Kemeny's constant from the stationary distribution using a numerically preferable linear solve
  • add documentation, examples, and regression tests

Mathematical definition

For a finite irreducible chain, the implementation uses K = trace((I - P + 1 %*% t(pi))^{-1}) - 1, equivalent to the stationary-distribution-weighted mean first-passage formulation.

Implementation notes

No Rcpp is used: this quick win is dominated by dense linear algebra already provided by R/BLAS, and the implementation avoids an explicit matrix inverse.

Validation

  • analytical two-state example
  • invariance to starting state
  • one-state chain
  • rejection of reducible chains

Closes #255.

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.

Enhancement: add Kemeny's constant

1 participant