samer@11: function [Info,ergodic]=mc_global_info(T,pz) samer@0: % mc_global_info - Three global information measures about stationary MC samer@0: % samer@0: % mc_global_info :: [[N,N]] ~'transmat' -> [[3]]. samer@0: % samer@0: % mc_global_info :: samer@0: % [[N,N]] ~'transmat', samer@0: % [[N]] ~'stationary distribution if already known' samer@11: % -> [[3]],bool. samer@0: % samer@0: % The three measures in order are samer@0: % Entropy rate H(X|Z) samer@0: % Redundancy I(X,Z) samer@0: % Predictive information rate I(X,Y|Z) samer@7: % All in NATS, not bits. samer@0: samer@0: samer@0: n=size(T,1); samer@11: if nargin<2, pz=mc_fixpt(T,0.001); end samer@0: samer@11: ergodic=(size(pz,2)==1); samer@11: if ergodic && all(isfinite(pz)) samer@0: samer@11: TlogT=T.*slog(T); samer@11: HXZ=-sum(TlogT,1)*pz; samer@0: samer@11: pxz=T; % p(x|z) samer@11: pyxz=repmat(T,[1,1,n]).*repmat(shiftdim(T,-1),[n,1,1]); % p(y,x|z) samer@11: pyz=sum(pyxz,2); % p(y|z) samer@11: pyz(pyz==0)=realmin; samer@11: pxyz=permute(pyxz./repmat(pyz,[1,n,1]),[2,1,3]); % p(x|y,z) samer@0: samer@11: HXYz=-shiftdim(sum(sum(permute(pyxz,[2,1,3]).*slog(pxyz),1),2),2); % H(X|Y,z) samer@11: IXYZ=(-HXYz' - sum(pxz.*slog(pxz)))*pz; samer@0: samer@11: IXZ=max(0,(sum(TlogT)-slog(pz)')*pz); samer@11: samer@11: samer@11: Info=[HXZ;IXZ;IXYZ]; samer@11: if any(~isreal(Info)) samer@11: disp('unreal information'); samer@11: ergodic=0; samer@11: elseif any(Info<0) samer@11: if any(Info<-eps) samer@11: disp('negative information'); samer@11: disp(pz'); samer@11: disp(Info'); samer@11: ergodic=0; samer@11: else samer@11: Info=max(0,Info); samer@11: end samer@0: end samer@11: else samer@11: Info=[0;0;0]; samer@0: end samer@0: samer@0: function y=slog(x) samer@0: % slog - safe log, x<=0 => slog(x)=0 samer@0: % samer@0: % slog :: real -> real. samer@0: samer@0: x(x<=0)=1; samer@0: y=log(x); samer@0: