Skip to main content

Example of C-Accelerated Dynamic Time Warping with Pruning Control

This snippet computes C-accelerated Dynamic Time Warping using dtaidistance on identical sequences. Setting window=1 limits temporal drift off the main diagonal, while use_pruning=False turns off C-level early-stopping heuristics—guaranteeing exact distance values instead of inf while tracking the strict 1-to-1 warping path.

Source

import numpy as np from dtaidistance import dtw # Sample 1D sequences sequence_a = np.array([0.0, 1.0, 1.2, 1.5, 2.2, 10.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1], dtype=np.float64) sequence_b = np.array([0.0, 1.0, 1.2, 1.5, 2.2, 10.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1], dtype=np.float64) WINDOW_SIZE = 1 # Disable C-level pruning heuristics explicitly distance = dtw.distance( sequence_a, sequence_b, window=WINDOW_SIZE, use_pruning=False # Forces full computation without inf cutoff ) path = dtw.warping_path( sequence_a, sequence_b, window=WINDOW_SIZE, use_pruning=False ) print(f"DTW Distance: {distance:.4f}") print(f"Warping Path: {path}")

Output

DTW Distance: 0.0000
Warping Path: [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11)]


Comments

Popular posts from this blog

Udemy - Time Series Classification in Python - Learn various algorithms available

I am going to take this this Udemy course https://www.udemy.com/course/time-series-classification-in-python/  on Time Series Data Analysis. I am mainly curious about different open source algorithms available for time series pattern recognition. I have background in Computer Science/Engineering, so I am hoping I can easily digest it. 

I will go take the online Udemy course on Python for Data Science and Machine Learning Bootcamp

I did some research, and concluded that it is still worth learning in today's day and age when AI can generate just about any kind of code snippets. But only experienced programmers can judge AI's output to fullest. I am going to get my Python skills sharpened now. I am going to take Udemy's course on Python for Data Science and Machine Learning Bootcamp .