kl.dist {seewave} | R Documentation |
Compare two distributions (e.g. two frequency spectra) by computing the Kullback-Leibler distance
kl.dist(spec1, spec2, base = 2)
spec1 |
any distribution, especially a spectrum obtained with |
spec2 |
any distribution, especially a spectrum obtained with
|
base |
the logarithm base used to compute the distance. See |
The Kullback-Leibler distance or relative entropy is a
non-symmetric measure of the difference between two probability
distributions. It is here adapted for frequency spectra. The distance
is asymmetric, ie computing the K-L distance between spec1 and spec2 is
not the same as computing it between spec2 and spec1. A symmetry can be
obtained by calculating the mean between the two directions.
The distance is obtained following:
D(spec1 || spec2) = sum(spec1 * log(spec1 / spec2))
The function returns a list of three items:
D1 |
The K-L distance of 'spec2' with respect to 'spec1' (i.e. D(spec1 || spec2)) |
D2 |
The K-L distance of 'spec1' with respect to 'spec2' (i.e. D(spec2 || spec1)) |
D |
The symmetric K-L distance (i.e. D = 0.5*(D1+D2)) |
The base of the logarithm can be changed using the argument
base
. When sets to base 2, the information is measured in units of
bits. When sets to base e, the information is measured in
nats.
The function works for both Hz and (htk-)mel scales.
Jerome Sueur, improved by Laurent Lellouch
Kullback, S., Leibler, R.A. (1951). On information and sufficiency. Annals of Mathematical Statistics, 22: 79-86
ks.dist
, logspec.dist
, simspec
, diffspec
# Comparison of two spectra data(tico) tico1 <- spec(tico, at=0.65, plot=FALSE) tico2 <- spec(tico, at=1.1, plot=FALSE) kl.dist(tico1, tico2) # log2 (binary logarithm) kl.dist(tico1, tico2, base=exp(1)) # ln (natural logarithm)