Repository navigation
(ENH) Extend functions for Markov classes to deal with non-ergodic Markov chains - #109
Conversation
…reducible Markov chains.
There was a problem hiding this comment.
Not sure if this matters since I'm not a maintainer, but I've got some feedback given I've been tagged. My main concerns are:
- why are we not filling empty states by default?
- we should use clearer language than
fill_diagonal, since this has a pretty different meaning elsewhere.
| [0. , 0. , 0. , 0. , 1. ]]) | ||
| >>> sm.S[2] | ||
| array([0.03607655, 0.22667277, 0.25883041, 0.43607249, 0.04234777]) | ||
|
|
There was a problem hiding this comment.
Given this discussion, shouldn't we always fill the empty states? i.e. shouldn't this always be True?
There was a problem hiding this comment.
Two reasons not filling empty states by default:
- Right now, the tests for spatial dependence in the Markov chain model actually ignore the rows full of 0 estimates. If we fill empty states by default, it could have significant implications to these tests.
- Users might want to know where they have no observations.
Although the returned estimated transition probability matrix could have rows full of 0, when estimating the steady state distributions (for absorbing Markov chains) and first mean passage times, internally the transition probability matrix is adjusted so that it is stochastic - otherwise, it would not be possible to estimate them https://github.com/weikang9009/giddy/blob/limiting/giddy/markov.py#L226
|
oh yeah I also should say, this is great, and really significant that it's added 😄 I'm really glad to see this issue being addressed. |
|
The current implementation for first mean passage times cannot properly deal with absorbing Markov chains like: P = np.array([[1, 0,0,0,0],
[0,1,0,0,0],
[0, 0,0,0.5, 0.5],
[0,0.5,0, 0, 0.5],
[0.5,0, 0, 0.5, 0]])where 0 and 1 are absorbing states and 2,3 and 4 are transient states. |
Can you say a little more about what "cannot properly" means here? |
P = np.array([[1. , 0. , 0. , 0. , 0. ],
[0. , 1. , 0. , 0. , 0. ],
[0. , 0. , 0. , 0.5, 0.5],
[0. , 0.5, 0. , 0. , 0.5],
[0.5, 0. , 0. , 0.5, 0. ]])The Markov chain with transition probability matrix array([[1. , inf, inf, inf, inf],
[ inf, 1. , inf, inf, inf],
[ inf, inf, 1. , inf, inf],
[ inf, inf, inf, 2. , 1.33333333],
[ inf, inf, inf, 1.33333333, 2. ]])However, it is obvious that it is quite possible to pass from state 4 to 0, and once 0 is reached, the system will stay there forever. Therefore, the fmpt[4,0] should not be infinite and the current implementation is unable to deal with such Markov chains. The reason is that this is an absorbing Markov chain in which 2,3 and 4 are transient states and 0 and 1 are absorbing states. Since the communicating classes [2] and [3,4] contain transient states, the function We need to draw on the absorbing chain theory to deal with such Markov chains in addition to the current implementation which can only deal with reducible Markov chains with multiple communicating classes full of ergodic sets. |
|
I have enhanced the current methods for estimating steady state distributions and first mean passage times for ergodic Markov chains only to be able to deal with non-ergodic Markov chains (e.g. have multiple communicating classes, absorbing states).
|
This PR is to extend functions for Markov classes to deal with non-ergodic Markov chains.
Instead of changing the behavior of existing functions like
giddy.ergodic.steady_stateandgiddy.ergodic.fmptwhich explicitly claim that they are only suitable for regular Markov chain, I added two functions:giddy.ergodic.steady_state_generalgiddy.ergodic.fmpt_generalwhich could deal with reducible Markov chains. For instance, if the Markov chain has two communicating classes,
giddy.ergodic.steady_state_generalwill return an array of two vectors (see here for an example in the inline docstring.), andgiddy.ergodic.fmpt_generalwill return an array which containsnp.infsince it is impossible to get a state in class 1 if the system starts at a state in class 2 (see [here] for an example in the inline docstring.).These two functions replace
giddy.ergodic.steady_stateandgiddy.ergodic.fmptin classesMarkov,Spatial_Markov,FullRank_MarkovandGeoRank_Markovfor estimating the steady state distributions and first mean passage times (spatially conditional or not).Another enhancement is adding an optional parameter
fill_diagto each of these Markov related classes to allow users to determine whether a stochastic transition probability matrix (each row summing to 1) is desired.