Exemple #1
0
def test_dtw():
    data = ones(dshape('100, float32'))
    query = ones(dshape('100, float32'))

    loc, dist = ucr.dtw(data, query, 0.1, 100, verbose=False)

    # these are stupid, mostly just to check for regressions
    assert isinstance(loc, int)
    assert isinstance(dist, float)
Exemple #2
0
def test_dtw():
    data  = ones(dshape('100, float32'))
    query = ones(dshape('100, float32'))

    loc, dist = ucr.dtw(data, query, 0.1, 100, verbose=False)

    # these are stupid, mostly just to check for regressions
    assert isinstance(loc, int)
    assert isinstance(dist, float)
Exemple #3
0
def test_dtw():
    # note: ucr.dtw only supports float64 atm
    count = 100 
    data  = fromiter((sin(2*pi*i/count) for i in xrange(count)), 'x, float64')
    query = data[50:60]

    loc, dist = ucr.dtw(data, query, 0.1, verbose=False)
    
    # these are stupid, mostly just to check for regressions
    ok_ (isinstance(loc, (int, long)))
    ok_ (isinstance(dist, float))
    eq_ (loc, 50)
    ok_ (dist < 1e-10 and dist >= 0.0)
Exemple #4
0
def test_dtw():
    # note: ucr.dtw only supports float64 atm
    count = 100
    data = fromiter((sin(2 * pi * i / count) for i in xrange(count)),
                    'x, float64')
    query = data[50:60]

    loc, dist = ucr.dtw(data, query, 0.1, verbose=False)

    # these are stupid, mostly just to check for regressions
    ok_(isinstance(loc, (int, long)))
    ok_(isinstance(dist, float))
    eq_(loc, 50)
    ok_(dist < 1e-10 and dist >= 0.0)
Exemple #5
0
def dtw(d1, d2, s, n):
    return ucr.dtw(d1, d2, s, n)
Exemple #6
0
# Convert txt file into Blaze native format
def convert(filetxt, storage):
    import os.path
    if not os.path.exists(storage):
        blaze.Array(np.loadtxt(filetxt), params=blaze.params(storage=storage))


# Make sure that data is converted into a persistent Blaze array
convert("Data.txt", "Data")
convert("Query.txt", "Query")
convert("Query2.txt", "Query2")

t0 = time()
# Open Blaze arrays on-disk (will not be loaded in memory)
data = blaze.open("Data")
query = blaze.open("Query")
query2 = blaze.open("Query2")
print "Total Blaze arrays open time :", round(time() - t0, 4)

t0 = time()
# Do different searches using ED/DTW with native Blaze arrays
#loc, dist = ucr.ed(data, query, 128)
loc, dist = ucr.dtw(data, query, 0.1, 128, verbose=False)
#loc, dist = ucr.dtw(data, query2, 0.1, 128)

print "Location : ", loc
print "Distance : ", dist
print "Data Scanned : ", data.size
print "Total Execution Time :", round(time() - t0, 4)
Exemple #7
0
def dtw(d1, d2, s, n):
    return ucr.dtw(d1, d2, s, n)
Exemple #8
0
# Convert txt file into Blaze native format
def convert(filetxt, storage):
    import os.path
    if not os.path.exists(storage):
        blaze.Array(np.loadtxt(filetxt),
                    params=blaze.params(storage=storage))

# Make sure that data is converted into a persistent Blaze array
convert("Data.txt", "Data")
convert("Query.txt", "Query")
convert("Query2.txt", "Query2")

t0 = time()
# Open Blaze arrays on-disk (will not be loaded in memory)
data = blaze.open("Data")
query = blaze.open("Query")
query2 = blaze.open("Query2")
print "Total Blaze arrays open time :", round(time()-t0, 4)

t0 = time()
# Do different searches using ED/DTW with native Blaze arrays
#loc, dist = ucr.ed(data, query, 128)
loc, dist = ucr.dtw(data, query, 0.1, 128, verbose=False)
#loc, dist = ucr.dtw(data, query2, 0.1, 128)

print "Location : ", loc
print "Distance : ", dist
print "Data Scanned : ", data.size
print "Total Execution Time :", round(time()-t0, 4)
if os.path.exists('query2.blz'): shutil.rmtree('query2.blz')
n = np.random.randn(query.size)*.1  # introduce some noise
query2 = blz.array(xq*np.sin(xq)+n, params=blz.params(storage='query2.blz'))
if timing: print "Total Blaze arrays create time :", round(time()-t0, 4)

t0 = time()
# Open Blaze arrays on-disk (will not be loaded in memory)
ts = blz.open("ts.blz")
query = blz.open("query.blz")
query2 = blz.open("query2.blz")
if timing: print "Total Blaze arrays open time :", round(time()-t0, 4)
print "query size:", query.size

# Do the search for the exact pattern
print "   ***   Querying *exact* pattern   ***"
t0 = time()
loc, dist = ucr.dtw(ts, query, 0.1, query.size, verbose=False)
print "Location : ", loc
print "Distance : ", dist
print "Data Scanned : ", ts.size
if timing: print "Total Execution Time (exact):", round(time()-t0, 4)

# Do the search for the noisy pattern
print "   ***   Querying *noisy* pattern   ***"
t0 = time()
loc, dist = ucr.dtw(ts, query2, 0.1, query2.size, verbose=False)
print "Location : ", loc
print "Distance : ", dist
print "Data Scanned : ", ts.size
if timing: print "Total Execution Time (noisy) :", round(time()-t0, 4)