Python 1d相关归一化和非归一化值

时间:2018-04-03 13:23:39

标签: python-3.x numpy correlation

使用np.correlate函数以找到另一个数组的最佳拟合 在匹配精确的理想输入中,我希望从相关索引(滞后)中的归一化相关返回值1。 另外,为什么np.correlate函数会返回从end到start的乘法,如下面的输出所示?

有人可以澄清如何实现所需的输出以及np.correlate函数中反向乘法的原因吗?

函数调用:

cor = correlation_normalized([3., 4., 4.], [1., 2., 3., 4., 4., 5.])
cor2 = correlation_normalized([1., 2., 3.], [1., 2., 3., 4., 4., 5.])

corr = np.correlate([3., 4., 4.], [1., 2., 3., 4., 4., 5.])
corr2 = np.correlate([1., 2., 3.], [1., 2., 3., 4., 4., 5.])

功能:

def correlation_normalized(a, v):
    a = (a - np.mean(a)) / (np.std(a) * len(a))
    v = (v - np.mean(v)) / np.std(v)
    return np.correlate(a, v)  # Default is mode="valid"

规范化函数源:Why NUMPY correlate and corrcoef return different values and how to “normalize” a correlate in “full” mode?

输出:

cor = [0.1754116  0.35082321 0.52623481 0.52623481]
cor2 = [0.30382181 0.30382181 0.60764362 0.60764362]
corr = [48. 41. 34. 23.]
corr2 = [27. 23. 20. 14.]

预期产出:

cor = [value  value 1.0 value]
cor2 = [1.0 value value value]
corr = [23. 34. 41. 48.]
corr2 = [14. 20. 23. 27.]

0 个答案:

没有答案