-
Notifications
You must be signed in to change notification settings - Fork 226
Implement quantile(model(), u)
?
#2525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @mvsoom - how would this work with multivariate distributions? |
Hi, that's a good point! Thanks for raising it! I thought about and it made me realize a few things... I'd be delighted to discuss these with you!
Short answer: if the multivariate distribution can be "uncorrelated" into independent variables, then the answer is of course to perform the inverse sampling transform on each of these variables separately and then tie them back up again with some correlating transform.
This So, for general multivariate distributions that can't be uncorrelated readily, the picture changes. The inverse sampling transform is not uniquely defined mathematically, and a variety of techniques like copulas are used. But this is irrelevant in my mind. Any sample from a So the name "quantile transform" is misleading, my bad. It is more about decorrelating and bringing everything back to a common parameter space [0,1]ᴺ, with unifying benefits such as independence, single unified dimension of inverse probability, unified inference for discrete and continuous params, and distribution-dependent step lengths (larger in regions of low prior mass, smaller in regions of higher prior mass). AD takes care of the derivatives Is it possible for me to take a Turing model and to somehow run inference in |
This is interesting. Sorry for the delay in response, I've been pondering it. It seems to me we would first need to introduce a QuantileBijector in Bijectors.jl, which obeys the following API (ish). d = Normal()
q = QuantileBijector(d)
# converts points in original space to [0, 1]
# specifically if q(x) = y, then we require that cdf(d, x) = y
q(0) = 0.5
# returns a distribution that behaves like Uniform(0, 1), i.e. rand(u) should be the same as rand()
u = transformed(d, q)
# returns the log jacobian of the transform
logabsdetjac(q, 0) This is probably not too difficult for univariate, using the cdf. Also getting the log-jacobian of the transform seems to be fairly trivial (it's just logpdf of the original value with the original dist). While I do see the fundamental point about how After that we might worry about how to use this in DynamicPPL so that you can evaluate and sample from a model in this hypercube space. I think this is doable but quite tricky and might require unravelling some assumptions that we have inside DynamicPPL. All in all, it feels like a nice thing to have but I'm not sure whether the core team will be able to implement it any time soon. Of course, if you wanted to take some of it on we would be happy to help. Thoughts / corrections are welcome @TuringLang/maintainers |
Oh, as it happens, there's already an existing PR for the univariate one 😄 TuringLang/Bijectors.jl#273 although what I called |
Sampling from priors works perfectly:
I wonder if it would be possible to implement
quantile
to sample from the prior using the quantile transform:Quantile transform simply maps a
u ~ Uniform
to the desired distribution, e.g.,Use cases:
The hypercube
[0,1]ᴺ
parametrizationu ↦ θ
is e.g. used in Nested Sampling.It is effective in inference because fixed length steps in
u
space result in prior-dependent step lengths in the originalθ
parameter space.And it can be used to unify inference with discrete and continuous variates. (e.g. jaxns)
If this could be implemented, hooking up NestedSamplers.jl would be relatively simple:
Since this is the way many random variates are generated computationally, maybe implementing this would relatively easy?
I could give it a try with some pointers, since I only recently picked up Julia again and don't know Turing.jl.
The text was updated successfully, but these errors were encountered: