KLCMAT Kullback-Leibler distance of cycle matrix. comuptes the Kullback-Leibler distance between the observed cycle matrix Fobs and the expected cycle matrix F. The Kullback-Leibler distance is defined as K.L. = sum( f_ij * log(N*f_ij/N_ij) ) kl = klcmat(Fobs,F) Fobs = Observation of cycle matrix F = Expected cycle matrix
Auxiliary function used by ESTSMCTP |
01 function kl = klcmat(Fobs,F) 02 % KLCMAT Kullback-Leibler distance of cycle matrix. 03 % 04 % comuptes the Kullback-Leibler distance between the observed 05 % cycle matrix Fobs and the expected cycle matrix F. 06 % 07 % The Kullback-Leibler distance is defined as 08 % K.L. = sum( f_ij * log(N*f_ij/N_ij) ) 09 % 10 % kl = klcmat(Fobs,F) 11 % 12 % Fobs = Observation of cycle matrix 13 % F = Expected cycle matrix 14 15 F = flipud(F)'; % Convert to PJ-def 16 Fobs = flipud(Fobs)'; % Convert to PJ-def 17 18 n = length(F); 19 N = sum(sum(Fobs)); 20 21 F = F / sum(sum(F)); 22 23 FF = F(:); 24 FFobs = Fobs(:); 25 FI = find( (Fobs>0) & (F>0) ); 26 27 % Compute Kullback-Leibler distance 28 29 kl = sum( FF(FI) .* log(N*F(FI)./Fobs(FI)) ); 30 31
Comments or corrections to the WAFO group