

def jensen_renyi(xx, xy, yy, yx, alphas, Ks, dim, clamp=True, **opts):
    '\n    Estimate the Jensen-Renyi divergence between distributions,\n        R_\\alpha((p + q)/2) - 1/2 R_\\alpha(p) - 1/2 R_\\alpha(q)\n    where R_\\alpha is the Renyi entropy:\n        1/(1 - \\alpha) \\log \\int p^\\alpha\n    which is estimated based on kNN distances.\n\n    Returns a matrix: each row corresponds to an alpha, each column to a K.\n    '
    if (xy is None):
        return np.zeros((len(alphas), len(Ks)))
    max_K = xx.shape[1]
    N = xx.shape[0]
    M = yy.shape[0]
    alphas = np.asarray(alphas)
    entropy = functools.partial(renyi_entropy_knns, dim=dim, alphas=alphas, Ks=Ks)
    if (N != M):
        raise ValueError("can't do jensen-renyi for nonequal sample sizes yet")
    mixture_toself = np.empty(((N + M), (2 * max_K)))
    mixture_toself[:N, :mixture_toself] = xx
    mixture_toself[:N, max_K:] = xy
    mixture_toself[N:, :max_K] = yy
    mixture_toself[N:, max_K:] = yx
    mixture_toself.sort(axis=1)
    mix_entropies = entropy(mixture_toself)
    x_entropies = entropy(xx)
    y_entropies = entropy(yy)
    ests = ((mix_entropies - (x_entropies / 2)) - (y_entropies / 2))
    return (np.maximum(ests, 0) if clamp else ests)

dataset/ETHPy150Open dougalsutherland/py-sdm/sdm/jensen_divs.py jensen_renyi/VarMisuse@159/377 `max_K`->`mixture_toself`