My problem is as follows. I have Markov chain with several absorbing classes and I would like to determine which states in the state space are absorbing and which are transient. As a simple example, we could have the following sparse transition matrix, with on each row the transition probabilities of states 0,1,2,3.
import numpy as np
from scipy.sparse import csr_matrix,csgraph
P = np.array([[0.6,0.4,0.,0.],[0.3,0.7,0.,0.],[0.2,0.4,0.2,0.2],[0.,0.,0.,1.]])
P = csr_matrix(P)
Here, there are two absorbing classes: states 0-1 and state 3. State 2 is transient. Since there are classes of absorbing states, checking for probability 1 on the diagonal is not sufficient to identify the absorbing classes.
I'm wondering how I can programmatically identify the absorbing classes. Using tools from csgraph
, I can find the strongly connected components using
components,labels = csgraph.connected_components(P,connection="strong")
print( components, labels )
3 [0 0 2 1]
So, I have 3 components, each with their own labels. The absorbing classes correspond certainly to one of these components, but there are also transient components. How do I find out which component is absorbing and which is transient?
Does anyone have a nice idea for this?