def gem(query, subject, St0=2, St1=2, E=0.01, symmetric=False, squared=True): """GEM local similarity measure""" # enable openmp support omp = False N = lgem.TimeSeries(query) H = lgem.TimeSeries(subject) R = lgem.Result() lgem.match(N, H, R, St0, St1, E, omp, squared) dist = R[0].penalty if (symmetric): R = lgem.Result() lgem.match(H, N, R, St0, St1, E, omp, squared) dist = min(dist, R[0].penalty) return dist
H = gem.TimeSeries(S[1000:]) print len(N), len(H) # matching parameters St0, St1, E = 2, 2, 0.01 R = gem.Result() t = time.time() gemc.cuda_match(N, H, R, St0, St1, E, True) print "time needed:", time.time( ) - t, "best match:", R[0].penalty, R[0].left, R[0].right R = gem.Result() t = time.time() gem.match(N, H, R, St0, St1, E, True, True) print "time needed:", time.time( ) - t, "best match:", R[0].penalty, R[0].left, R[0].right pl.plot(np.array(N) + 1) pl.plot(H, c="lightgrey") for item in R[:10]: L = gem.TimeSeries() X = gem.TimeCoords() Y = gem.TimeSeries() gem.backtrace(N, H, item, L, X, Y, St0, St1, E, False, True) pl.plot(X, Y, color="r") pl.plot(X, L, color="b")
N = gem.TimeSeries(S[:1000]) H = gem.TimeSeries(S[1000:]) print len(N), len(H) # matching parameters St0, St1, E = 2, 2, 0.01 R = gem.Result() t=time.time() gemc.cuda_match(N, H, R, St0, St1, E, True) print "time needed:", time.time()-t, "best match:", R[0].penalty, R[0].left, R[0].right R = gem.Result() t=time.time() gem.match(N, H, R, St0, St1, E, True, True) print "time needed:", time.time()-t, "best match:", R[0].penalty, R[0].left, R[0].right pl.plot(np.array(N) + 1) pl.plot(H, c = "lightgrey") for item in R[:10]: L = gem.TimeSeries() X = gem.TimeCoords() Y = gem.TimeSeries() gem.backtrace(N, H, item, L, X, Y, St0, St1, E, False, True) pl.plot(X, Y, color="r") pl.plot(X, L, color="b")