meinardmueller / synctoolbox

Sync Toolbox - Python package with reference implementations for efficient, robust, and accurate music synchronization based on dynamic time warping (DTW)
https://meinardmueller.github.io/synctoolbox
Other
108 stars 11 forks source link

euclidean distance is too slow #23

Closed yiitozer closed 1 year ago

yiitozer commented 1 year ago

We might want to change the computation of euclidean_distance:

from sklearn.metrics.pairwise import euclidean_distances

#@jit(nopython=True)
def euclidean_distance(f1, f2, l2_meas_max=1.0, l2_meas_min=0.0):
    """Computes euclidean distances between the vectors in f1 and f2, and
    rescales the results to lie in the range [cos_meas_min, cos_meas_max]."""

    #S1 = np.zeros((f1.shape[1], f2.shape[1]))
    #for n in range(f2.shape[1]):
    #    S1[:, n] = np.sqrt(np.sum((f1.T - f2[:, n]) ** 2, axis=1))
    S1 = euclidean_distances(f1.T, f2.T)

    return S1 * (l2_meas_max - l2_meas_min) + l2_meas_min
yiitozer commented 1 year ago

Thank you @nctamer for pointing this out.