Skip to content

Commit

Permalink
Move bijector definitions to utils.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxd3 committed Sep 7, 2023
1 parent 783c063 commit bedff95
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
37 changes: 0 additions & 37 deletions src/bijectors.jl

This file was deleted.

36 changes: 36 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,39 @@ function BangBang.NoBang._setindex(xs::AbstractArray, v::AbstractArray, I...)
ys[I...] = v
return ys
end

# defines some default bijectors for link functions
# these are currently not in use, because we transform the expression by calling inverse functions
# on the RHS (in the case of logical assignment) or disallow the use of link functions (in the case of
# stochastic assignments)

struct LogisticBijector <: Bijectors.Bijector end

Bijectors.transform(::LogisticBijector, x::Real) = logistic(x)
Bijectors.transform(::Inverse{LogisticBijector}, x::Real) = logit(x)
Bijectors.logabsdet(::LogisticBijector, x::Real) = log(logistic(x)) + log(1 - logistic(x))

struct CExpExp <: Bijectors.Bijector end

Bijectors.transform(::CExpExp, x::Real) = icloglog(x)
Bijectors.transform(::Inverse{CExpExp}, x::Real) = cloglog(x)
Bijectors.logabsdet(::CExpExp, x::Real) = -log(cloglog(-x))

struct ExpBijector <: Bijectors.Bijector end

Bijectors.transform(::ExpBijector, x::Real) = exp(x)
Bijectors.transform(::Inverse{ExpBijector}, x::Real) = log(x)
Bijectors.logabsdet(::ExpBijector, x::Real) = x

struct Phi <: Bijectors.Bijector end

Bijectors.transform(::Phi, x::Real) = phi(x)
Bijectors.transform(::Inverse{Phi}, x::Real) = probit(x)
Bijectors.logabsdet(::Phi, x::Real) = -0.5 * (x^2 + log(2π))

link_function_to_bijector_mapping = Dict(
:logit => LogisticBijector(),
:cloglog => CExpExp(),
:log => ExpBijector(),
:probit => Phi(),
)

0 comments on commit bedff95

Please sign in to comment.