-
Notifications
You must be signed in to change notification settings - Fork 34
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
Stackoverflow in custom bijector #292
Comments
I've also tried to define the bijector by following a similar recipe to that of the
|
The default implementation of You then get a stack overlflow error because In fact, here you don't really need to mess around with the I'd implement the above as: using ChangesOfVariables, InverseFunctions, StatsFuns
InverseFunctions.inverse(::typeof(tanh)) = atanh
InverseFunctions.inverse(::typeof(atanh), x) = tanh
function ChangesOfVariables.with_logabsdet_jacobian(::typeof(tanh), x::Real)
y = tanh(x)
return y, _logabsdetjac_tanh(x)
end
function ChangesOfVariables.with_logabsdet_jacobian(::typeof(atanh), y::Real)
x = atanh(y)
return x, -_logabsdetjac_tanh(x)
end
# Use the irrational representation `StatsFuns.logtwo` to defer type-promotion.
# Similarly, I've removed all explicit usages of `Float64`, e.g. converted `2.0` to `2`
# to allow type-promotion to do its thing rather than forcing usage of `Float64`.
_logabsdetjac_tanh(x::Real) = 2 * (StatsFuns.logtwo - x - softplus(-2 * x)) If you want a version that is supposed to act elementwise, then you can use julia> using Bijectors
julia> elementwise(tanh)(rand(10))
10-element Vector{Float64}:
0.22076308094447367
0.06828859488600718
0.3496810171644955
0.02413051400382789
0.6228303792319176
0.5772825278828461
0.7370222452215927
0.45865543543291265
0.6128386429868988
0.7094298145373448
julia> with_logabsdet_jacobian(elementwise(tanh), rand(10))
([0.5475308984676883, 0.7498770212815672, 0.11406375475912378, 0.04598020777639154, 0.41278517115619784, 0.3067650082385844, 0.6441810700388316, 0.7430095366528289, 0.7023124306195118, 0.2806093226497268], -3.5844094465162772) |
I am trying to define my own
Tanh
bijectorThe forward transformation appears to be working, but I am struggling to understand the error I am receiving when computing the
logpdf
The text was updated successfully, but these errors were encountered: