patternrec_dtw with rolling is not working properly
I have an issue when applying patternrec_dtw to my dataset. To test it, I have set max_distance=0
, hence only the same day as the pattern should be flagged as pattern. The function isPattern(chunk)
correctly returns FALSE
for all the chunks - but then all the days get flagged as pattern. Whats the reason for this?
"""
ref = data[ref_field]
ref = ref.to_numpy()
ref_var = ref.var()
def func(a, b):
return np.linalg.norm(a - b)
def isPattern(chunk):
dist, *_ = dtw.dtw(chunk, ref, func)
if normalize:
dist /= ref_var
return dist < max_distance
dat = data[field]
sz = len(ref)
mask = customRoller(dat, window=sz, min_periods=sz).apply(isPattern, raw=True)
flagger = flagger.setFlags(field, loc=mask, **kwargs)
return data, flagger
"""
Edited by Juliane Geller