Skip to content

Commit

Permalink
Merge pull request #41 from TuringLang/torfjelde/Bijectors-compat
Browse files Browse the repository at this point in the history
Bump Bijectors.jl compat bounds
  • Loading branch information
yebai committed Feb 3, 2023
2 parents bb7e85c + 7c2f30c commit 64ef0ee
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- os: macOS-latest
arch: x86
include:
- version: '1.0'
- version: '1.6'
os: ubuntu-latest
arch: x64
- os: ubuntu-latest
Expand Down Expand Up @@ -60,4 +60,4 @@ jobs:
if: matrix.coverage
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: lcov.info
path-to-lcov: lcov.info
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AdvancedVI"
uuid = "b5ca4192-6429-45e5-a2d9-87aec30a685c"
version = "0.1.6"
version = "0.2.0"

[deps]
Bijectors = "76274a88-744f-5084-9051-94815aaf08c4"
Expand All @@ -17,7 +17,7 @@ StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"

[compat]
Bijectors = "0.4.0, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10"
Bijectors = "0.11, 0.12"
Distributions = "0.21, 0.22, 0.23, 0.24, 0.25"
DistributionsAD = "0.2, 0.3, 0.4, 0.5, 0.6"
DocStringExtensions = "0.8, 0.9"
Expand All @@ -27,7 +27,7 @@ Requires = "0.5, 1.0"
StatsBase = "0.32, 0.33"
StatsFuns = "0.8, 0.9, 1"
Tracker = "0.2.3"
julia = "1"
julia = "1.6"

[extras]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand Down
1 change: 1 addition & 0 deletions src/AdvancedVI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ end
const DEBUG = Bool(parse(Int, get(ENV, "DEBUG_ADVANCEDVI", "0")))

include("ad.jl")
include("utils.jl")

using Requires
function __init__()
Expand Down
6 changes: 3 additions & 3 deletions src/advi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ function (elbo::ELBO)(
# = 𝔼[log p(x, f⁻¹(z̃)) + logabsdet(J(f⁻¹(z̃)))] + ℍ(q̃(z̃))
# = 𝔼[log p(x, z) - logabsdetjac(J(f(z)))] + ℍ(q̃(z̃))

# But our `forward(q)` is using f⁻¹: ℝ → supp(p(z | x)) going forward → `+ logjac`
_, z, logjac, _ = forward(rng, q)
# But our `rand_and_logjac(q)` is using f⁻¹: ℝ → supp(p(z | x)) going forward → `+ logjac`
z, logjac = rand_and_logjac(rng, q)
res = (logπ(z) + logjac) / num_samples

if q isa TransformedDistribution
Expand All @@ -92,7 +92,7 @@ function (elbo::ELBO)(
end

for i = 2:num_samples
_, z, logjac, _ = forward(rng, q)
z, logjac = rand_and_logjac(rng, q)
res += (logπ(z) + logjac) / num_samples
end

Expand Down
16 changes: 16 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Distributions

using Random: Random
using Bijectors: Bijectors


function rand_and_logjac(rng::Random.AbstractRNG, dist::Distribution)
x = rand(rng, dist)
return x, zero(eltype(x))
end

function rand_and_logjac(rng::Random.AbstractRNG, dist::Bijectors.TransformedDistribution)
x = rand(rng, dist.dist)
y, logjac = Bijectors.with_logabsdet_jacobian(dist.transform, x)
return y, logjac
end

2 comments on commit 64ef0ee

@yebai
Copy link
Member Author

@yebai yebai commented on 64ef0ee Feb 3, 2023

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/76962

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.2.0 -m "<description of version>" 64ef0ee2c1a94459bfb5fb1970bdfdcf70ffbf84
git push origin v0.2.0

Please sign in to comment.