Venturecxx
Venturecxx copied to clipboard
Stochastically constrained nodes can lead to wrong stationary distribution
This has to do with many of the test cases in test_constrain.py.
In particular, consider the program:
(assume x (mem (lambda (i) (normal 0 1))))
(assume xs (mapv x (arange 10)))
(observe (x (tag 'u 0 (uniform_discrete 0 10))) 5)
; repeat however many times:
(do (mh 'u 0 100) (mh default one 1) (sample xs))
Here, there are ten standard normal distributed nodes, one of which is constrained to equal 5. M-H steps on 'u
will have the effect of changing which node is constrained, but when it does so, it leaves the old value of the now-unconstrained node there, so that the number of nodes with value 5 monotonically increases. This has the result that after many steps, almost all of them will be 5, which is very uncharacteristic of the posterior distribution, even though we purport to be running a Markov chain of M-H steps that touches all of the random choices infinitely often.
One possible fix is to treat stochastically constrained nodes as potential resampling nodes, so that if they get unconstrained they will be resimulated from the prior rather than left at their previously-constrained value. But I'm not sure if this is the right thing to do in all cases especially if there are other things downstream of the constrained node (i.e. all the propagateConstraints stuff in regen).
Right. In this case, the mh proposal to the 'u 0 node is not reversible, and hence computes the wrong acceptance ratio. Treating stochastically constrained nodes as potential resampling nodes would restore its reversibility.