困惑度计算
import pandas as pd
import math
data=pd.read_csv("D://h_conv1.csv",header=None)
list=data.values.tolist()
perlx=[]
for m in range(224):
for n in range(224):
average=[]
sum=0
su=0
per=0
for i in range(48):
sum=sum+list[i*225+m][n]
for i in range(48):
if(list[i*225+m][n]==0):
average.append(1)
else:
average.append(list[i*225+m][n]/sum)
for i in range(48):
su=su+average[i]
for i in range(48):
per=per+math.log(average[i])
per=per/48
perlx.append(math.exp(-per))