diff --git a/.github/workflows/Interface.yml b/.github/workflows/Interface.yml new file mode 100644 index 00000000..d670855d --- /dev/null +++ b/.github/workflows/Interface.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 08d163f5..00000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -# Documentation: http://docs.travis-ci.com/user/languages/julia/ -language: julia -branches: - only: - - master -os: - - linux - - osx -julia: - - 1.3 - - 1 - - nightly -matrix: - allow_failures: - - julia: nightly - fast_finish: true -notifications: - email: false -after_success: - - if [[ $TRAVIS_JULIA_VERSION = 1 ]] && [[ $TRAVIS_OS_NAME = linux ]]; then - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'; - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'; - fi diff --git a/Project.toml b/Project.toml index 1c3db5cb..6446dd66 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/README.md b/README.md index 89ec3769..c87d772d 100644 --- a/README.md +++ b/README.md @@ -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}`, diff --git a/src/bijectors/planar_layer.jl b/src/bijectors/planar_layer.jl index 8332c08d..c8f7c460 100644 --- a/src/bijectors/planar_layer.jl +++ b/src/bijectors/planar_layer.jl @@ -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 @@ -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}) @@ -90,13 +90,13 @@ 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) ``` @@ -104,22 +104,30 @@ 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 diff --git a/test/runtests.jl b/test/runtests.jl index b317cc4f..2b098227 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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. @@ -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