powered by
Analytical KL divergence for two discrete distributions
kld_discrete(P, Q)
A scalar (the Kullback-Leibler divergence)
Numerical arrays with the same dimensions, representing discrete probability distributions
# 1-D example P <- 1:4/10 Q <- rep(0.25,4) kld_discrete(P,Q) # The above example in 2-D P <- matrix(1:4/10,nrow=2) Q <- matrix(0.25,nrow=2,ncol=2) kld_discrete(P,Q)
Run the code above in your browser using DataLab