-
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
log1pexp, #52 #70
log1pexp, #52 #70
Conversation
log1pexp, use float
Looks good to me. |
merge? |
bump |
@@ -63,8 +63,8 @@ Return `log(1+exp(x))` evaluated carefully for largish `x`. | |||
This is also called the ["softplus"](https://en.wikipedia.org/wiki/Rectifier_(neural_networks)) | |||
transformation, being a smooth approximation to `max(0,x)`. Its inverse is [`logexpm1`](@ref). | |||
""" | |||
log1pexp(x::Real) = x < 18.0 ? log1p(exp(x)) : x < 33.3 ? x + exp(-x) : oftype(exp(-x), x) | |||
log1pexp(x::Float32) = x < 9.0f0 ? log1p(exp(x)) : x < 16.0f0 ? x + exp(-x) : oftype(exp(-x), x) | |||
log1pexp(x::Real) = x ≤ -37. ? exp(x) : x ≤ 18. ? log1p(exp(x)) : x ≤ 33.3 ? x + exp(-x) : float(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use ≤
here but <
in the Float32
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was now moved to JuliaStats/LogExpFunctions.jl#37. But to answer your question, I only copied the algorithm described in https://cran.r-project.org/web/packages/Rmpfr/vignettes/log1mexp-note.pdf, which uses ≤
here.
Should be moved to https://github.com/JuliaStats/LogExpFunctions.jl |
#52
(replaces #57)