Created
April 4, 2023 15:46
-
-
Save cmoog/13e1b001fb77d83e183bb9621f54a09d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LinearAlgebra | |
# A utility for computing the unique invariant probability | |
# vector for a finite, time homogeneous, irreducible, and aperiodic Markov chain | |
# from its transition probability matrix. | |
function invariantProb(P) | |
PT = transpose(P) | |
left_eigenvectors = nullspace(PT - I) | |
normalized_left_eigenvector = left_eigenvectors[:, 1] / sum(left_eigenvectors[:, 1]) | |
return normalized_left_eigenvector | |
end | |
# A utility for computing expected step behavior | |
# of a transient communication class in a finite, time homogeneous | |
# Markov chain. | |
function subStochasticM(Q) | |
return inv(I - Q) | |
end | |
P = [ | |
0 1/2 1/2 0; | |
1/2 0 0 1/2; | |
1/2 0 0 1/2; | |
0 1/2 1/2 0; | |
] | |
p = invariantProb(P) | |
println(p) | |
Q = [ | |
1/3 2/3 0 0; | |
1/4 1/2 1/4 0; | |
1/4 1/4 1/4 1/4; | |
1/4 0 1/4 1/4; | |
] | |
M = subStochasticM(Q) | |
println(sum(M[:, 1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment