I read Markov’s cat and mouse model on wikipedia and decided to write Julia’s code to empirically confirm the analytical results:
P = [
0 0 0.5 0 0.5 ;
0 0 1 0 0 ;
0.25 0.25 0 0.25 0.25;
0 0 0.5 0 0.5 ;
0 0 0 0 1
]
prob_states = transpose([0.0, 1, 0, 0, 0])
prob_end = [0.0]
for i in 1:2000
prob_states = prob_states * P
prob_end_new = (1 - sum(prob_end)) * prob_states[end]
push!(prob_end, prob_end_new)
println("Ending probability: ", prob_end_new)
println("Cumulative: ", sum(prob_end))
end
println("Expected lifetime: ", sum(prob_end .* Array(1:2001)))
Here Pis the transition matrix, prob_statesis the probability distribution of states at each iteration, prob_endis the array of completion probabilities at each step (for example, prob_end[3]is the probability of completion at stage 3).
According to the result of this script, the expected mouse lifetime is about 4.3, and the analytical result is 4.5. The script makes sense to me, so I really don't know where it could go wrong. Can anyone help?
PS An increase in the number of iterations by an order of magnitude changes almost nothing.