Skip to content
DeepForgeby svx
All problems

Stationary Distribution

Problem

Find the stationary distribution of a row-stochastic transition matrix by power iteration.

Start from the uniform distribution and repeatedly compute d = d * P until the largest component change is below tol, then renormalize. Return the limit reached from the uniform start.

Hint

Power iteration converges for any initial distribution when P is row-stochastic.

Test cases

case 1
in: [[[0.5,0.5],[1,0]]]
expected: [0.6666666669771075,0.3333333330228925]
case 2
in: [[[1,0],[0,1]]]
expected: [0.5,0.5]
case 3
in: [[[0,1],[1,0]]]
expected: [0.5,0.5]
case 4
in: [[[0.8,0.2],[0.3,0.7]]]
expected: [0.599999999254942,0.40000000074505804]
Starter codePython
def stationary_distribution(P, tol=1e-9):
    # Your code here
    pass

4 test cases · run your code against them in the editor