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

Fix mass absolute nan #288

Merged
merged 2 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stumpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,9 @@ def _mass_absolute(Q_squared, T_squared, QT):
`See Mueen's Absolute Algorithm for Similarity Search \
<https://www.cs.unm.edu/~mueen/MASS_absolute.m>`__
"""
return np.sqrt(Q_squared + T_squared - 2 * QT)
D = Q_squared + T_squared - 2 * QT
D[D < 0] = 0.0
return np.sqrt(D)


def mass_absolute(Q, T):
Expand Down
60 changes: 60 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,66 @@ def test_mass_absolute_T_inf(Q, T):
npt.assert_almost_equal(ref, comp)


def test_mass_absolute_sqrt_input_negative():
Q = np.array(
[
-13.09,
-14.1,
-15.08,
-16.31,
-17.13,
-17.5,
-18.07,
-18.07,
-17.48,
-16.24,
-14.88,
-13.56,
-12.65,
-11.93,
-11.48,
-11.06,
-10.83,
-10.67,
-10.59,
-10.81,
-10.92,
-11.15,
-11.37,
-11.53,
-11.19,
-11.08,
-10.48,
-10.14,
-9.92,
-9.99,
-10.11,
-9.92,
-9.7,
-9.47,
-9.06,
-9.01,
-8.79,
-8.67,
-8.33,
-8.0,
-8.26,
-8.0,
-7.54,
-7.32,
-7.13,
-7.24,
-7.43,
-7.93,
-8.8,
-9.71,
]
)
ref = 0
comp = core.mass_absolute(Q, Q)
npt.assert_almost_equal(ref, comp)


def test_apply_exclusion_zone():
T = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=float)
ref = np.empty(T.shape)
Expand Down