All problems
Markov Chain Mixing Rate
Problem
Return the mixing rate of a 2x2 row-stochastic matrix P: the absolute value of its second eigenvalue.
One eigenvalue is always 1, so the second is trace(P) - 1 and the mixing rate is |trace(P) - 1|.
Hint
A smaller mixing rate means faster convergence to the stationary distribution.
Test cases
case 1
in: [[[0.5,0.5],[1,0]]]
expected: 0.5
case 2
in: [[[0.9,0.1],[0.3,0.7]]]
expected: 0.6
case 3
in: [[[1,0],[0,1]]]
expected: 1
case 4
in: [[[0.5,0.5],[0.5,0.5]]]
expected: 0
Starter codePython
def markov_mixing_rate(P):
# Your code here
pass4 test cases · run your code against them in the editor