def th_matrixcorr(x, y):
"""
return a correlation matrix between
columns of x and columns of y.
So, if X.size() == (1000,4) and Y.size() == (1000,5),
then the result will be of size (4,5) with the
(i,j) value equal to the pearsonr correlation coeff
between column i in X and column j in Y
"""
mean_x = th.mean(x, 0)
mean_y = th.mean(y, 0)
xm = x.sub(mean_x.expand_as(x))
ym = y.sub(mean_y.expand_as(y))
r_num = xm.t().mm(ym)
r_den1 = th.norm(xm,2,0)
r_den2 = th.norm(ym,2,0)
r_den = r_den1.t().mm(r_den2)
r_mat = r_num.div(r_den)
return r_mat
评论列表
文章目录