I have a long time serie, let's say 1000 items. I want to find patterns in it of different lengths from 10 to 100 elements. To do this, I extract sliding windows of different lengths and calculate distance matrix between them using DTW. But it works very slowly. Can you please tell me if there is a more efficient method?
My code:
def generate_sliding_windows(series, window_size):
sliding_windows = []
for i in range(0, len(series) - window_size + 1):
window = tuple(series[i:i + window_size])
indexes = (i, i + window_size)
sliding_windows.append(
SlidingWindow(data=np.array(window), indexes=np.array(indexes))
)
return sliding_windows
sliding_windows = []
for window_size in range(10, 100):
sliding_windows.extend(
generate_sliding_windows(time_serie, window_size))
n = len(sliding_windows)
distance_matrix = np.zeros((n, n))
for i in range(n):
for j in range(i + 1, n):
dist = fastdtw(x, y, dist=euclidean)[0]
distance_matrix[i][j] = dist
distance_matrix[j][i] = dist
The slowest piece of code here is the calculation of the distance matrix.