我是Python新手,我试图看到两个不同信号之间的标准化互信息,不管我使用什么信号,我得到的结果总是1,我认为这是不可能的,因为信号是不同的,不是完全相关的。
我使用的是Normalized Mutual Information Function provided Scikit Learn:sklearn.metrics.normalized mutanalinfo评分(labels为true,labels为pred)。
下面是我使用的代码: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()
你们以前有过类似的问题吗?你知道我做错了什么吗?
非常感谢您的奉献。