Last active
July 23, 2017 09:09
-
-
Save colobas/56f1d8b067d4c050d607d26800218263 to your computer and use it in GitHub Desktop.
matrix of mutual information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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