#### Previous topic

spatial_dynamics.markov – Markov based methods

#### Next topic

spatial_dynamics.rank – Rank and spatial rank mobility measures

# spatial_dynamics.ergodic – Summary measures for ergodic Markov chains¶

New in version 1.0.

## ergodic — summary measures for ergodic Markov chains¶

Calculates the steady state probability vector for a regular Markov transition matrix P

Parameters: P : matrix (kxk) an ergodic Markov transition probability matrix implicit : matrix (kx1) steady state distribution

Examples

Taken from Kemeny and Snell. [1]_ Land of Oz example where the states are Rain, Nice and Snow - so there is 25 percent chance that if it rained in Oz today, it will snow tomorrow, while if it snowed today in Oz there is a 50 percent chance of snow again tomorrow and a 25 percent chance of a nice day (nice, like when the witch with the monkeys is melting).

```>>> import numpy as np
>>> p=np.matrix([[.5, .25, .25],[.5,0,.5],[.25,.25,.5]])
matrix([[ 0.4],
[ 0.2],
[ 0.4]])
```

Thus, the long run distribution for Oz is to have 40 percent of the days classified as Rain, 20 percent as Nice, and 40 percent as Snow (states are mutually exclusive).

pysal.spatial_dynamics.ergodic.fmpt(P)

Calculates the matrix of first mean passage times for an ergodic transition probability matrix.

Parameters: P : matrix (kxk) an ergodic Markov transition probability matrix M : matrix (kxk) elements are the expected value for the number of intervals required for a chain starting in state i to first enter state j If i=j then this is the recurrence time.

References

 [R2] (1, 2) Kemeny, John, G. and J. Laurie Snell (1976) Finite Markov Chains. Springer-Verlag. Berlin

Examples

```>>> import numpy as np
>>> p=np.matrix([[.5, .25, .25],[.5,0,.5],[.25,.25,.5]])
>>> fm=fmpt(p)
>>> fm
matrix([[ 2.5       ,  4.        ,  3.33333333],
[ 2.66666667,  5.        ,  2.66666667],
[ 3.33333333,  4.        ,  2.5       ]])
```

Thus, if it is raining today in Oz we can expect a nice day to come along in another 4 days, on average, and snow to hit in 3.33 days. We can expect another rainy day in 2.5 days. If it is nice today in Oz, we would experience a change in the weather (either rain or snow) in 2.67 days from today. (That wicked witch can only die once so I reckon that is the ultimate absorbing state).

Notes —–

Uses formulation (and examples on p. 218) in Kemeny and Snell (1976) [R2]