Skip to content

Conversation

@KDr2
Copy link
Member

@KDr2 KDr2 commented Mar 18, 2019

@yebai yebai requested review from xukai92 and yebai March 18, 2019 21:23
@xukai92
Copy link
Member

xukai92 commented Mar 18, 2019

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?

@KDr2
Copy link
Member Author

KDr2 commented Mar 19, 2019

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.

@KDr2 KDr2 requested a review from yebai March 19, 2019 04:20
@KDr2 KDr2 changed the title [WIP] Using new Selector type instead of gid Using new Selector type instead of gid Mar 19, 2019
Copy link
Member

@yebai yebai left a 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 a selector for 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 the deletion as 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.gids to something more readable, perhaps splSelector?

@yebai yebai requested a review from mohdibntarek March 19, 2019 12:24
@yebai
Copy link
Member

yebai commented Mar 19, 2019

Ready to merge from my side.

@KDr2
Copy link
Member Author

KDr2 commented Mar 19, 2019

  • Do we really need a DEFAULT_SELECTOR, since we can always generate a selector for new samplers on-the-fly?

Currently, the DEFAULT_SELECTOR is used for

  1. SampleFromPrior and SampleFromUniform, in this case, we push var into VI with the default selector because these samplers has no selector. This can be easily fixed.
  2. In components of Gibbs, their many spl.selector == DEFAULT_SELECTOR and spl.selector != DEFAULT_SELECTOR, I will look into this.

@KDr2
Copy link
Member Author

KDr2 commented Mar 19, 2019

Ready to merge from my side.

OK, if the PR is merged, I will file new PR for the renaming and DEFAULT_SELECTOR deletion if I can fix them :)

@KDr2
Copy link
Member Author

KDr2 commented Mar 19, 2019

2. In components of Gibbs, their many spl.selector == DEFAULT_SELECTOR and spl.selector != DEFAULT_SELECTOR, I will look into this.

We use spl.selector ==/!= DEFAULT_SELECTOR to test if a Sampler is a top-level one or a component of another sampler, so if we remove DEFAULT_SELECTOR, we should add a new field to indicate this relation, e.g., a parent field for each sampler. Is it right?

@yebai
Copy link
Member

yebai commented Mar 19, 2019

We use spl.selector ==/!= DEFAULT_SELECTOR to test if a Sampler is a top-level one or a component of another sampler, so if we remove DEFAULT_SELECTOR, we should add a new field to indicate this relation, e.g., a parent sampler for each sampler. Is it right?

yes, maybe add a field to Selector instead of Sampler for this purpose? Given that each sampler only has one unique selector field, this might be the most straightforward approach.

@KDr2
Copy link
Member Author

KDr2 commented Mar 20, 2019

yes, maybe add a field to Selector instead of Sampler for this purpose? Given that each sampler only has one unique selector field, this might be the most straightforward approach.

I think that adding a parent field to the Sampler type may be better:

  1. The hierarchy is of the samplers, not the selectors. parent in Sampler type shows this hierarchy more straightforwardly.
  2. We can use the singleton SampleFromPrior() as the parent of the top-level samplers.
  3. A selector can be reused in different Samplers or be used standalone without any sampler, and selectors have no hierarchies, adding a hierarchy field in it brings much confusion.
  4. For now, the argument new_selector in the Sampler constructor is also very confusing. When we use new_selector=true to create a Sampler, we indeed mean to create a Sampler with a parent. So this argument should be changed to parent.

I add some new commits about this, please have a look. @yebai

@KDr2 KDr2 requested a review from yebai March 20, 2019 08:29
model(vi, SampleFromUniform())

if spl.selector == DEFAULT_SELECTOR
if spl.parent == SampleFromPrior()
Copy link
Member

@yebai yebai Mar 20, 2019

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.

Copy link
Member

@yebai yebai Mar 20, 2019

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.gid

Then 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))
    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.

Copy link
Member Author

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.

@yebai yebai mentioned this pull request Mar 20, 2019
7 tasks
@KDr2 KDr2 force-pushed the issue-567 branch 2 times, most recently from 828dbfe to d0d248a Compare March 21, 2019 07:31
@yebai
Copy link
Member

yebai commented Mar 21, 2019

Excellent work - thanks @KDr2!

Copy link
Contributor

@mohdibntarek mohdibntarek left a 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!

@yebai
Copy link
Member

yebai commented Mar 21, 2019

@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.

@yebai yebai deleted the issue-567 branch June 8, 2019 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants