function [kl] = KL(p,q,Chk_q)
% KL returns the Kullbac-Leibler divergence, where:
% KL(p,q) = p*log(p/q)
p=0.6;
q=0.6;
Chk_q=0.5;
inds = find(p);
p = p(inds);
q = q(inds);
if Chk_q % not necessary when called from JS
if min(q)==0
kl=inf;
return
end
end
kl = sum(p.*log(p./q));
return
- 1
- 2
- 3
- 4
- 5
- 6
前往页