How to use the dtaidistance.dtw.warping_paths 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_warping.py View on Github external
def test_normalize2():
    s1 = np.array([0., 0, 1, 2, 1, 0, 1, 0, 0, 2, 1, 0, 0])
    s2 = np.array([0., 1, 2, 3, 1, 0, 0, 0, 2, 1, 0, 0, 0])
    d1, paths1 = dtw.warping_paths(s1, s2, psi=2)
    d2, paths2 = dtw.warping_paths_fast(s1, s2, psi=2)
    path1 = dtw.best_path(paths1)
    path2 = dtw.best_path(paths2)
    if directory:
        dtwvis.plot_warpingpaths(s1, s2, paths1, path1, filename=directory / "normalize.png")
    np.testing.assert_almost_equal(d1, d2, decimal=4)
    np.testing.assert_almost_equal(paths1, paths2, decimal=4)
    np.testing.assert_almost_equal(path1, path2, decimal=4)
github wannesm / dtaidistance / tests / test_warping.py View on Github external
def test_psi_dtw_1a():
    x = np.arange(0, 20, .5)
    s1 = np.sin(x)
    s2 = np.sin(x - 1)
    d, paths = dtw.warping_paths(s1, s2, psi=2)
    # print(paths[:5,:5])
    # path = dtw.warping_path(s1, s2, psi=2)
    # dtwvis.plot_warping(s1, s2, path, filename=os.path.expanduser("~/Desktop/test_psi_dtw_1_1.png"))
    # path = dtw.best_path(paths)
    # dtwvis.plot_warpingpaths(s1, s2, paths, path, filename=os.path.expanduser("~/Desktop/test_psi_dtw_1_2.png"))
    np.testing.assert_equal(d, 0.0)
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)
github wannesm / dtaidistance / tests / test_warping.py View on Github external
def test_psi_dtw_2a():
    x = np.arange(0, 20, .5)
    s1 = np.sin(x - 1)
    s2 = np.sin(x)
    d, paths = dtw.warping_paths(s1, s2, psi=2, window=3)
    # path = dtw.warping_path(s1, s2, psi=2)
    # dtwvis.plot_warping(s1, s2, path, filename=os.path.expanduser("~/Desktop/test_psi_dtw_2_1.png"))
    # path = dtw.best_path(paths)
    # dtwvis.plot_warpingpaths(s1, s2, paths, path, filename=os.path.expanduser("~/Desktop/test_psi_dtw_2_2.png"))
    np.testing.assert_equal(d, 0.0)
github wannesm / dtaidistance / tests / test_dtw.py View on Github external
def test_distance1_b():
    s1 = [0, 0, 1, 2, 1, 0, 1, 0, 0]
    s2 = [0, 1, 2, 0, 0, 0, 0, 0, 0]
    d2, _ = dtw.warping_paths(s1, s2)
    assert d2 == pytest.approx(math.sqrt(2))
github wannesm / dtaidistance / tests / test_benchmark.py View on Github external
def d():
        dd, _ = dtw.warping_paths(s1, s2)
        return dd
github wannesm / dtaidistance / tests / test_dtw_weighted.py View on Github external
def test_distance1():
    directory = prepare_directory()

    s1 = np.array([0., 0, 1, 2, 1, 0, 1, 0, 0, 2, 1, 0, 0])
    s2 = np.array([0., 1, 2, 3, 1, 10, 1, 0, 2, 1, 0, 0, 0])
    d, paths = dtw.warping_paths(s1, s2)
    # print(d, "\n", paths)
    dtwvis.plot_warpingpaths(s1, s2, paths, filename=directory / "temp1.png")

    weights = np.full((len(s1), 8), np.inf)
    weights[:, 2:4] = 0.0
    weights[4:7, 2:4] = 10.0
    weights[:, 4:6] = 0.0
    weights[4:7, 4:6] = 10.0
    d, paths = dtww.warping_paths(s1, s2, weights)
    # print(d, "\n", paths)
    dtwvis.plot_warpingpaths(s1, s2, paths, filename=directory / "temp2.png")