Commit 54ea1914 authored by Benjamin Paaßen's avatar Benjamin Paaßen
Browse files

built a dynamic time warping demo and refactored the pure python dtw code into the demo

parent 351147a3
......@@ -3,3 +3,4 @@
This diff is collapsed.
import numpy as np
def multi_dtw_pure_python(Xs, Ys, delta):
D = np.zeros((len(Xs), len(Ys)))
for i in range(len(Xs)):
for j in range(len(Ys)):
D[i, j] = dtw_pure_python(Xs[i], Ys[j], delta)
return D
def dtw_pure_python(x, y, delta):
# First, compute all pairwise replacements
Delta = np.zeros((len(x), len(y)))
for i in range(len(x)):
for j in range(len(y)):
Delta[i, j] = delta(x[i], y[j])
# Then, compute the dynamic time warping
# distance
D = np.zeros((len(x), len(y)))
# initialize last entry
D[-1, -1] = Delta[-1, -1]
# initialize last column
for i in range(len(x)-2,-1,-1):
D[i,-1] = Delta[i,-1] + D[i+1,-1]
# initialize last row
for j in range(len(y)-2,-1,-1):
D[-1,j] = Delta[-1,j] + D[-1,j+1]
for i in range(len(x)-2,-1,-1):
for j in range(len(y)-2,-1,-1):
D[i,j] = Delta[i,j] + min3(D[i+1,j+1], D[i,j+1], D[i+1,j])
return D[0,0]
def min3(a, b, c):
if(a < b):
if(a < c):
return a
return c
if(b < c):
return b
return c
......@@ -68,10 +68,6 @@ def pairwise_distances(Xs, Ys, dist, delta = None, num_jobs = 8):
# set up the result matrix
D = np.zeros((K,L))
# set up the callback function
def callback(tpl):
D[tpl[0], tpl[1]] = tpl[2]
# start off all parallel processing jobs
results = []
if(not delta):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment