-
Notifications
You must be signed in to change notification settings - Fork 40
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
Pre-calculate mean instead of nothing for efficiency #15
Conversation
This only changes the place where the mean is calculated. It now calculated a bit later in |
@mschauer but most of the api called |
The algorithm is only implemented for |
@mschauer It's not only implemented for And this is how the |
As mentioned above, the efficient implementation for var and mean simultaneously maybe mean this: However, it happens in the case that mean is Another way is to accept As my point of view, the implementation here mixes the implementation and interface. It may need refactoring. |
Actually IIRC Welford's algorithm isn't more efficient, it's just the only way to compute the variance if you are not allowed to make two passes over the data (for general iterators). But for arrays it's better to do two efficient passes (using SIMD) than a single slow pass. Wikipedia notes "This algorithm is much less prone to loss of precision due to catastrophic cancellation, but might not be as efficient because of the division operation inside the loop." Anyway, this can be checked quite easily if you want. But TBH I don't really understand what problem this PR tries to address: is it efficiency or just API simplicity? Anyway, this PR would break the current API which allows passing |
@nalimilan The problem this PR tries to address is that we will calculate the ALSO, the But TBH the current API is a little messy. We shouldn’t use keyword argument on internal functions since they can have some impact on the performance. We would need a throughout internal API redesign. |
OK, I see. Good catch. I guess the simplest solution then it to replace The performance impact of keyword arguments is much lower than what it used to be AFAIK, so better check that it really makes a difference before redesigning the whole thing. Also we're talking about functions which are relatively expensive so the overhead should be negligible. |
I open another PR to refactor API directly. #17 |
No description provided.