Пример #1
0
def KL_normal(m1, sigma1, m2, sigma2):
    """
    Calculates the KL divergence between two normal distributions specified by
    N(``mu1``, ``sigma1``), N(``mu2``, ``sigma2``)
    """

    return 1. / 2. * (math.log(det(sigma2) / det(sigma1)) - len(m1) + trace(mdot(inv(sigma2), sigma1)) + \
    mdot((m2 - m1).T, inv(sigma2) , m2- m1))
Пример #2
0
def KL_normal(m1, sigma1, m2, sigma2):
    """
    Calculates the KL divergence between two normal distributions specified by
    N(``mu1``, ``sigma1``), N(``mu2``, ``sigma2``)
    """

    return 1. / 2. * (math.log(det(sigma2) / det(sigma1)) - len(m1) + trace(mdot(inv(sigma2), sigma1)) + \
    mdot((m2 - m1).T, inv(sigma2) , m2- m1))