Skip to content

Commit

Permalink
Use more conservative initial bracket (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Oct 25, 2021
1 parent c50ce62 commit 31b1c38
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Bijectors"
uuid = "76274a88-744f-5084-9051-94815aaf08c4"
version = "0.9.10"
version = "0.9.11"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
9 changes: 6 additions & 3 deletions src/bijectors/planar_layer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ Thus
α̂ - |wt_u_hat| - wt_y \\leq 0 \\leq α̂ + |wt_u_hat| - wt_y,
```
which implies ``α̂ ∈ [wt_y - |wt_u_hat|, wt_y + |wt_u_hat|]``.
To avoid floating point issues if ``α̂ = wt_y ± |wt_u_hat|``, we use the more conservative
interval ``[wt_y - 2 |wt_u_hat|, wt_y + 2|wt_u_hat|]`` as initial bracket, at the cost of
one additional iteration step.
# References
Expand All @@ -155,9 +158,9 @@ function find_alpha(wt_y::Real, wt_u_hat::Real, b::Real)
end
function find_alpha(wt_y::T, wt_u_hat::T, b::T) where {T<:Real}
# Compute the initial bracket (see above).
abs_wt_u_hat = abs(wt_u_hat)
lower = float(wt_y - abs_wt_u_hat)
upper = float(wt_y + abs_wt_u_hat)
Δ = 2 * abs(wt_u_hat)
lower = float(wt_y - Δ)
upper = float(wt_y + Δ)

# Handle empty brackets (https://github.com/TuringLang/Bijectors.jl/issues/204)
if lower == upper
Expand Down
7 changes: 7 additions & 0 deletions test/norm_flows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ end
end
end
end

# floating point issues
# https://github.com/TuringLang/Bijectors.jl/issues/204
wt_y = 0.8845640339582252
wt_u_hat = 0.8296950433716855
b = -1e8
@test Bijectors.find_alpha(wt_y, wt_u_hat, b) wt_y + wt_u_hat
end
end

Expand Down

2 comments on commit 31b1c38

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/47433

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.11 -m "<description of version>" 31b1c387ed6a243e02fd906cb615b61de47b935f
git push origin v0.9.11

Please sign in to comment.