Skip to main content
. 2022 Oct 1;24(10):1400. doi: 10.3390/e24101400
Listing A5: Calculate symbolically the Kullback–Leibler divergence and the Bhattacharyya coefficient between a half normal distribution and an exponential distribution.
  • assume(sigma>0);

  • halfnormal(x,sigma):=(sqrt(2)/(sqrt(%pi*sigma**2)))*exp(-x**2/(2*sigma**2));

  • assume(lambda>0);

  • exponential(x,lambda):=lambda*exp(-lambda*x);

  • /* KLD diverges */

  • integrate(exponential(x,lambda)*log(exponential(x,lambda)/halfnormal(x,sigma)),x,0,inf);

  • /* KLD converges */

  • integrate(halfnormal(x,sigma)*log(halfnormal(x,sigma)/exponential(x,lambda)),x,0,inf);

  • /* Bhattacharyya coefficient */

  • assume(alpha>0);

  • assume(alpha<1);

  • integrate( (halfnormal(x,sigma)**alpha) * (exponential(x,lambda)**(1-alpha)),x,0,inf);