Skip to content
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

Closed
wants to merge 1 commit into from
Closed

log1pexp, #52 #70

wants to merge 1 commit into from

Conversation

cossio
Copy link
Contributor

@cossio cossio commented May 21, 2019

#52

(replaces #57)

@cossio cossio mentioned this pull request May 21, 2019
src/basicfuns.jl Outdated Show resolved Hide resolved
log1pexp, use float
@dmbates
Copy link
Contributor

dmbates commented May 22, 2019

Looks good to me.

@cossio
Copy link
Contributor Author

cossio commented Jun 3, 2019

merge?

@cossio
Copy link
Contributor Author

cossio commented May 20, 2020

bump

@nalimilan nalimilan requested a review from dmbates June 7, 2020 14:22
@@ -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)
Copy link
Member

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?

Copy link
Contributor Author

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.

@andreasnoack
Copy link
Member

Should be moved to https://github.com/JuliaStats/LogExpFunctions.jl

@cossio cossio deleted the log1pexp branch March 7, 2022 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants