Skip to content

Commit

Permalink
Run interface tests, update badges, and fix planar layer (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Jan 8, 2021
1 parent e6b7c9c commit 06fa669
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 48 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/Interface.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

name: Interface tests

on:
push:
branches:
- master
pull_request:

jobs:
test:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.version == 'nightly' }}
strategy:
matrix:
version:
- '1.3'
- '1'
os:
- ubuntu-latest
- macOS-latest
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
env:
GROUP: Interface
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

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.8.10"
version = "0.8.11"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
# Bijectors.jl

[![Build Status](https://travis-ci.org/TuringLang/Bijectors.jl.svg?branch=master)](https://travis-ci.org/TuringLang/Bijectors.jl)

[![ForwardDiff and Tracker tests](https://github.com/TuringLang/Bijectors.jl/workflows/ForwardDiff%20and%20Tracker%20tests/badge.svg?branch=master)](https://github.com/TuringLang/Bijectors.jl/actions?query=workflow%3A%22ForwardDiff+and+Tracker+tests%22)

[![Zygote tests](https://github.com/TuringLang/Bijectors.jl/workflows/Zygote%20tests/badge.svg?branch=master)](https://github.com/TuringLang/Bijectors.jl/actions?query=workflow%3A%22Zygote+tests%22)

[![ReverseDiff tests](https://github.com/TuringLang/Bijectors.jl/workflows/ReverseDiff%20tests/badge.svg)](https://github.com/TuringLang/Bijectors.jl/actions?query=workflow%3A%22ReverseDiff+tests%22)

[![Interface tests](https://github.com/TuringLang/Bijectors.jl/workflows/Interface%20tests/badge.svg?branch=master)](https://github.com/TuringLang/Bijectors.jl/actions?query=workflow%3A%22Interface+tests%22+branch%3Amaster)
[![AD tests](https://github.com/TuringLang/Bijectors.jl/workflows/AD%20tests/badge.svg?branch=master)](https://github.com/TuringLang/Bijectors.jl/actions?query=workflow%3A%22AD+tests%22+branch%3Amaster)

This package implements a set of functions for transforming constrained random variables (e.g. simplexes, intervals) to Euclidean space. The 3 main functions implemented in this package are the `link`, `invlink` and `logpdf_with_trans` for a number of distributions. The distributions supported are:
1. `RealDistribution`: `Union{Cauchy, Gumbel, Laplace, Logistic, NoncentralT, Normal, NormalCanon, TDist}`,
Expand Down
36 changes: 22 additions & 14 deletions src/bijectors/planar_layer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function forward(flow::PlanarLayer, z::AbstractVecOrMat)
else
T = typeof(vec(psi))
end
log_det_jacobian::T = log.(abs.(1.0 .+ psi' * u_hat)) # from eq(12)
log_det_jacobian::T = log.(abs.(1 .+ psi' * u_hat)) # from eq(12)
return (rv = transformed, logabsdetjac = log_det_jacobian)
end

Expand All @@ -75,7 +75,7 @@ function (ib::Inverse{<:PlanarLayer})(y::AbstractVector{<:Real})
wt_u_hat = dot(w, u_hat)
alpha = find_alpha(wt_y, wt_u_hat, b)

return y .- u_hat .* tanh(alpha * norm(w, 2) + b)
return y .- u_hat .* tanh(alpha + b)
end

function (ib::Inverse{<:PlanarLayer})(y::AbstractMatrix{<:Real})
Expand All @@ -90,36 +90,44 @@ function (ib::Inverse{<:PlanarLayer})(y::AbstractMatrix{<:Real})
find_alpha(dot(w, c), wt_u_hat, b)
end

return y .- u_hat .* tanh.(reshape(alphas, 1, :) .* norm(w, 2) .+ b)
return y .- u_hat .* tanh.(reshape(alphas, 1, :) .+ b)
end

"""
find_alpha(wt_y, wt_u_hat, b)
Compute an (approximate) real-valued solution ``α`` to the equation
Compute an (approximate) real-valued solution ``α̂`` to the equation
```math
wt_y = α + wt_u_hat tanh(α + b)
```
The uniqueness of the solution is guaranteed since ``wt_u_hat ≥ -1``.
For details see appendix A.1 of the reference.
# Initial bracket
For all ``α``, we have
```math
α - |wt_u_hat| - wt_y \\leq α + wt_u_hat tanh(α + b) - wt_y \\leq α + |wt_u_hat| - wt_y.
```
Thus
```math
α̂ - |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|]``.
# References
D. Rezende, S. Mohamed (2015): Variational Inference with Normalizing Flows.
arXiv:1505.05770
"""
function find_alpha(wt_y, wt_u_hat, b)
# Compute the initial bracket ((-Inf, 0) or (0, Inf))
f0 = wt_u_hat * tanh(b) - wt_y
zero_f0 = zero(f0)
if f0 < zero_f0
initial_bracket = (zero_f0, oftype(f0, Inf))
else
initial_bracket = (oftype(f0, -Inf), zero_f0)
end
prob = NonlinearSolve.NonlinearProblem{false}(initial_bracket) do x, _
x + wt_u_hat * tanh(x + b) - wt_y
# Compute the initial bracket.
_wt_y, _wt_u_hat, _b = promote(wt_y, wt_u_hat, b)
initial_bracket = (_wt_y - abs(_wt_u_hat), _wt_y + abs(_wt_u_hat))

prob = NonlinearSolve.NonlinearProblem{false}(initial_bracket) do α, _
α + _wt_u_hat * tanh+ _b) - _wt_y
end
alpha = NonlinearSolve.solve(prob, NonlinearSolve.Falsi()).left
return alpha
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ using DistributionsAD: TuringUniform, TuringMvNormal, TuringMvLogNormal,

import NNlib

const is_TRAVIS = haskey(ENV, "TRAVIS")
const GROUP = get(ENV, "GROUP", "All")

# Always include this since it can be useful for other tests.
Expand All @@ -35,7 +34,7 @@ if GROUP == "All" || GROUP == "Interface"
include("bijectors/coupling.jl")
end

if !is_TRAVIS && (GROUP == "All" || GROUP == "AD")
if GROUP == "All" || GROUP == "AD"
include("ad/distributions.jl")
end

2 comments on commit 06fa669

@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/27564

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.8.11 -m "<description of version>" 06fa669895209578c6d25133dabe69620fd81187
git push origin v0.8.11

Please sign in to comment.