-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
extra::stats suffers from catastrophic cancellation #10851
Comments
I'm happy to mentor someone through this as a relatively easy first bug. (Feel free to talk to me here, or ping me (nick: dbaupp) on IRC.) |
If I've understood correctly, I have to implement Kahan summation here. |
Yes, that's exactly correct; you can either convert the Also, another neat thing to do would be to make the variance calculation more numerically stable, e.g. using this or this. |
(Also, sorry for repeatedly missing you on IRC; I'm in Australia which means that our times seem to not line up. :( ) |
@huonw |
I certainly don't mind, go for it! Feel free to attempt to catch me in IRC if you have any questions (or just throw them here, or email me (should be visible in my github profile)). |
Hey @huonw, I have implemented the compensated summation but it has not done any impact. |
Hm, Python has >>> import math
>>> math.fsum([1e20, 1, -1e20])
1.0 so we may need to use a different algorithm. |
OK, I will take a look at this :D. |
The implementation of It would be good for the documentation on (That implementation of Kahan summation looks good.) |
`[1e20, 1.0, -1e20].sum()` returns `0.0`. This happens because during the summation, `1.0` is too small relative to `1e20`, making it negligible. I have tried Kahan summation but it hasn't fixed the problem. Therefore, I've used Python's `fsum()` implementation. For more details, read: www.cs.cmu.edu/~quake-papers/robust-arithmetic.ps #10851 Python's fsum (msum) http://code.activestate.com/recipes/393090/ @huonw, your feedback is more than welcome. It looks unpolished; Do you have suggestions how to make it more beautiful and elegant? Thanks in advance,
Fixed by #10927. |
It is using the naive algorithm which is numerically unstable; it should be using something like Kahan summation.
The text was updated successfully, but these errors were encountered: