def dtw_func(): f = DataReader("F", "yahoo", datetime(2000, 1, 1), datetime(2012, 1, 1)) f_2008 = f[f.index.year == 2008] f_2009 = f[f.index.year == 2009] query = f_2008.Volume.values template = f_2009.Volume.values dist = distancefunc(name="manhattan") #windowtype="paliwal" #window, distance, path = dtwpy.dtw(query, template, dist=dist, windowtype=windowtype, windowsize=50,pattern="symmetric1", normalized=False,dist_only=False, cost=True) #pltdtw.plotwithQT(query, template, path,title="") #pltdtw.plotalignment_with_window(window,windowtype,path,title="") #pltdtw.plotalignment(path, title="") #windowtype="scband" #window, distance, path = dtwpy.dtw(query, template, dist=dist, windowtype=windowtype, windowsize=50,pattern="symmetric1", normalized=False,dist_only=False, cost=True) #pltdtw.plotwithQT(query, template, path,title="") #pltdtw.plotalignment_with_window(window,windowtype,path,title="") #pltdtw.plotalignment(path, title="") windowtype="itakura" window, distance, path = dtwpy.dtw(query, template, dist=dist, windowtype=windowtype, windowsize=50,pattern="symmetric1", normalized=False,dist_only=False, cost=True) #pltdtw.plotwithQT(query, template, path,title="") #pltdtw.plotalignment_with_window(window,windowtype,path,title="") #pltdtw.plotalignment(path, title="") return pltdtw.plotalignment_with_window(window,windowtype,path,title="")
diff1 = int(max_x2 - max_x1) diff2 = int(max_y1 / max_y2) D2 = d2[diff1:3543] plt.figure(1) plt.plot(d1) plt.figure(2) plt.plot(d2) plt.plot(D2) query = d1 template = d2 dist = distancefunc(name="manhattan") windowtype = "itakura" figure_number = 3 window, distance, path = dtwpy.dtw(query, template, dist=dist, windowtype=windowtype, windowsize=50, pattern="symmetric1", normalized=False, dist_only=False, cost=True) pltdtw.plotwithQT(query, template, path, figure_number, title=" Original")
data2 = np.load('Output2.npy') d21 = data2[2] d2 = d21.sum(1) max_y1 = max(d1) max_x1 = xvals[d1.argmax()] max_y2 = max(d2) max_x2 = xvals[d2.argmax()] diff1 = int(max_x2 - max_x1) diff2 = int(max_y1 / max_y2) D2 = d2[diff1:3543] dist = distancefunc(name="euclidean") windowtype = "scband" query = d1 template = D2 ''' UNCOMMENT BELOW FOR THE DTWPY ALIGNMENT. IT IS THE SAME AS DTAI BUT TAKES LONGER TO RUN. ''' ''' dist = distancefunc(name="euclidean") windowtype="scband" figure_number = 1