(x, y, z=1e-11)
return (kl1 + kl2) / 2
r"""
    symmetrized KL divergence between two probability distributions

    ..math::
        D(x, y) = \frac{D_{KL}\left(x \Vert y\right) + D_{KL}\left(y \Vert x\right)}{2}
r"""
    symmetrized KL divergence between two probability distributions
r symmetrized KL divergence between two probability distributions
def symmetric_kl(x, y, z=1e-11):  # pragma: no cover
    r"""
    symmetrized KL divergence between two probability distributions

    ..math::
        D(x, y) = \frac{D_{KL}\left(x \Vert y\right) + D_{KL}\left(y \Vert x\right)}{2}
    """
    n = x.shape[0]
    x_sum = 0.0
    y_sum = 0.0
    kl1 = 0.0
    kl2 = 0.0

    for i in range(n):
        x[i] += z
        x_sum += x[i]
        y[i] += z
        y_sum += y[i]

    for i in range(n):
        x[i] /= x_sum
        y[i] /= y_sum

    for i in range(n):
        kl1 += x[i] * np.log(x[i] / y[i])
        kl2 += y[i] * np.log(y[i] / x[i])

    return (kl1 + kl2) / 2
def symmetric_kl ( x , y , z = 1e-11 ) : # pragma: no cover n = x . shape [ 0 ] x_sum = 0.0 y_sum = 0.0 kl1 = 0.0 kl2 = 0.0 for i in range ( n ) : x [ i ] += z x_sum += x [ i ] y [ i ] += z y_sum += y [ i ] for i in range ( n ) : x [ i ] /= x_sum y [ i ] /= y_sum for i in range ( n ) : kl1 += x [ i ] * np . log ( x [ i ] / y [ i ] ) kl2 += y [ i ] * np . log ( y [ i ] / x [ i ] ) return ( kl1 + kl2 ) / 2