Add enumerative inference to the inference library #545
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.
This PR introduces the
enumerative_inference
function, which can be used to perform:The motivations for this PR are:
importance_sampling
with lots of samples, even though there's no guarantee that gives you a good approximation of the posterior.To use
enumerative_inference
, users provide an iterator over choice maps and their associated log-volumes, i.e. the log of the volume of sample space that each choice map is associated with (the volume is 1 if all choices are discrete).enumerative_inference
then returns a trace and normalized log. probability for each(choices, log_vol)
pair in the iterator, along with an estimate of the log marginal likelihood, essentially performing Riemann integration over the space of traces.A grid of
(choices, log_vol)
pairs can be constructed usingchoice_vol_iter
, by specifying addresses and a grid of values / intervals to enumerate over for each address.Documentation has been added (see https://www.gen.dev/docs/previews/PR545/ref/inference/enumerative/), but I still might want to add a simple tutorial showing how enumerative inference can be used to debug a model in cases where importance sampling with the default proposal might be a give a poor approximation to the posterior (e.g. in cases where the observations are highly unlikely under the prior).