Re: K-L Distance
- From: "carneym" <michael.carney@xxxxxxxxx>
- Date: 23 Sep 2005 10:00:46 -0700
Hi,
I wrote some code a while back in Matlab to calculate the KL for
Gaussian Mixture Models.
It's pretty crude but it works.
mix1 and mix2 are the mixture model distributions.
gmmprob returns the density at x.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
divergence = quad('kl_function', a, b, [], [], mix1, mix2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function y = kl_function(x, mix1, mix2)
%KL_FUNCTION - The interior of the KL integral
len = length(x);
y = zeros(1,len);
for i = 1:len
temp = gmmprob(mix1, x(i)).*log(gmmprob(mix1, x(i)) ./ gmmprob(mix2,
x(i)));;
if(isnan(temp) | isinf(temp))
warning('Integration Problem.')
y(i) = 0;
else
y(i) = temp;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Hope this helps.
M
.
- References:
- K-L Distance
- From: shahnoor
- K-L Distance
- Prev by Date: Re: General linear / mixed models
- Next by Date: Re: General linear / mixed models
- Previous by thread: Re: K-L Distance
- Next by thread: Computing Really Tiny p-values using Fisher's Exact Test
- Index(es):