-
Notifications
You must be signed in to change notification settings - Fork 219
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
Interface Changeover #793
Interface Changeover #793
Conversation
Hey @cpfiffer, the following issues have been raised for a while. It seems they are mostly interface related features. Can you take a look at them in this PR if possible?
|
|
Seems that everything is done. Great PR! I will merge it in 24 hours if no rejection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great work @cpfiffer - this has clearly been a lot of work. I've left a number of nit-picky style related comments, and also some requests for additional inline documentation.
One thing in particular: the docstrings for sample_init!
, step!
, and sample_end!
could probably do with being improved a bit. sample_init!
and sample_end!
are a little bit terse, and step!
produces three separate docstrings, where one would suffice. Would also be helpful to document whether or not it's expected that the user will return the modified sampler or not.
src/core/RandomVariables.jl
Outdated
""" | ||
islinked(vi::VT, spl::Sampler) where VT<:VarInfo | ||
|
||
Returns `true` if a `VarInfo` is linked for a particular sampler `spl`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A slightly more informative docstring would be appreciated. What does linked
mean in this context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to say "in the transformed space" rather than "linked", is that helpful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's helpful, but maybe add a reference to some other documentation for Bijectors or something? I mean, it's clear what's happening here if you know anything about the relationship between Turing and Bijectors etc, but for a newbie it might still be a bit unclear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to read:
islinked(vi::VT, spl::Sampler) where VT<:VarInfo
Returns true
if a VarInfo
is in the transformed space for a particular sampler spl
.
Turing's Hamiltonian samplers use the link
and invlink
functions from
Bijectors.jl to map a constrained variable
(for example, one bounded to the space [0, 1]
) from its constrained space to the set of
real numbers. islinked
checks if the number is in the constrained space or the real space.
I meet a bug in the following example with thie branch using Turing
@model testmissing() = begin
n ~ Categorical(10)
l = tzeros(Int, n)
for i in 1:n
l[i] ~ Categorical(2)
end
3 ~ Normal(sum(l), 1)
end
chain = sample(testmissing(), PG(10), 1_000) gives
This example works in |
That's a very strange bug. Seems to only happen sometimes. I'm investigating. |
Another 24-hour merge notifcation. |
To do
Supported samplers (
src/inference/
)Contributed samplers (
src/contrib/inference
)[ ] SGLD[ ] SGHMC[ ] PIMH[ ] PMMH[ ] IPMCMCSummary
This will be the comprehensive PR containing all the code to change us over to using the new interface. Since the changes must be done for all the samplers pretty much all at once (we don't want half to use the new interface and the other half to use the old version), this will probably be a large PR. There is an
hmc-interface.jl
file which is not really ready for consumption yet, so you can ignore it.Currently, I have a (very) rough proof-of-concept for SMC to get myself on stable ground for the rest of the samplers. The following interface is supported:
I've introduced a couple of new things since the discussion in #746.
First, I'm attempting to unify all the samplers under the existing
Sampler
type we have. Theinfo
field is not going to be removed in this PR because of all theVarInfo
stuff -- that will be a separate undertaking. TheSampler
type now has an additional field calledstate
, which contains a mutable struct that replaces the sampler-specific information likelogevidence
oreval_num
. The ultimate goal is to have this go away at some point and move to a more general sampler state, but changing over to the front-end interface and changing the entire backend would be too much for one PR.Second, this isn't yet benchmarked for performance. One issue I have is how to package up the
TransitionType
s into something that has name & value information together, without too much overhead. At the moment, each step bundles up all the names fromvi
and all thevi.vals
, but I think there's probably a better design.More to come on this.