probmods / webchurch

A Church to Javascript compiler (DEPRECATED)
Other
140 stars 15 forks source link

MH implementation not ergodic on certain models #72

Open nalourie opened 9 years ago

nalourie commented 9 years ago

Because the implementation of MH updates the random variables one at a time, the resulting chain is not ergodic for certain models and thus doesn't actually sample from the posterior distribution. Example:

(mh-query 100 100
  (define bools (list (flip) (flip)))
  bools
  (not (equal? bools (list true false))
         (equal? bools (list false true))) ;; -> will return samples only from either '(#t #t) or '(#f #f)

I ran this code on the probabilistic models of cognition book's website.

My quick suggestion for a fix: do a full state transition (every dimension) regularly in the beginning, then once you have an estimate for how many "components" the markov chain has, you can decide how often you want to do a full state transition after that.

longouyang commented 9 years ago

A full state transition requires some annoying book-keeping (e.g., what if some random variables disappear or have new types / supports?)

A simpler solution: change the proposal distribution to sample directly from the prior with some small probability. Thoughts, @ngoodman?

nalourie commented 9 years ago

You could also try periodically allowing it to transition to a state that doesn't satisfy the condition, and not storing it in the sample when you do.

(Edit: accidentally closed the issue, sorry about that.)