LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
EmpiricalRelativeEntropy.m
1% re = EmpiricalRelativeEntropy(f1, f2, intBounds)
2%
3% Returns the relative entropy (aka Kullback–Leibler
4% divergence) of two continuous functions given by samples
5% and the bounds of the corresponding intervalls.
6%
7% This function can be used to characterize the distance
8% between two density functions, distribution functions,
9% etc.
10%
11% Parameters
12% ----------
13% f1 : vector, length M
14% Samples of the first continuous function
15% f2 : vector, length M
16% Samples of the second continuous function
17% intBounds : vector, length M+1
18% The bounds of the intervals. The ith sample
19% corresponds to the interval
20% (intbounds(i),intbounds(i+1))
21%
22% Returns
23% -------
24% re : double
25% The relative entropy
26
27function re = EmpiricalRelativeEntropy (f1, f2, intBounds)
28
29 intlens = intBounds(2:end) - intBounds(1:end-1);
30 intlens = reshape(intlens, size(f1));
31 p1 = f1 .* intlens;
32 p2 = f2 .* intlens;
33 re = RelativeEntropy (p1, p2);
34end
35