Skip to content
DeepForgeby svx
All problems
HardLinear Algebrala-178

Markov Stationary Distribution

Problem

Estimate the stationary distribution of a row-stochastic matrix P by power iteration.

Start with the uniform row vector v = [1/n, ..., 1/n] and repeat v = v*P for num_iterations steps. Return the final row vector.

Hint

Stationary distributions satisfy v*P = v, which power iteration converges to for nice chains.

Test cases

case 1
in: [[[0.5,0.5],[1,0]],50]
expected: [0.6666666666666667,0.3333333333333333]
case 2
in: [[[0,1],[1,0]],10]
expected: [0.5,0.5]
case 3
in: [[[1,0],[0,1]],5]
expected: [0.5,0.5]
case 4
in: [[[0.9,0.1],[0.3,0.7]],50]
expected: [0.75,0.25]
Starter codePython
def stationary_distribution(P, num_iterations):
    # Your code here
    pass

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