In [ ]:
import os.path
import blaze
from blaze.ts.ucr_dtw import ucr
In [ ]:
# Convert txt file into Blaze native format (if it is not yet)
def convert(filetxt, storage):
if not os.path.exists(storage):
blaze.Array(np.loadtxt(filetxt),
params=blaze.params(storage=storage))
In [ ]:
# Make sure that data is converted into a persistent Blaze array
convert("Data.txt", "Data")
convert("Query.txt", "Query")
convert("Query2.txt", "Query2")
In [ ]:
# Open Blaze arrays on-disk (will not be loaded in memory)
data = blaze.open("Data")
query = blaze.open("Query")
query2 = blaze.open("Query2")
In [ ]:
# Play with different methods & parameters here...
#%time loc, dist = ucr.ed(data, query, 128)
%time loc, dist = ucr.dtw(data, query, 0.1, 128, verbose=False)
#%time loc, dist = ucr.dtw(data, query2, 0.1, 128)
Notice that times here can be up to 4x than the original code based on text files. Blaze format is fast to read!
In [ ]:
print "Location : ", loc
print "Distance : ", dist
print "Data Scanned : ", data.size
In [ ]:
plot(data[loc:loc+128])
In [ ]:
plot(query[:])
In [ ]: