![Hands-On Markov Models with Python](https://wfqqreader-1252317822.image.myqcloud.com/cover/405/36699405/b_36699405.jpg)
上QQ阅读APP看书,第一时间看更新
Absorbing states
State i is said to be an absorbing state if it is impossible for a system to leave that state once it reaches it. For a state to be an absorbing state, the probability of staying in the same state should be 1, and all the other probabilities should be 0:
![](https://epubservercos.yuewen.com/EB2BC1/19470388308856506/epubprivate/OEBPS/Images/09d3d7e8-7bed-43c4-aaed-c50658b6e009.png?sign=1739031016-ReejAxYW3Lbgn1EBKGcnQXasLG6q45cU-0-9936e92954a837cc8e5972c8fbbfc325)
In a Markov chain, if all the states are absorbing, then we call it an absorbing Markov chain:
![](https://epubservercos.yuewen.com/EB2BC1/19470388308856506/epubprivate/OEBPS/Images/ed11565f-4c97-40c8-b946-587c3d705b3a.png?sign=1739031016-IpxKdAgNGvRxKlM7nBU7KJsAJu6yu5qg-0-f7747f4c8666fe0e1fe7c2bdf8bfee6a)
Figure 1.7: An example showing an absorbing state C, since the probability of transitioning from state C to C is 1
Again, we can add a very simple method to check for absorbing states in our MarkovChain class:
def is_absorbing(self, state):
"""
Checks if the given state is absorbing.
Parameters
----------
state: str
The state for which we need to check whether it's absorbing
or not.
"""
state_index = self.index_dict[state]
if self.transition_matrix[state_index, state_index]
We can again check whether our state in the example is absorbing by creating a Markov chain and using the is_absorbing method:
>>> absorbing_matrix = [[0, 1, 0],
[0.5, 0, 0.5],
[0, 0, 1]]
>>> absorbing_chain = MarkovChain(transition_matrix=absorbing_matrix,
states=['A', 'B', 'C'])
>>> absorbing_chain.is_absorbing('A')
False
>>> absorbing_chain.is_absorbing('C')
True