-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
ENH: small speedup for stats.gaussian_kde #8558
Conversation
The appveyor failures are all related to convexhull, so I believe that they are unrelated to this change. |
Thanks Gael. Can you put the benchmark in https://github.com/scipy/scipy/blob/master/benchmarks/benchmarks/stats.py? Then we will notice any regressions. |
I've added a couple of benchmarks, in the small n regime, and in the large n regime. I must confess that I haven't ran them (I think that the README isn't up to date). |
Thanks. The
|
I don't see where runtests.py is :$
|
It sits at the root of the scipy repository |
AFAIK, the readme is up to date?
|
AFAIK, the readme is up to date?
Yes, I was goofing up :)
|
Benchmarks look good:
Numerically the old and new implementation are not identical - typical differences are |
I initially thought it's fine as is, but reading again, I think the cholesky should be stored and attached as private attribute. The immediate advantage is that repeated calls don't have to redo the cholesky. Beyond this PR, there might be some savings in other places like rvs to use the stored cholesky of cov_inv. (aside: current behavior assumes cov is non-singular, alternative to inv and cholesky would be to use SVD which would extend to (numerically) singular cov. But I never looked at kde with singular cov to have any idea about those use cases..) |
OK, @josef-pkt . This entail a bit more work, but if done properly, I agree that it should give additional benefits. I'll try to find time to work on this this week. |
How about we merge it as is, and work on storing the result of Cholesky factorization in a follow-up PR? Otherwise this is in danger of sliding under everyone's radar, I'm afraid. |
Sounds good to me. I'll look at doing that before the 1.2.x branching on 5 Nov unless there are more comments. |
A 20% speedup in gaussian_kde.evaluate when the number of points is large (whether it is in the dataset, or the points on which the KDE is evaluated).
Rebased and all green, so merging. Thanks @GaelVaroquaux, all! |
Thanks @rgommers for making sure that this got in. My apologies for not being able to do more. I've had a tab opened on my browser for months, but it was not sufficient :). |
We're using the same system:) after 20 tabs it stops working .... |
I observe 100% speedup. Before:
After:
What is interesting, before this commit, all CPUs are being used by computation (mostly trashed by kernel). Take a look at user and sys times. After this change, only one thread is being used. I did not check out the whole git repository, just downloaded the current version of this file, so the rest of scipy is 1.1.0 with 1.15.4 numpy. |
A 20% speedup in gaussian_kde.evaluate when the number of points is large (whether it is in the dataset, or the points on which the KDE is evaluated).
The speedup isn't huge, so I won't be offended if this is not merged :).
To benchmark, I adapted the example in the docstring:
Timing can then be done (in IPython):
%timeit kernel(positions)
With master, I get 2.17s, with this branch 1.73s.