Fixed #1112 Migrate to New NumPy Random Number Generator (RNG) API#1131
Fixed #1112 Migrate to New NumPy Random Number Generator (RNG) API#1131seanlaw wants to merge 7 commits intostumpy-dev:mainfrom
Conversation
|
Review these changes at https://app.gitnotebooks.com/stumpy-dev/stumpy/pull/1131 |
|
@NimaSarajpoor I've tested the migration on |
NimaSarajpoor
left a comment
There was a problem hiding this comment.
@seanlaw
I've left just one comment for your consideration.
|
@NimaSarajpoor If it's okay with you, I'm going to add ~5 files at a time for you to incrementally review (there are 46 test files in total and I'll need to work on tutorials and other docs too). |
|
Things are starting to get tricky. Previously, |
|
@NimaSarajpoor I added three new files for you to review |
| np.random.seed(1234) | ||
| pytest.fix_rng_state() | ||
|
|
||
| # The time series is random noise with two motifs for m=10: |
There was a problem hiding this comment.
| # The time series is random noise with two motifs for m=10: | |
| # The time series is random noise with two motifs for m=20: |
According to Line 80: m = 20
| # naive.distance(naive.z_norm(T[10:30]), naive.z_norm(T[110:130])) = 0.47 | ||
| # naive.distance(naive.z_norm(T[10:30]), naive.z_norm(T[210:230])) = 0.24 | ||
| # naive.distance(naive.z_norm(T[110:130]), naive.z_norm(T[210:230])) = 0.72 | ||
| # Hence T[10:30] is the motif representative for this motif |
There was a problem hiding this comment.
I think these comments should be revised. They show the calculation of z-normalized distances. However, aamp_motifs is for non-normalized case.
| ) | ||
| motif_indices_ref = np.array([[19, 77, 63, 52, 71]]) | ||
| motif_subspaces_ref = [np.array([2])] | ||
| motif_distances_ref = np.array([[0.0, 0.10660435, 0.27927693]]) |
There was a problem hiding this comment.
I cannot figure out how these numbers are obtained. Since tests are passing, I guess all is good here. I guess these numbers are revised to match the actual output. So... an off-topic question: are we cheating here by using ref values that are based on the calculation of outputs obtained from performant function ?
| # * (almost) identical step functions at indices 10, 110 and 210 | ||
| # * identical linear slopes at indices 70 and 170 | ||
| T = np.random.normal(size=300) | ||
| T = pytest.RNG.normal(size=300) |
There was a problem hiding this comment.
To be consistent with other test functions, I was wondering if we should go with random rather than normal distribution.
| npt.assert_almost_equal(ref_subseq_idx, comp_subseq_idx) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("seed", [41, 88, 290, 292, 310, 328, 538, 556, 563, 570]) |
There was a problem hiding this comment.
I think you missed removing this one.
|
|
||
|
|
||
| @pytest.mark.parametrize("seed", [41, 88, 290, 292, 310, 328, 538, 556, 563, 570]) | ||
| def test_deterministic_ostinatoed(seed, dask_cluster): |
There was a problem hiding this comment.
| def test_deterministic_ostinatoed(seed, dask_cluster): | |
| def test_deterministic_ostinatoed(dask_cluster): |
|
|
||
| T[70:90] = np.arange(m) * 0.1 | ||
| T[170:190] = np.arange(m) * 0.1 | ||
| # naive.distance(naive.z_norm(T[70:90]), naive.z_norm(T[170:190])) = 0.0 |
There was a problem hiding this comment.
| # naive.distance(T[70:90], T[170:190]) = 0.0 |
| def test_random_ostinatoed(seed, dask_cluster): | ||
| with Client(dask_cluster) as dask_client: | ||
| def test_deterministic_ostinato(): | ||
| pytest.fix_rng_state() |
There was a problem hiding this comment.
Do we need to fix state here? I can see we do not fix state for test_random_ostinato, and that should be OK.
|
|
||
| @pytest.mark.parametrize("seed", [41, 88, 290, 292, 310, 328, 538, 556, 563, 570]) | ||
| def test_deterministic_ostinatoed(seed, dask_cluster): | ||
| pytest.fix_rng_state() |
There was a problem hiding this comment.
Do we need to fix state here? I can see we do not fix state for test_random_ostinato.
Pull Request Checklist
Below is a simple checklist but please do not hesitate to ask for assistance!
black(i.e.,python -m pip install blackorconda install -c conda-forge black)flake8(i.e.,python -m pip install flake8orconda install -c conda-forge flake8)pytest-cov(i.e.,python -m pip install pytest-covorconda install -c conda-forge pytest-cov)black --exclude=".*\.ipynb" --extend-exclude=".venv" --diff ./in the root stumpy directoryflake8 --extend-exclude=.venv ./in the root stumpy directory./setup.sh dev && ./test.shin the root stumpy directoryTo Do List
np.randomnp.random.rand(x)withpytest.RNG.random(x)np.random.rand(x*y).reshape(x,y)withpytest.RNG.random(size=(x, y))np.random.uniform(x, y, [z])withpytest.RNG.uniform(x, y, size=z)np.random.permutation([x, y, z])withpytest.RNG.permutation([x, y, z])np.random.randint(x, y, z)withpytest.RNG.integers(x, y, z)np.random.choice([x, y], l, replace=True)withpytest.RNG.choice([x, y], l, replace=True)np.random.normal(size=x)withpytest.RNG.normal(size=x)