I’m new in Python and I’m trying to see the normalized mutual information between 2 different signals, and no matter what signals I use, the result I obtain is always 1, which I believe it’s impossible because the signals are different and not totally correlated.
I’m using the Normalized Mutual Information Function provided Scikit Learn: sklearn.metrics.normalized mutualinfo_score(labels_true, labels_pred).
Here’s the code I’m using:
from numpy.random import randn
from numpy import *
from matplotlib.pyplot import *
from sklearn.metrics.cluster import normalized_mutual_info_score as mi
import pandas as pd
def fzX(X):
''' z-scoring columns'''
if len(X.shape)>1:
'''X is matrix ... more vars'''
meanX=mean(X,0)
stdX=std(X,0)
stdX[stdX<1e-9]=0
zX=zeros(X.shape)
for i in range(X.shape[1]):
if stdX[i]>0:
zX[:,i]=(X[:,i]-meanX[i])/stdX[i]
else:
zX[:,i]=0
else:
'''X is vector ... more vars'''
meanX=mean(X)
stdX=std(X,0)
zX=(X-meanX)/stdX
return(zX,meanX,stdX)
def fMI(X):
'''vars in columns,
returns mut info of normalized data'''
zX,meanX,stdX=fzX(X)
n=X.shape[1]
Mut_Info=zeros((n,n))
for i in range(n):
for j in range(i,n):
Mut_Info[i,j]=mi(zX[:,i],zX[:,j])
Mut_Info[j,i]=Mut_Info[i,j]
plot(zX);show()
return(Mut_Info)
t=arange(0,100,0.1) # t=0:0.1:99.9
N=len(t) # number of samples in t
u=sin(2*pi*t)+(randn(N)*2)**2
y=(cos(2*pi*t-2))**2+randn(N)*2
X=zeros((len(u),2))
X[:,0]=u
X[:,1]=y
mut=fMI(X)
print mut
plot(X)
show()
Did anyone of you have similar problem before? Do you know what I’m doing wrong?
Thank you very much in advance for your dedicated time.