How to use the dtaidistance.dtw.distance_matrix_fast 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_bugs.py View on Github external
def test_bug1():
    """Failed on Windows if pointer types are different."""
    series = [np.array([0, 0, 1, 2, 1, 0, 1, 0, 0], dtype=np.double),
              np.array([0.0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0]),
              np.array([0.0, 0, 1, 2, 1, 0, 0, 0])]
    ds = dtw.distance_matrix_fast(series)
    # print(ds)
github wannesm / dtaidistance / tests / test_bugs.py View on Github external
def test_bug1_serial():
    """Failed on Windows if pointer types are different."""
    series = [np.array([0, 0, 1, 2, 1, 0, 1, 0, 0], dtype=np.double),
              np.array([0.0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0]),
              np.array([0.0, 0, 1, 2, 1, 0, 0, 0])]
    ds = dtw.distance_matrix_fast(series, parallel=False)
    print(ds)
github wannesm / dtaidistance / tests / test_bugs.py View on Github external
def test_bug1_psi():
    s = [np.array([0., 0, 1, 2, 1, 0, 1, 0, 0]),
         np.array([9., 0, 1, 2, 1, 0, 1, 0, 9])]

    res1 = dtw.distance_matrix(s, compact=True, psi=1)
    res2 = dtw.distance_matrix_fast(s, compact=True, psi=1)
    print(res1)
    print(res2)
    assert res1 == pytest.approx(res2)
github wannesm / dtaidistance / examples / hierarchical_clustering.py View on Github external
For a more efficient approach, check:
    Mueen, A and Keogh, E, Extracting Optimal Performance from Dynamic Time Warping,
    Tutorial, KDD 2016
    http://www.cs.unm.edu/~mueen/DTW.pdf

    :return: None
    """
    series = [
        np.array([0.0, 0.0, 2.0, 1.0, 1.0, 0.0, 0.0]),
        np.array([0.0, 0.0, 2.0, 1.0, 1.0, 0.0, 0.0]),
        np.array([2.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0]),
        np.array([2.0, 1.0, 1.0, 0.0, 0.0, 2.0, 3.0]),
        np.array([4.0, 2.0, 1.0, 0.0, 0.0, 1.0, 3.0])
    ]

    dists = dtw.distance_matrix_fast(series)
    print("Distance matrix:\n{}".format(dists))

    dists_cond = np.zeros(size_cond(len(series)))
    idx = 0
    for r in range(len(series)-1):
        dists_cond[idx:idx+len(series)-r-1] = dists[r, r+1:]
        idx += len(series)-r-1

    z = linkage(dists_cond, method='complete', metric='euclidean')
    print(z)

    fig, axes = plt.subplots(2, 1, figsize=(8, 3))
    for idx, serie in enumerate(series):
        serie += idx * 0.1
        axes[0].plot(serie, label=str(idx))
        axes[0].text(0 + 0.15 * (-1)**idx * idx, serie[0] + 0.15 * idx, idx)