TuringLang / Bijectors.jl

Implementation of normalising flows and constrained random variable transformations
https://turinglang.org/Bijectors.jl/
MIT License
200 stars 33 forks source link

SimplexBijector tests fails on boundary #232

Open torfjelde opened 1 year ago

torfjelde commented 1 year ago

https://github.com/TuringLang/Bijectors.jl/blob/6f05a87647a05ab71c1602dffbb6d28d89dcd57e/test/interface.jl#L445-L449

causes issues because

julia> using Bijectors, ForwardDiff

julia> b = Bijectors.SimplexBijector{false}();

julia> x = [1.0, 0.0];

julia> logabsdetjac(b, x)
36.04365338911715
julia> log(abs(det(ForwardDiff.jacobian(b, x))))  # (✓) Same!
36.04365338911715

julia> x = [0.9999999999999999, 0.0];

julia> logabsdetjac(b, x)
36.04365338911715

julia> log(abs(det(ForwardDiff.jacobian(b, x))))  # (×) Different
35.63818828100899

And [0.9999999999999999, 0.0] is indeed a possible realization from Dirichlet even though it's technically not in the support:

julia> using StableRNGs

julia> dist = Dirichlet([1000 * one(Float64), eps(Float64)]);

julia> rand(StableRNG(2), dist)
2-element Vector{Float64}:
 0.9999999999999999
 0.0

julia> insupport(dist, [0.9999999999999999, 0.0])
true