-
Notifications
You must be signed in to change notification settings - Fork 22
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
add logabstanh
#86
base: master
Are you sure you want to change the base?
add logabstanh
#86
Conversation
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.
Thank you! Can you add tests and update the docs? Probably should also add a ChainRules definition.
src/basicfuns.jl
Outdated
The implementation ensures `logabstanh(-x) = logabstanh(x)`. | ||
""" | ||
function logabstanh(x::Real) | ||
return log1p(-2/((exp(2abs(x))+1))) |
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.
As indicated by the special cases close to 0 for Float32 and Float64, maybe a safer default would be
return log1p(-2/((exp(2abs(x))+1))) | |
return log(abs(tanh(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.
I think the version I wrote stays more accurate overall but I'll do a test
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.
I don't think it's possible to do such an analysis? You can't realistically test any subtype of Real
.
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.
for any AbstractFloat
log(tanh(x))
will be inaccurate for large x since tanh(x)
will be very close to 1.
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
as requested by @c05 on slack. This has 15 ULP for Float64, and 5 ULP for Float32.