Effect handler that conditions a model on sample sites having the same value #3395
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Description
It would be helpful to have an effect handler that can condition a model on sample sites having the same value.
Suggested Solution
Use the
EqualizeMessenger
effect handler with a newly added optionkeep_dist
, that when set toTrue
keeps the original distribution functions of the sample sites, as opposed to the default behavior of converting the second and subsequent sites to be deterministic.Usage Example
Consider the model
The model can be conditioned on ‘x’ and ‘y’ having the same value by
which is equivalent to
as opposed to the default behavior of
EqualizeMessenger
withkeep_dist
equal to False such thatwhich is equivalent to
Note that the conditioned model defined above calculates the correct unnormalized log-probablity density, but in order to correctly sample from it one must use SVI or MCMC techniques.
Testing
I've added a test for the conditioned model case, with two normally distributed random variables, which allows for analytic calculation of the expected resulting normal distribution.