[Failed] Fixed #1112 Migrate to New NumPy Random Number Generator (RNG) API#1131
[Failed] Fixed #1112 Migrate to New NumPy Random Number Generator (RNG) API#1131seanlaw wants to merge 9 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 |
| # 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.
There was a problem hiding this comment.
Hmm, what should it be changed to? I don't remember adding this comment :(
This?
# naive.distance(T[10:30], T[110:130]) = 0.47
# naive.distance(T[10:30], T[210:230]) = 0.24
# naive.distance(T[110:130], T[210:230]) = 0.72
# Hence T[10:30] is the motif representative for this motif
There was a problem hiding this comment.
I just recalculated the numbers for non-normalized distance.
# naive.distance(T[10:30], T[110:130]) = 16.65
# naive.distance(T[10:30], T[210:230]) = 0.1
# naive.distance(T[110:130], T[210:230]) = 16.68
# Hence T[10:30] is the motif representative for this motif
There was a problem hiding this comment.
Maybe we should use == because I had interpreted it as setting the distance rather than the value of the distance
There was a problem hiding this comment.
Right... == should be used here 👍
|
I discovered yesterday that this migration will require a lot more work since, unlike the traditional As a result, I think I'm gonna need to start all over with a new PR and rethink what needs to be done |
Can you please provide an example for this so that I can better understand the challenge? Do we need to share random state in certain cases? Because I think we create a randomly-generated input data |
Here's a simple illustrative example. In this case, we have a dummy function (naive and performant) and all it does is take an array
Note that we have exactly this case in some of our Now, if we transition this "legacy" numpy code over to the modern way of implementing random number generators, we'd have to do something like (this is untested!): @NimaSarajpoor at least this is what I am thinking. Please see if you can get my point and feel free to ask clarifying questions! |
Got it 👍 And since we have a case like the following in some modules in then we cannot set the random state in |
That's right! Hence why I eventually came to the conclusion that the migration will be tricky and one needs to take extra care because tests were failing and really hard to understand why (because it was literally "random"). I'm going to close this PR (use it as a reference) and submit a brand new PR now that I know what to do (and hopefully don't encounter another problem). |
See #1112
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)np.randomfrom docstrings, README, tutorials, etc