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

Questions on custom bijectors #234

Open
vboussange opened this issue Nov 2, 2022 · 1 comment
Open

Questions on custom bijectors #234

vboussange opened this issue Nov 2, 2022 · 1 comment

Comments

@vboussange
Copy link

Hey guys, I really like that you provide this package independently from Turing.jl. I am actually making intensive use of Bijectors.jl for a project that I have called PiecewiseInference.jl.

I need to define few custom bijectors, and I would like to make sure that I am doing things right. Here is one that transforms a random variable with values in $\mathbb{R}$ to a random variable with values in $[C, \infty)$. Here is my code for it.

struct AbsCap{N,C} <: Bijector{N} 
    c::C
end
(a::AbsCap)(x) = x .- a.c # transform itself, "forward"
(a::Inverse{<: AbsCap})(y) = abs.(y) .+ a.orig.c # inverse transform, "backward"
logabsdetjac(::Abs{0}, y::Real) = zero(eltype(y))

Is everything alright in this piece of code?

Thanks a lot for your help!

@torfjelde
Copy link
Member

Hi!

Sorry, this went completely under my radar.

It's difficult for me to say what's "right" here as I don't know the transformation you're trying to implement.

But the transformation you've implemented is not bijective (abs maps both -1 and 1 to the same number).

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

No branches or pull requests

2 participants