![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=1739259453-LplIbWpl6wNYFVib3MK5wVJltL90ElOd-0-f033ab2edc30fa4d76281379c68e4d88)
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=1739259453-povmrwtY9RnUa41d8rABm8jnmp62eqae-0-2ce634dbad61aed535efcedad207347d)
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