How to use the dtaidistance.dtw.distance function in dtaidistance

To help you get started, we’ve selected a few dtaidistance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wannesm / dtaidistance / tests / test_penalty.py View on Github external
def test_penalty_cyclicalshift():
    s1 = np.array([0., 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0])
    s2 = np.array([2., 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2])
    # plt.plot(s1)
    # plt.plot(s2)
    # plt.show(block=True)
    d1 = dtw.distance(s1, s2)
    d2 = dtw.distance(s1, s2, penalty=1)
    assert d1 == pytest.approx(math.sqrt(10))
    assert d2 == pytest.approx(math.sqrt(14))
github wannesm / dtaidistance / tests / test_bugs.py View on Github external
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)
github wannesm / dtaidistance / tests / test_cython.py View on Github external
def test_overflowdistance():
    maxvalthirtytwobit = 2147483647
    s = np.array([
        [maxvalthirtytwobit, maxvalthirtytwobit, 1, 2, 1, 0, 1, 0, 0],
        [1., 2, 0, 0, 0, 0, 0, 1, 0]])
    d1 = dtw.distance(s[0], s[1], use_c=False)
    d2 = dtw.distance(s[0], s[1], use_c=True)
    print(d1)
    print(d2)
    # m = dtw_c.distance_matrix_nogil(s)
github wannesm / dtaidistance / tests / test_bugs.py View on Github external
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)
github wannesm / dtaidistance / tests / test_penalty.py View on Github external
def test_penalty_cyclicalshift():
    s1 = np.array([0., 1, 2, 1, 0, 1, 2, 1, 0, 1, 2, 1, 0])
    s2 = np.array([2., 1, 0, 1, 2, 1, 0, 1, 2, 1, 0, 1, 2])
    # plt.plot(s1)
    # plt.plot(s2)
    # plt.show(block=True)
    d1 = dtw.distance(s1, s2)
    d2 = dtw.distance(s1, s2, penalty=1)
    assert d1 == pytest.approx(math.sqrt(10))
    assert d2 == pytest.approx(math.sqrt(14))
github wannesm / dtaidistance / tests / test_bugsvis.py View on Github external
def test_bug2():
    s1 = np.array([0, 0, 1, 2, 1, 0, 1, 0, 0], dtype=np.double)
    s2 = np.array([0.0, 1, 2, 0, 0, 0, 0, 0, 0])
    d1a = dtw.distance_fast(s1, s2, window=2)
    d1b = dtw.distance(s1, s2, window=2)

    if directory:
        fn = directory / "warpingpaths.png"
    else:
        file = tempfile.NamedTemporaryFile()
        fn = Path(file.name + "_warpingpaths.png")
    d2, paths = dtw.warping_paths(s1, s2, window=2)
    best_path = dtw.best_path(paths)
    dtwvis.plot_warpingpaths(s1, s2, paths, best_path, filename=fn, shownumbers=False)
    print("Figure saved to", fn)

    assert d1a == pytest.approx(d2)
    assert d1b == pytest.approx(d2)