changeset 14:1d8ae1c1ee2f

test THEN commit...
author samer
date Sun, 26 Feb 2012 23:17:29 +0000
parents c0e75adddc95
children a6d5597bd922
files private/mc_global_info1.m
diffstat 1 files changed, 30 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/private/mc_global_info1.m	Sun Feb 26 23:15:59 2012 +0000
+++ b/private/mc_global_info1.m	Sun Feb 26 23:17:29 2012 +0000
@@ -1,4 +1,3 @@
-function [Info,ergodic]=mc_global_info1(T,tol)
 % mc_global_info1 - Three global information measures about stationary MC
 %
 % mc_global_info1 :: 
@@ -11,44 +10,45 @@
 %    Redundancy I(X,Z)
 %    Predictive information rate I(X,Y|Z)
 % All in NATS, not bits.
+function [Info,ergodic]=mc_global_info1(T,tol)
 
+	n=size(T,1);
+	pz=mc_fixpt(T,tol); 
+	ergodic=(size(pz,2)==1);
+	if ergodic && all(isfinite(pz))
 
-n=size(T,1);
-pz=mc_fixpt(T,tol); 
-ergodic=(size(pz,2)==1);
-if ergodic && all(isfinite(pz))
+		TlogT=T.*slog(T);
+		HXZ=-sum(TlogT,1)*pz;
 
-	TlogT=T.*slog(T);
-	HXZ=-sum(TlogT,1)*pz;
+		pxz=T; % p(x|z)
+		pyxz=repmat(T,[1,1,n]).*repmat(shiftdim(T,-1),[n,1,1]); % p(y,x|z)
+		pyz=sum(pyxz,2); % p(y|z)
+		pyz(pyz==0)=realmin;
+		pxyz=permute(pyxz./repmat(pyz,[1,n,1]),[2,1,3]); % p(x|y,z)
 
-	pxz=T; % p(x|z)
-	pyxz=repmat(T,[1,1,n]).*repmat(shiftdim(T,-1),[n,1,1]); % p(y,x|z)
-	pyz=sum(pyxz,2); % p(y|z)
-	pyz(pyz==0)=realmin;
-	pxyz=permute(pyxz./repmat(pyz,[1,n,1]),[2,1,3]); % p(x|y,z)
+		HXYz=-shiftdim(sum(sum(permute(pyxz,[2,1,3]).*slog(pxyz),1),2),2); % H(X|Y,z)
+		IXYZ=(-HXYz' - sum(pxz.*slog(pxz)))*pz;
 
-	HXYz=-shiftdim(sum(sum(permute(pyxz,[2,1,3]).*slog(pxyz),1),2),2); % H(X|Y,z)
-	IXYZ=(-HXYz' - sum(pxz.*slog(pxz)))*pz;
+		IXZ=max(0,(sum(TlogT)-slog(pz)')*pz); 
 
-	IXZ=max(0,(sum(TlogT)-slog(pz)')*pz); 
 
-
-	Info=[HXZ;IXZ;IXYZ];
-	if any(~isreal(Info))
-		disp('unreal information');
-		ergodic=0;
-	elseif any(Info<0)
-		if any(Info<-eps)
-			disp('negative information');
-			disp(pz');
-			disp(Info');
+		Info=[HXZ;IXZ;IXYZ];
+		if any(~isreal(Info))
+			disp('unreal information');
 			ergodic=0;
-		else
-			Info=max(0,Info);
+		elseif any(Info<0)
+			if any(Info<-eps)
+				disp('negative information');
+				disp(pz');
+				disp(Info');
+				ergodic=0;
+			else
+				Info=max(0,Info);
+			end
 		end
+	else
+		Info=[0;0;0];
 	end
-else
-	Info=[0;0;0];
 end
 
 function y=slog(x)
@@ -58,6 +58,7 @@
 
 	x(x<=0)=1;
 	y=log(x);
+end
 
 % mc_fixpt - fixed point(s) of Markov chain (stationary state distribution)
 %