comparison private/mc_fixpt.m @ 0:be936975f254

Initial check in.
author samer
date Wed, 01 Feb 2012 14:06:37 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:be936975f254
1 function p=mc_fixpt(Pt)
2 % mc_fixpt - fixed point of Markov chain (stationary state distribution)
3 %
4 % mc_fixpt :: [[K,K]]~'transition matrix'-> [[K]].
5
6
7 % for ergodic HMM we want to get stationary distribution
8 % use eigenvalues of transition matrix.
9 [V,D]=eig(Pt);
10
11 % one of the eigenvalues should be 1
12 [dummy,k]=max(-abs(diag(D)-1));
13
14 % check that it is really close
15 if abs(D(k,k)-1)>0.001
16 disp('mc_fixpt: failed to find eigenvalue of 1 in ');
17 disp(Pt)
18 error('mc_fixpt:noeig','failed to find eigenvalue of 1');
19 end
20
21 % get eigenvector and flip it over if all negative
22 v=V(:,k); if sum(v)<0, v=-v; end
23
24 if ~isreal(v)
25 disp('mc_fixpt: discarding complex parts of eigenvector');
26 v=real(v);
27 end
28 if any(v<0)
29 %fprintf('mc_fixpt: discarding negative parts of eigenvector: %s\n',mat2str(v(v<0)));
30 v=max(0,v);
31 end
32
33 % final normalisation
34 p=v/sum(v);