## Define two discrete probability distributions with equal lengths.
p <- c(0.1, 0.2, 0.3, 0.4)
q <- c(0.2, 0.5, 0.1, 0.2)
## Calculate the Kullback-Leibler divergence
## between the probability distributions p and q
kullback.leibler(p, q)
Run the code above in your browser using DataLab