-
Notifications
You must be signed in to change notification settings - Fork 230
Using new Selector type instead of gid #720
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
Conversation
|
Regarding the broken tests, it seems like a deterministic bug simply because we fixed the random seed and use a small number of iterations (500) and small tolerance (0.1). Thus the bug is tied to that particular random seed we set, which makes the estimate slightly larger than the tolerance with 500 iterations. Either simply increasing the number of iterations (e.g. both to 2,000) can fix the tests. Question is why and where this PR change the random number generator process? With a skim on the changes it doesn't seem direct to me. Or does the use of UUID have any influence on it? |
It must be the UUID, if I change it to a timestamp, all the test cases pass. |
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.
Thanks, @KDr2. Excellent work! I've left some questions below. Here are some more for discussions:
- Do we really need a
DEFAULT_SELECTOR, since we can always generate aselectorfor new samplers on-the-fly? - There's only one place that uses
INVALID_SELECTOR, and it's for marking variables for deletion after a variable disappeared from the model during inference. As an alternative, can we treat thedeletionas a specific MCMC step, and introduce an implicit sampler that will perform variable elimination. This might be more general since it allows a user to override this implicit sampler with more elaborate operations, e.g. re-use variables after a variable re-appear after several MCMC steps. @xukai92 Again, this can be done in a separate PR. - This is less important, and can be done later: we should rename
VarInfo.gidsto something more readable, perhapssplSelector?
|
Ready to merge from my side. |
Currently, the
|
OK, if the PR is merged, I will file new PR for the renaming and |
We use |
yes, maybe add a field to |
I think that adding a
I add some new commits about this, please have a look. @yebai |
src/inference/dynamichmc.jl
Outdated
| model(vi, SampleFromUniform()) | ||
|
|
||
| if spl.selector == DEFAULT_SELECTOR | ||
| if spl.parent == SampleFromPrior() |
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.
@xukai92 I'm confused by why we need spl.selector == DEFAULT_SELECTOR here. I understand that this is helpful for HMC samplers to decide whether to perform link!/invlink!, is that the only reason? If so, can we refactor this to remove the requirement of a parent field for samplers? It feels odd to say a sampler is the parent of another sampler since logically they are the same -- i.e. a transition kernel.
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.
Perhaps we can introduce a field to Selector to indicate sampling algorithm types, e.g.
struct Selector
gid :: UInt64
alg :: Ref{Symbol} # :default, :invalid, :Gibbs, :HMC, etc.
end
Selector() = Selector(time_ns(), Ref(:default))
Selector(a::Symbol) = Selector(time_ns(), Ref(a))
==(s1::Selector, s2::Selector) = s1.gid == s2.gidThen we can
spl.selector == DEFAULT_SELECTOR==>spl.selector.alg[]==:default- Remove
INVALID_SELECTOR - and change
push!(vi, vn, r, dist, INVALID_SELECTOR)==>
push!(vi, vn, r, dist, Selector(:invalid))
Turing.jl/src/inference/pgibbs.jl
Line 173 in b7ceac2
push!(vi, vn, r, dist, INVALID_SELECTOR)
This allows the Gibbs constructor to modify Selector field of each component algorithms, and avoid creating an explicit dependence on samplers when initialising Selector.
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.
Good solution, I will have a try.
828dbfe to
d0d248a
Compare
|
Excellent work - thanks @KDr2! |
mohdibntarek
left a comment
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.
@KDr2 Sorry, I am late to the party! Thanks for the great PR. I left some comments. If you agree with me, please address them in another PR. Cheers!
I left some comments above. Other comments look reasonable to me and can be addressed by a new PR. |
#567