-
Notifications
You must be signed in to change notification settings - Fork 593
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
Clip exponential in ffunc to avoid overflow #201
Conversation
This should avoid (hopefully) some possible FloatingPointError overflow errors. The sigmoid function ffunc is for any x<-20 and x>20 already 0 resp. 1 up to 10^-9 and cutting will therefore not change the function substantially. This idea is from @tmbdev in #5 (comment) Implemented first in #49 (comment) Additional infos from #79 (comment)
Note that some lines above we have: def sigmoid(x):
"""Compute the sigmoid function.
We don't bother with clipping the input value because IEEE floating
point behaves reasonably with this function even for infinities."""
return 1.0/(1.0+exp(-x))
|
-20/20 seems to be overly conservative but should work. Ultimately the gradients are important and they are negligible even at -10/10. On another note You won't need both
|
I'd like to merge it, and/or try @mittagessen's proposed scipy fix. @zuphilip do you have data to test this? |
@kba I think it is good to merge this. Maybe reformulate the contradicting comment before... I don't have data for reproduce the error, but there is at least one confirmation #246 (comment) that after this fix it worked fine. |
Yes, this will fix a breaking bug, so let's merge it. Just would be interesting to test |
@mittagessen and @kba Thank you for helping here! |
https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.expit.html#scipy.special.expit @mittagessen mentioned this function as a replacement to sigmoid/ffunc. |
This should avoid (hopefully) some possible FloatingPointError overflow errors.
The sigmoid function ffunc is for any x<-20 and x>20 already 0 resp. 1 up to 10^-9
and cutting will therefore not change the function substantially.
This idea is from @tmbdev in #5 (comment)
Implemented first in #49 (comment)
Additional infos from #79 (comment)