Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Complexity Measure confuses mean and sum #85

Closed
JaKasb opened this issue Nov 8, 2019 · 1 comment
Closed

Complexity Measure confuses mean and sum #85

JaKasb opened this issue Nov 8, 2019 · 1 comment

Comments

@JaKasb
Copy link

JaKasb commented Nov 8, 2019

The complexity measure for the annotation vector is defined as:
sqrt(sum(diff(subsequence).^2))

CID (Batista 2013)
https://doi.org/10.1007/s10618-013-0312-3
Matrix Profile V (Dau 2017)
http://dx.doi.org/10.1145/3097983.3097993

However, the implementation uses the mean instead of the sum.

def make_complexity_AV(ts, m):

A possible fix is to use a moving sum.
The moving sum is already contained in movmeanstd

def movmeanstd(ts,m):

See MASS by Mueen:
https://www.cs.unm.edu/~mueen/findNN.html

Fun Fact:
mean(x) = sum(x) / len(x)
In the sliding window setting, len(x) is a constant integer.
The min-max normalization of the Annotation Vector removes the constant factor.

Debugging Implementation (probably contains off-by-one error):

def CE(x: np.ndarray) -> float:
    assert x.ndim == 1, x.shape
    _ce = np.sqrt(np.sum(np.ediff1d(x)**2))
    assert _ce >= 0, (_ce, x)
    return _ce

@peterdhansen

@JaKasb
Copy link
Author

JaKasb commented Nov 11, 2019

Vectorized Numpy Implementation:

from skimage.util import view_as_windows

sliding_windows = view_as_windows(data, subsequenceLength)
assert sliding_windows.shape[0] == len(data)-subsequenceLength+1
complexity = np.sqrt(np.sum(np.square(np.diff(sliding_windows, axis=1)), axis=1))
assert sliding_windows.shape[0] == complexity.size

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

No branches or pull requests

2 participants