add helper functions for marginalising discrete random variables
- Dominant language
- C++
- Stars
- 607
- Forks
- 67
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 1
Description
greta can't currently sample discrete random variables, because HMC is the only implemented sampler (though see #104)
You can use HMC to sample (some) models with latent discrete random variables, by explicitly marginalising out the random variable. This is possible in the dev version of greta, using the new `mixture()` distribution.
It would be great to provide utility functions to help people do that marginalisation though. The computation for these models isn't too difficult, but finding a nice user interface could be a bit tricky.
This gist: https://gist.github.com/goldingn/4192ddff71037ca3f18927b8d273cd2a has a prototype implementation for a latent Poisson random variable in a simple model.
That interface requires the user to pass a function for the model likelihood *conditional* on the scalar Poisson variable `N`, a greta array `lambda` for the rate parameter, and the maximum value of `N` up to which to integrate the likelihood.
The syntax looks like this:
```r
likelihood <- function (N) bernoulli(0.9 ^ N)
distribution(y) <- marginal_poisson(likelihood,
lambda,
max_n = 10)
```
The gist shows how to get the posterior over the weights for different values of N, and how to sample values of N *post-hoc*.
A more general interface would be nice, i.e. just `marginalise()`, but with a discrete greta distribution over which to marginalise, e.g.:
```r
distribution(y) <- marginalise(likelihood,
poisson(lambda),
values = 1:10)
```
Contributor guide
Assessment
This issue has not been assessed yet.