def test_distance3_a(): dist_opts = {"penalty": 0.005, "max_step": 0.011, "window": 3} s = np.array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.005, 0.01, 0.015, 0.02, 0.01, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) p = np.array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.005, 0.01, 0.015, 0.02, 0.01, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) d1 = dtw.distance(s, p, **dist_opts) d2 = dtw_c.distance_nogil(s, p, **dist_opts) assert d1 == pytest.approx(d2)
def test_distance2_c(): dist_opts = {} s1 = np.array([0.0, 0.0, 2.0, 1.0, 1.0, 0.0, 0.0]) s2 = np.array([0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0]) d1 = dtw.distance(s1, s2, **dist_opts) d2 = dtw_c.distance_nogil(s1, s2, **dist_opts) assert d1 == d2 assert d1 == pytest.approx(1.0)
def test_distance1_b(): dist_opts = {} s1 = np.array([0., 0.01, 0., 0.01, 0., 0., 0., 0.01, 0.01, 0.02, 0., 0.]) s2 = np.array([0., 0.02, 0.02, 0., 0., 0.01, 0.01, 0., 0., 0., 0.]) d1 = dtw.distance(s1, s2, **dist_opts) d2 = dtw_c.distance_nogil(s1, s2, **dist_opts) assert d1 == d2 assert d1 == pytest.approx(0.02)
def test_distance2_bb(): dist_opts = {'max_step': 0.1} s1 = np.array([0.0, 0.0, 2.0, 1.0, 1.0, 0.0, 0.0]) s2 = np.array([0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0]) d1 = dtw.distance(s1, s2, **dist_opts) d2 = dtw_c.distance_nogil(s1, s2, **dist_opts) print(d1, d2) assert d1 == d2 assert d1 == pytest.approx(np.inf)
def test_distance1_a(): # dist_opts = {'max_dist': 0.201, 'max_step': 0.011, 'max_length_diff': 8, 'window': 3} dist_opts = {'window': 3} s1 = np.array([0., 0.01, 0., 0.01, 0., 0., 0., 0.01, 0.01, 0.02, 0., 0.]) s2 = np.array([0., 0.02, 0.02, 0., 0., 0.01, 0.01, 0., 0., 0., 0.]) d1 = dtw.distance(s1, s2, **dist_opts) d2 = dtw_c.distance_nogil(s1, s2, **dist_opts) assert d1 == d2 assert d1 == pytest.approx(0.02)
def test_distance4(): try: import pandas as pd except ImportError: # If no pandas, ignore test (not a required dependency) return s = [[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [0.005, 0.01, 0.015, 0.02, 0.01, 0., 0., 0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]] p = np.array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) df = pd.DataFrame(data=s) s = df.values for i in range(s.shape[0]): ss = s[i] # ss will not be C contiguous memory layout d = dtw_c.distance_nogil(ss, p)
def d(): return dtw_c.distance_nogil(s1, s2)
def test_distance1_d(): s1 = np.array([0., 0, 1, 2, 1, 0, 1, 0, 0]) s2 = np.array([0., 1, 2, 0, 0, 0, 0, 0, 0]) d = dtw_c.distance_nogil(s1, s2) assert(d) == pytest.approx(math.sqrt(2))
def test_psi_dtw_2c(): x = np.arange(0, 20, .5) s1 = np.sin(x - 1) s2 = np.sin(x) d = dtw_c.distance_nogil(s1, s2, psi=2, window=3) np.testing.assert_equal(d, 0.0)