MATLAB Examples

Contents

% This function generates the KLD metric values for the given data and the
% inverse gaussian fitted data of itself.

% USE: [Kd]= kldcmpnormFivh1(Fivh1,dec)
% where Fivh1 -- is the Data set. It has to be a vector.
% dec --- is a variable set to eliminate the minimum value 0 in the
% probability estimates. Since this would lead to 'Inf' values because of
% the logarithm used in KLD.

% Written by
% --------------------------------------------------
% Doctorand M.Sc.-Ing Divyesh Varade
% Editorial Board NERD, IIT Kanpur
% Indian Institute of Technology,
% Geoinformatics Division,
% Department of Civil Engineering
% Kanpur-208016
% --------------------------------------------------



function [Kd]= kldcmpnorm(Fivh1,dec)
A = Fivh1;
B = invgaussfit(Fivh1); % Data induced after Gaussian Fitting.
nbins = size(A,1);
[n1] = hist(A(:),nbins);% Histogram
P1 = n1./numel(A); % Generating Probabilty Estimate from Histogram
[n2] = hist(B(:),nbins);
P2 = n2./numel(B);
P1(P1==0)= 1/dec;
P2(P2==0)= 1/dec;
temp = sum(P1 .* log(P1 ./ P2));
temp( isinf(temp) ) = 0; % this resloves where h1(i) == 0
d1 = sum(temp);
Error using kldcmpnorm (line 23)
Not enough input arguments.

Symmetric Evaluation of KLD

temp = sum(P2 .* log(P2 ./ P1)); % other direction of compare since it's not symetric
temp( isinf(temp) ) = 0;
d2 = sum(temp);
Kd = d1 + d2;