-
Notifications
You must be signed in to change notification settings - Fork 35
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
Better expm1 #117
Comments
Thanks for the hint! Not sure why I was not aware of that... But it is not that bad now either:
So I need to see what I can gain. Will try it out. |
I checked it in python, and the two formulas match to within 1e-16 at your threshold, which is at the limits of float64. I guess the only difference would be the speed difference in the two implementations in julia. The implementation I use in my C++ solver is equivalent to:
I am curious though about: and why not use:
as done here: |
Well, I don't recall why... julia> B(x)=x/expm1(x);
julia> B0(x)=1/(1+0.5x);
julia> B0(0.0)
1.0
julia> B0(nextfloat(0.0))
1.0
julia> ForwardDiff.derivative(B0,0)
-0.5
julia> ForwardDiff.derivative(B0,nextfloat(0.0))
-0.5
julia> ForwardDiff.derivative(B,nextfloat(0.0))
NaN |
Very cool. I had to look up what Nerd Sniping was. |
In my code, this is what I end up using for the derivative of
and so it works well even with extended precision. The full implementation is here: where I have to account for numerical issues I was having with the Android version of |
So finally, thanks for this discussion, which lead to a more concise implementation. |
https://github.com/j-fu/VoronoiFVM.jl/blob/975d5b1f9a2d21988dd84d61f4e58b76769d5250/src/vfvm_functions.jl#L79
To avoid precision loss, please consider using the Julia function for
expm1
, which offers better precision for small arguments:https://docs.julialang.org/en/v1/base/math/#Base.expm1
The text was updated successfully, but these errors were encountered: