Comments (5)
I guess the problem is that the the samples in vi
are saved as Real
, and hence rerunning leads to the error since the evaluation of the logpdf in Bijectors calls eps
for Real
which is not defined. It seems reasonable that it doesn't affect the likelihood context since we don't evaluate the logpdf there. I guess this issue should be transferred to Bijectors, maybe it's possible to avoid eps
or define some _eps
instead that falls back to eps(Float64)
for Real
.
from bijectors.jl.
Hm, the funny thing is that eps
is only used with Dirichlet
: https://github.com/TuringLang/Bijectors.jl/blob/master/src/Bijectors.jl#L124.
I guess this is the reason:
julia> logpdf(Dirichlet(2, 1.0), [1, 0])
NaN
julia> logpdf(Dirichlet(2, 1.0), [1 + eps(Float64), eps(Float64)])
0.0
Probably either of the following should be fine:
julia> logpdf(Dirichlet(2, 1.0), nextfloat.(Real[1.0, 0.0]))
0.0
julia> logpdf(Dirichlet(2, 1.0), Real[1.0, 0.0] .+ eps.(Real[1.0, 0.0]))
0.0
(and eps
is defined internally through nextfloat
, so I'd prefer the first).
from bijectors.jl.
_eps
should be used here. I will make a PR.
from bijectors.jl.
Line 124 in 1f3b581
is actually not defined for
x >= 1 - eps
mathematically even though it works with Distributions (and incorrect for any x > 0
). Maybe one should apply the same fix as in the SimplexBijector and rescale x
to x * (1 - 2 * eps) + eps
, which leads to values in [eps, 1-eps]
if x in [0, 1]
before and would be consistent with the calculation in SimplexBijector. Of course, that still doesn't work if x < 0
or x > 1
due to numerical issues, so probably the only numerically stable way would be to work with the logarithm of the unnormalized Gamma random variates instead and apply the softmax function later on if needed (e.g., for parameterizing a categorical distribution).from bijectors.jl.
More generally speaking, I'm wondering if for sampling and optimization in the unconstrained space we could use a rand_trans
function that generates samples in the transformed space directly to avoid these issues altogether. E.g., there exist algorithms for sampling X
with exp(X) \sim Gamma(a, 1)
directly in log-space, which avoids the issue of getting zero values for small shape parameters a
. It could always fall back to sampling in the original space and applying the transformation afterwards, but a more sophisticated implementation could avoid numerical issues whenever possible.
from bijectors.jl.
Related Issues (20)
- 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
- support ProductDistribution HOT 3
- Fixes to correlation bijectors
- Improve `with_logabsdet_jacobian` performance for `SimplexBijector` HOT 1
- Tests are failing for `VecCorrBijector` in _very_ rare scenarios
- Add Tapir to Bijectors tests.
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.