def correlation(probs):
"""Compute correlation rho(X,Y) = sqrt(1 - exp(-2 I(X;Y))).
Args:
probs: An [M, M]-shaped numpy array representing a joint distribution.
Returns:
A number in [0,1) representing the information-theoretic correlation.
"""
assert len(probs.shape) == 2
assert probs.shape[0] == probs.shape[1]
mutual_information = (entropy(probs.sum(0)) + entropy(probs.sum(1)) -
entropy(probs.flatten()))
return np.sqrt(1.0 - np.exp(-2.0 * mutual_information))
评论列表
文章目录