view private/mc_fixpt.m @ 9:cc549aca4ea6

Added optional shuffling of Markov chain symbols.
author samer
date Mon, 20 Feb 2012 13:39:30 +0000
parents be936975f254
children
line wrap: on
line source
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);