Mercurial > hg > trimatlab
diff private/mc_fixpt.m @ 0:be936975f254
Initial check in.
author | samer |
---|---|
date | Wed, 01 Feb 2012 14:06:37 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/private/mc_fixpt.m Wed Feb 01 14:06:37 2012 +0000 @@ -0,0 +1,34 @@ +function p=mc_fixpt(Pt) +% mc_fixpt - fixed point of Markov chain (stationary state distribution) +% +% mc_fixpt :: [[K,K]]~'transition matrix'-> [[K]]. + + +% for ergodic HMM we want to get stationary distribution +% use eigenvalues of transition matrix. +[V,D]=eig(Pt); + +% one of the eigenvalues should be 1 +[dummy,k]=max(-abs(diag(D)-1)); + +% check that it is really close +if abs(D(k,k)-1)>0.001 + disp('mc_fixpt: failed to find eigenvalue of 1 in '); + disp(Pt) + error('mc_fixpt:noeig','failed to find eigenvalue of 1'); +end + +% get eigenvector and flip it over if all negative +v=V(:,k); if sum(v)<0, v=-v; end + +if ~isreal(v) + disp('mc_fixpt: discarding complex parts of eigenvector'); + v=real(v); +end +if any(v<0) + %fprintf('mc_fixpt: discarding negative parts of eigenvector: %s\n',mat2str(v(v<0))); + v=max(0,v); +end + +% final normalisation +p=v/sum(v);