Skip to content

Instantly share code, notes, and snippets.

@colobas
Last active July 23, 2017 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colobas/56f1d8b067d4c050d607d26800218263 to your computer and use it in GitHub Desktop.
Save colobas/56f1d8b067d4c050d607d26800218263 to your computer and use it in GitHub Desktop.
matrix of mutual information
import numpy as np
from sklearn.metrics import mutual_info_score
def calc_MI(x, y, bins):
c_xy = np.histogram2d(x, y, bins)[0]
mi = mutual_info_score(None, None, contingency=c_xy)
return mi
def calc_MI_matrix(A, bins)
n = A.shape[1]
matMI = np.zeros((n, n))
for ix in np.arange(n):
for jx in np.arange(ix+1,n):
matMI[ix,jx] = calc_MI(A[:,ix], A[:,jx], bins)
return matMI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment