@jit  # if you don't have number, then comment out this line but this routine will be slow!
def dynamic_time_warping(tseries1, tseries2):
    ntime1, nfeatures = tseries1.shape
    ntime2 = tseries2.shape[0]
    dtw = np.zeros((ntime1, ntime2), dtype=np.float)  # matrix of coordinate distances
    path = np.zeros((ntime1, ntime2), dtype=np.int)  # path of algorithm

    # initialize the first row and column
    for k in range(nfeatures):
        dtw[0, 0] += (tseries1[0, k] - tseries2[0, k]) ** 2
    path[0, 0] = -1

    for i in range(1, ntime1):
        dist = 0.0
        for k in range(nfeatures):
            dist += (tseries1[i, k] - tseries2[0, k]) ** 2
        dtw[i, 0] = dtw[i-1, 0] + dist
        path[i, 0] = 2

    for j in range(1, ntime2):
        dist = 0.0
        for k in range(nfeatures):
            dist += (tseries1[0, k] - tseries2[j, k]) ** 2
        dtw[0, j] = dtw[0, j-1] + dist
        path[0, j] = 1

    # main loop of the DTW algorithm
    for i in range(1, len(tseries1)):
        for j in range(1, len(tseries2)):
            a = dtw[i-1, j-1]
            b = dtw[i, j-1]
            c = dtw[i-1, j]
            if a < b:
                if a < c:
                    idx = 0  # a is the minimum
                    delta = a
                else:
                    idx = 2  # c is the minimum
                    delta = c
            else:
                if b < c:
                    idx = 1  # b is the minimum
                    delta = b
                else:
                    idx = 2  # c is the minimum
                    delta = c
            # neighbors = np.array([dtw[i-1, j-1], dtw[i, j-1], dtw[i-1, j]])
            # idx = np.argmin(neighbors)
            # delta = neighbors[idx]
            dist = 0.0
            for k in range(nfeatures):
                dist += (tseries1[i, k] - tseries2[j, k]) ** 2
            dtw[i, j] = dist + delta
            path[i, j] = idx

    return dtw[-1, -1], dtw, path
Create shared memory objects.
dataset/ETHPy150Open brandonckelly/bck_stats/bck_stats/dba.py/dynamic_time_warping--crossover with--dataset/ETHPy150Open wkentaro/conque.vim/autoload/conque_term/conque_sole_subprocess.py/ConqueSoleSubprocess.init_shared_memory