Last active
October 13, 2019 23:14
-
-
Save rileylev/1082517f4003b25d9acbab925632ca01 to your computer and use it in GitHub Desktop.
Calculates the mean hitting time of a state in a homogenous markov chain
This file contains 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
function K = fixedPoint(M) | |
[r c] = size(M); | |
assert(r==c); | |
I = eye(r); | |
K = -rref(I-M)(:,r); | |
K(r)=1; | |
assert(norm(M*K-K)<.0001*norm(K)); | |
end | |
function p = projectFromPRn(X) | |
assert(X(1)!=0); | |
X/=X(1); | |
p=X(2:end); | |
end | |
function k = meanHittingTime(P,destination) | |
[r c] = size(P); | |
assert(r==c); | |
N = r+1; | |
M = [ones(N,1) [zeros(1,r); P]]; | |
M(:,destination+1)=zeros(1,N); | |
k = projectFromPRn(fixedPoint(M)); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment