机器学习互相关
Posted linengier
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了机器学习互相关相关的知识,希望对你有一定的参考价值。
Computing the cross-correlation function is useful for finding the time-delay offset between two time series.
Python has the numpy.correlate function. But there is a much faster FFT-based implementation.
Check out the following paper for an application of this function:
import numpy as np
from numpy.fft import fft, ifft, fft2, ifft2, fftshift
def cross_correlation_using_fft(x, y):
f1 = fft(x)
f2 = fft(np.flipud(y))
cc = np.real(ifft(f1 * f2))
return fftshift(cc)
# shift < 0 means that y starts 'shift' time steps before x # shift > 0 means that y starts 'shift' time steps after x
def compute_shift(x, y):
assert len(x) == len(y)
c = cross_correlation_using_fft(x, y)
assert len(c) == len(x)
zero_index = int(len(x) / 2) - 1
shift = zero_index - np.argmax(c)
return shift
We can test the above function by shifting the second series manually and seeing if the shift is accurately computed:
for n in range(1000, 1050, 7):
for s in range(-5, 5):
a = [random.random() for _ in xrange(n)] # big random sequence of values
b = a
if s >= 1:
a = a[s:]
b = b[:-s]
elif s <= -1:
a = a[:s]
b = b[-s:]
assert s_optimal == s
以上是关于机器学习互相关的主要内容,如果未能解决你的问题,请参考以下文章
面经分享网易互娱定向预研机器学习实习面经 | 已拿offer
HMS Core机器学习服务实现同声传译,支持中英文互译和多种音色语音播报
[机器学习与scikit-learn-50]:特征工程-特征选择(降维)-5-二级过滤-特征值与标签之间的关系:F过滤与互信息量法过滤