Skip to content
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
2 changes: 1 addition & 1 deletion stumpy/aamp_stimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def __init__(
p : float, default 2.0
The p-norm to apply for computing the Minkowski distance.
"""
self._T = T
self._T = T.copy()
self._T_min = np.min(self._T[np.isfinite(self._T)])
self._T_max = np.max(self._T[np.isfinite(self._T)])
self._p = p
Expand Down
15 changes: 9 additions & 6 deletions stumpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ def non_normalized(non_norm, exclude=None, replace=None):
parameters when necessary.

```
def non_norm_func(Q, T, A):
def non_norm_func(Q, T, A_non_norm):
...
return


@non_normalized(
non_norm_func,
exclude=["normalize", "A", "B"],
replace={"A": None},
exclude=["normalize", "p", "A", "B"],
replace={"A_norm": "A_non_norm", "other_norm": None},
)
def norm_func(Q, T, B=None, normalize=True):
def norm_func(Q, T, A_norm=None, other_norm=None, normalize=True, p=2.0):
...
return
```
Expand All @@ -104,13 +104,16 @@ def norm_func(Q, T, B=None, normalize=True):

exclude : list, default None
A list of function (or class) parameter names to exclude when comparing the
function (or class) signatures
function (or class) signatures. When `exlcude is None`, this parameter is
automatically set to `exclude = ["normalize", "p"]` by default.

replace : dict, default None
A dictionary of function (or class) parameter key-value pairs. Each key that
is found as a parameter name in the `norm` function (or class) will be replaced
by its corresponding or complementary parameter name in the `non_norm` function
(or class).
(or class) (e.g., {"norm_param": "non_norm_param"}). To remove any parameter in
the `norm` function (or class) that does not exist in the `non_norm` function,
simply set the value to `None` (i.e., {"norm_param": None}).

Returns
-------
Expand Down
6 changes: 5 additions & 1 deletion stumpy/gpu_stimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from .stimp import _stimp


@core.non_normalized(gpu_aamp_stimp)
@core.non_normalized(
gpu_aamp_stimp,
exclude=["pre_scrump", "normalize", "p", "pre_scraamp"],
replace={"pre_scrump": "pre_scraamp"},
)
class gpu_stimp(_stimp):
"""
Compute the Pan Matrix Profile with with one or more GPU devices
Expand Down
14 changes: 11 additions & 3 deletions stumpy/stimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def __init__(
mp_func : object, default stump
The matrix profile function to use when `percentage = 1.0`
"""
self._T = T
self._T = T.copy()
if max_m is None:
max_m = max(min_m + 1, core.get_max_window_size(self._T.shape[0]))
M = np.arange(min_m, max_m + 1, step).astype(np.int64)
Expand Down Expand Up @@ -320,7 +320,11 @@ def M_(self):
# return self._n_processed


@core.non_normalized(aamp_stimp)
@core.non_normalized(
aamp_stimp,
exclude=["pre_scrump", "normalize", "p", "pre_scraamp"],
replace={"pre_scrump": "pre_scraamp"},
)
class stimp(_stimp):
"""
Compute the Pan Matrix Profile
Expand Down Expand Up @@ -464,7 +468,11 @@ def __init__(
)


@core.non_normalized(aamp_stimped)
@core.non_normalized(
aamp_stimped,
exclude=["pre_scrump", "normalize", "p", "pre_scraamp"],
replace={"pre_scrump": "pre_scraamp"},
)
class stimped(_stimp):
"""
Compute the Pan Matrix Profile with a distributed dask cluster
Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ test_custom()
# Test one or more user-defined functions repeatedly
for VARIABLE in {1..10}
do
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_.py
pytest -x -W ignore::DeprecationWarning tests/test_.py
check_errs $?
done
clean_up
Expand Down Expand Up @@ -138,7 +138,7 @@ test_unit()
pytest -rsx -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_aamp_stimp.py
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aamp_stimp.py
check_errs $?
pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_non_normalized_decorator.py
pytest -x -W ignore::DeprecationWarning tests/test_non_normalized_decorator.py
check_errs $?
}

Expand Down
85 changes: 79 additions & 6 deletions tests/test_non_normalized_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from dask.distributed import Client, LocalCluster
from numba import cuda

import naive

try:
from numba.errors import NumbaPerformanceWarning
except ModuleNotFoundError:
Expand Down Expand Up @@ -352,18 +354,65 @@ def test_snippets():

@pytest.mark.parametrize("T, m", test_data)
def test_stimp(T, m):
if T.ndim > 1:
T = T.copy()
T = T[0]
n = 3
seed = np.random.randint(100000)

np.random.seed(seed)
ref = stumpy.aamp_stimp(T, m)
comp = stumpy.stimp(T, m, normalize=False)
npt.assert_almost_equal(ref.PAN_, comp.PAN_)
for i in range(n):
ref.update()

np.random.seed(seed)
cmp = stumpy.stimp(T, m, normalize=False)
for i in range(n):
cmp.update()

# Compare raw pan
ref_PAN = ref._PAN
cmp_PAN = cmp._PAN

naive.replace_inf(ref_PAN)
naive.replace_inf(cmp_PAN)

npt.assert_almost_equal(ref_PAN, cmp_PAN)

# Compare transformed pan
npt.assert_almost_equal(ref.PAN_, cmp.PAN_)


@pytest.mark.filterwarnings("ignore:\\s+Port 8787 is already in use:UserWarning")
@pytest.mark.parametrize("T, m", test_data)
def test_stimped(T, m, dask_cluster):
if T.ndim > 1:
T = T.copy()
T = T[0]
n = 3
seed = np.random.randint(100000)
with Client(dask_cluster) as dask_client:
np.random.seed(seed)
ref = stumpy.aamp_stimped(dask_client, T, m)
comp = stumpy.stimped(dask_client, T, m, normalize=False)
npt.assert_almost_equal(ref.PAN_, comp.PAN_)
for i in range(n):
ref.update()

np.random.seed(seed)
cmp = stumpy.stimped(dask_client, T, m, normalize=False)
for i in range(n):
cmp.update()

# Compare raw pan
ref_PAN = ref._PAN
cmp_PAN = cmp._PAN

naive.replace_inf(ref_PAN)
naive.replace_inf(cmp_PAN)

npt.assert_almost_equal(ref_PAN, cmp_PAN)

# Compare transformed pan
npt.assert_almost_equal(ref.PAN_, cmp.PAN_)


@pytest.mark.filterwarnings("ignore", category=NumbaPerformanceWarning)
Expand All @@ -372,6 +421,30 @@ def test_gpu_stimp(T, m):
if not cuda.is_available(): # pragma: no cover
pytest.skip("Skipping Tests No GPUs Available")

if T.ndim > 1:
T = T.copy()
T = T[0]
n = 3
seed = np.random.randint(100000)

np.random.seed(seed)
ref = stumpy.gpu_aamp_stimp(T, m)
comp = stumpy.gpu_stimp(T, m, normalize=False)
npt.assert_almost_equal(ref.PAN_, comp.PAN_)
for i in range(n):
ref.update()

np.random.seed(seed)
cmp = stumpy.gpu_stimp(T, m, normalize=False)
for i in range(n):
cmp.update()

# Compare raw pan
ref_PAN = ref._PAN
cmp_PAN = cmp._PAN

naive.replace_inf(ref_PAN)
naive.replace_inf(cmp_PAN)

npt.assert_almost_equal(ref_PAN, cmp_PAN)

# Compare transformed pan
npt.assert_almost_equal(ref.PAN_, cmp.PAN_)