Skip to contents

Renormalises both inputs to sum to one and returns \(\sum_i p_i \log(p_i / q_i)\) in nats, restricted to the support of p. Zeros in q are floored at 1e-300 rather than returning Inf, so the result is always finite.

Usage

morie_gh_kl(p, q)

Arguments

p

numeric vector of non-negative weights (the reference measure); renormalised internally

q

numeric vector of non-negative weights on the same support; renormalised internally

Value

numeric scalar divergence in nats

Examples

V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_gh_kl(V, V)
#> [1] 0