1
$\begingroup$
import numpy as np
from scipy.stats import norm


a_values = np.random.normal(0,0.3,100)

b_values = np.random.uniform(-0.7,0.2, 100)

a_pdf = norm.pdf(a_values)
b_pdf = norm.pdf(b_values)

kl_divergence = np.sum(a_pdf*(np.log(a_pdf/b_pdf)))

print(kl_divergence)

I would like to ask if this is a proper way to calculate kl divergence with cont. random variables? a_pdf and b_pdf are probability density functions.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.