feat: implement DTW comparison, add data segmentation and persistence, and update QML UI for file imports and graphing.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""Dynamic Time Warping comparision between two temperature runs."""
|
||||
|
||||
import numpy as np
|
||||
from dtw import dtw
|
||||
|
||||
|
||||
def compare_runs(series_a: list[float], series_b: list[float]) -> dict:
|
||||
"""Compute DTW alignment between 2 average-temperature series.
|
||||
|
||||
Returns:
|
||||
dict with keys:
|
||||
- distance: float - warping distance
|
||||
- index_a: list[int] - warping path indices into series_a
|
||||
- index_b: list[int] - warping path indices into series_b
|
||||
- warping_path: list[tuple[int,int]] - paired indices
|
||||
"""
|
||||
x = np.array(series_a, dtype=float)
|
||||
y = np.array(series_b, dtype=float)
|
||||
|
||||
if x.size == 0 or y.size == 0:
|
||||
return {"distance": float('inf'), "index_a": [],"index_b": [], "warping_path": []}
|
||||
|
||||
alignment = dtw(x, y, keep_internals=True)
|
||||
return {
|
||||
"distance": float(alignment.distance),
|
||||
"index_a": alignment.index1.tolist(),
|
||||
"index_b": alignment.index2.tolist(),
|
||||
"warping_path": list(zip(alignment.index1.tolist(), alignment.index2.tolist()))
|
||||
}
|
||||
Reference in New Issue
Block a user