Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Reqest | Custom cost function #189

Open
KarazhovAndrii opened this issue Jan 26, 2023 · 2 comments
Open

Change Reqest | Custom cost function #189

KarazhovAndrii opened this issue Jan 26, 2023 · 2 comments

Comments

@KarazhovAndrii
Copy link

Hello DTAI Team,

thank you for sharing this great project.
Consider in subsequent releases a possibility for users to define cost function, as they could need different metrics to evaluate the distance when computing DTW. Example of the interface (dist_func optional parameter is added):

def distance(s1, s2, dist_func=None,
             window=None, max_dist=None, max_step=None,
             max_length_diff=None, penalty=None, psi=None,
             use_c=False, use_pruning=False, only_ub=False)
def warping_paths(s1, s2, dist_func=None, window=None, max_dist=None, use_pruning=False,
                  max_step=None, max_length_diff=None, penalty=None, psi=None, psi_neg=True,
                  use_c=False, use_ndim=False):

where dist_func suppose to have a signature:

def dist_func(a, b):
    return some_computation_over_a_b
@wannesm
Copy link
Owner

wannesm commented Feb 21, 2023

We would need to support this also in the C code to be consistent. While not necessarily difficult to add in one location, it requires changes at multiple locations (e.g. also in the bounds) and increases the cost of maintaining. So we will have to think about how to do this consistent throughout the codebase (we already have this a bit to support ndim series).

If you urgently need this. It is not too difficult to change this in the python part (no compilation required). Simply change these two lines in the code:

d = (s1[i] - s2[j])**2

if use_ndim:

@wannesm
Copy link
Owner

wannesm commented Jun 14, 2023

In the master branch, this functionality is now available by using the inner_dist argument. When using the pure Python implementation, this can be any callable function (wrapped in an object that has as callable arguments inner_dist and result). When using the the fast dtw computation in C this needs to be one of 'euclidean' or 'squared euclidean'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants