Speed up distance calculations, FFT, Sliding window

175 Views Asked by At

I have two time series A and B. A with length m and B with length n. m << n. Both have the dimension d.

I calculate the distance between A and all subsequencies in B by sliding A over B. In python the code looks like this.

def sliding_dist(A,B)
    n = len(B)
    dist = np.zeros(n)
    for i in range(n-m):
        subrange = B[i:i+m,:]
        distance = np.linalg.norm(A-subrange)
        dist[i] = distance
    return dist

Now this code takes a lot of time to execute and I have very many calculations to do. I need to speed up the calculations. My guess is that I could do this by using convolutions, and multiplication in frequency domain. However, I have been unable to implement it.

Any ideas? :) Thanks