Closed quant12345 closed 1 year ago
Name | Link |
---|---|
Latest commit | e96a4564e31bf61cf2b62bddbb21bb88fbcfacac |
Latest deploy log | https://app.netlify.com/sites/hyppo/deploys/64fb1b019754840008b7fb2e |
Deploy Preview | https://deploy-preview-403--hyppo.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Tests are down. I assume that the 'MST' function that calls 'prim' has a numba decorator. I tried locally without the decorator, the function worked without errors. I'll try to make the 'MST' function without loops so as not to use a decorator. If possible, show sample data: x, labels for the MST function.
Sounds good. After everything works, I'd like to see the wall times figure again as shown in #402
Patch coverage: 100.00%
and project coverage change: +0.01%
:tada:
Comparison is base (
9e7fc39
) 96.71% compared to head (e96a456
) 96.72%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I removed the numba decorators and its imports. I made a version of the 'MST' function without cycles, but did not add it to the commit. On the attached chart, the 'Rafsky_performance.py' script is running: the original is running without numba. Function MST_new(new_alg) is a variant without cycles, MST_old_prim_new(new_alg_MSTold) MST is calculated as before. Both options calculation the 'prim' function in a new way. It can be seen that the new version ' MST' begins to deteriorate sharply at the end.
The 'Rafsky_loop.py' script counts in cycles: displays the elapsed time of each algorithm. And the ratio of the original algorithm to one of the new algorithms (in this case, MST_new). As before, the first run in 70-130 slower on numba.
And the question is the list 'i_min' if it is empty, that is, there is no minimum, an error may occur, but this is in theory. I have run scripts dozens of times, this has never happened. Can put a check on an empty list, but this will slightly reduce performance.?
I am attaching both scripts (Rafsky.tar.gz). Rafsky.tar.gz
n 100
time_original 0:00:02.309068
time_MST_old_prim_new 0:00:00.041586
time_new 0:00:00.026029
difference in time original / new 88.71136040570133
difference in time original / MST_old 55.52512864906459
*******************************************************
n 205
time_original 0:00:02.260544
time_MST_old_prim_new 0:00:00.197153
time_new 0:00:00.101197
difference in time original / new 22.33805349960967
difference in time original / MST_old 11.46593762204988
*******************************************************
n 450
time_original 0:00:02.429262
time_MST_old_prim_new 0:00:01.229136
time_new 0:00:01.046668
difference in time original / new 2.320947998792358
difference in time original / MST_old 1.976398055219276new
Tried several times to run the loop with different options. With an array size of 100, the first run is 50-130 times faster than numba. In this case, the calculation in numba lasts two seconds. With an array of 205, the difference is already 10 - 30 times faster, with 450 the difference is 2-3 times.
Probably even at the first start numba starts to accelerate after a certain time. Because with an array size of 10, the first run on numba takes 2.30 seconds and the same elapsed time for an array of 100.
Attached is the 'newRafsky_loop.py' file. In it, at the first iteration, the ratio of time to the original algorithm is considered, and vice versa at all subsequent iterations. The data is printed out.
If you will merge, there is a question. INF = 9999999 used to initialize the first minimum (in my opinion, this is the largest number, in fact it is: np.inf ).
Then sample < minimum is not needed. And instead of:
i_min = np.where((sample < minimum) & (sample == np.min(sample[np.nonzero(sample)])))
just need:
i_min = np.where(sample == np.min(sample[np.nonzero(sample)]))
Tests are down. I assume that the 'MST' function that calls 'prim' has a numba decorator. I tried locally without the decorator, the function worked without errors. I'll try to make the 'MST' function without loops so as not to use a decorator. If possible, show sample data: x, labels for the MST function.
Sounds good. After everything works, I'd like to see the wall times figure again as shown in #402
Will there be any reaction to the changes?
@sampan501 P.S. I left in i_min only finding the minimum, because I think thatโs what happens in the original, since INF is simply the largest number. And tests and comparisons give identical arrays. As a result, with numba the first launch is slower until about array size n - 450.
I also tried an array size of 4096 with numba and below is a graph with the results, where at the end the array size is 4096(with this size, the calculation of both algorithms lasted more than 20 minutes).
@quant12345 Thank you for your hard work. Once you add a unit test specific for your changes that verifies that given a mwe, you get the same answer, we should be good to merge
@sampan501
This is here I found the tests. Now I discovered that in the 'FriedmanRafsky class', the 'test' method has 'self.statistic' and it probably runs 'MST' multiple times, which runs 'prim'. If in reality this is the case, then my algorithm will lose to numba and my changes do not make sense. However, I am attaching a file with the old and new classes, the 'friedman_rafsky.py' file, which is used for tests.
Probably doesn't make sense.
Yes that test method uses that to estimate a p-value
Closes issue #402
After discussion here:
I would like to improve the function code: prim from the class: FriedmanRafsky.
Since the function has a decorator:
@jit(nopython=True, cache=True)
using numba, the first start is warming up and lasts a long time. For a 100 x 100 array, it turned out 30 - 120 times slower than my version on the first run. True, subsequent launches are about 5 times faster than my version.If you do not use numba, then the speedup is about 29 times with an array of 500 x 500. The speedup starts with an array size starting from 20 x 20.