Comments (4)
I'm currently not able to try this out, but the following should do the trick:
using StatsFuns
struct Softplus <: Bijector{0} end
# Forward
(::Softplus)(x::Real) = softplus(x)
(::Softplus)(x::AbstractArray{<:Real}) = softplus.(x)
# Backward
(::Inversed{<:Softplus})(y::Real) = invsoftplus(y)
(::Inversed{<:Softplus})(y::AbstractArray{<:Real}) = invsoftplus.(y)
# logabsdetjac (forward)
logabsdetjac(b::Softplus, x::Real) = x - log(1 + exp(x)) # I THINK this is right, haven't written it down
I'll make a PR and such when I'm back at the desk 👍
Sidenote: I think I realized a way we can avoid this code-duplication for making things work when we look at "batches" (i.e. define the (::Bijector{0})(x::AbstractArray{<:Real})
once and have all <:Bijector{0}
inherit this 🎉
from bijectors.jl.
logabsdetjac(b::Softplus, x::Real) = x - log(1 + exp(x)) # I THINK this is right, haven't written it down
Assuming it's correct (haven't thought about it), one should probably implement it as
logabsdetjac(::Softplus, x::Real) = -log1pexp(-x)
from bijectors.jl.
This is provided now by LogExpFunctions's ChangesOfVariables extension:
https://github.com/JuliaStats/LogExpFunctions.jl/blob/a1c4fda2b9cc4c59c184648c0cfc7f694c415bf3/ext/LogExpFunctionsChangesOfVariablesExt.jl#L7-L10
from bijectors.jl.
Sidenote: I think I realized a way we can avoid this code-duplication for making things work when we look at "batches" (i.e. define the (::Bijector{0})(x::AbstractArray{<:Real}) once and have all <:Bijector{0} inherit this tada
An alternative (as done, e.g., by Distributions.logpdf
) would be to demand from all users to specify broadcasting explicitly. I.e., users should just call Softplus().(x)
where x
is a vector.
from bijectors.jl.
Related Issues (20)
- Remove heavy usage of `@generated` HOT 2
- Add `rng` to have the reproducibility in `PlanarLayer` and `RadialLayer`
- `logpdf` of `UnivariateTransformed` produces `StackOverflowError` HOT 7
- Zygote is broken for `Stacked` bijectors HOT 5
- filldist, up1 not defined HOT 6
- Adding bijectors for OrderStatistic and JointOrderStatistics HOT 1
- Add API function to retrieve size of bijector output from bijector input HOT 1
- rational quadratic flows not supporting Float32 input HOT 1
- What to do with `CorrBijector` ? HOT 1
- Improve `PDVecBijector`
- Matrix factorization bijectors HOT 4
- Domain Error for VecCholeskyBijector bijector when calling logabsdetjac HOT 4
- Question on simplex bijector implementation HOT 9
- Can't apply Bijectors.ordered to TDist() and MvTDist() HOT 1
- Incorrect bijector for heterogeneous Product distribution HOT 3
- Radial flow to a simplex HOT 5
- Stackoverflow in custom bijector HOT 2
- Missing implementation of `Bijectors.bijector` for `arraydist` distributions. HOT 1
- Bijectors.ordered and MvLogNormal interaction .. only supported for unconstrained distributions. HOT 1
- `TruncatedBijectors` not defined in `Distributions` extension
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bijectors.jl.