All problems
Expected Hitting Time Three-State Chain
Problem
A three-state Markov chain has state 2 absorbing. Starting from start (0 or 1), the expected hitting time of state 2 solves (I - Q) E = 1 on the transient states 0 and 1. Solve the resulting 2x2 linear system and return E[start]. Return 0.0 when start is 2 and -1.0 for an invalid start or a singular system.
Hint
Write the two equations for E[0] and E[1] and solve with the 2x2 inverse.
Test cases
case 1
in: [[[0.5,0.5,0],[0.25,0.25,0.5],[0,0,1]],0]
expected: 5
case 2
in: [[[0.5,0.5,0],[0.25,0.25,0.5],[0,0,1]],1]
expected: 3
case 3
in: [[[0.2,0.3,0.5],[0.1,0.4,0.5],[0,0,1]],1]
expected: 2.0000000000000004
case 4
in: [[[1,0,0],[0,1,0],[0,0,1]],0]
expected: -1
case 5
in: [[[0.5,0.5,0],[0.25,0.25,0.5],[0,0,1]],2]
expected: 0
Starter codePython
def expected_hitting_time_three_state(matrix, start):
# Your code here
pass5 test cases · run your code against them in the editor