probcomp / GenExperimental.jl

Featherweight embedded probabilistic programming language and compositional inference programming library
MIT License
17 stars 2 forks source link

DPMM and SMC inference with linear scaling #20

Open marcoct opened 7 years ago

marcoct commented 7 years ago

First, do the version that scales O(n) per generation where n is the number of data points (resulting in an O(n^2) Gibbs sweep).

marcoct commented 7 years ago

Started on the O(N^2) version in https://github.com/probcomp/gen-examples/commit/da36f4b92e0df7bba15b54630ca40ea4e329c5ab

marcoct commented 7 years ago

notes from meeting today with vikash:

marcoct commented 7 years ago

Here is an implementation of a DPMM with a Gibbs sweep inference algorithm that scales in O(N) per sweep. It makes use of sufficient statistics for CRP and cluster components that are stored in the trace.

https://github.com/probcomp/gen-examples/blob/c851ba157ae01c9b7e40b8dc69fb7700260aa01a/dirichlet-process-mixture-model/dpmm.jl

It runs, but has not been tested for correctness or inference quality, etc.

An alternative approach, that may be implemented as an example of module networks, would instead define a single multivariate exchangeable module that generates a vector of N data points, with a sub-trace that contains the vector of data and the sufficient statistics. Then, the incorporate! and unincorporate! could possibly be hidden from the inference programmer, who would interact with the module using a version of the standard trace interface.

marcoct commented 7 years ago

Wrote a notebook with DPMM with Gibbs sampling O(N) per sweep and a custom D3 trace rendering including a transition animation.

Next step is to write the SMC inference program.

This effort brought to light a few ideas for how to formalize this inference programming model:

marcoct commented 7 years ago

A CRP joint generator with a custom trace type that exposes the cluster assignments as addressable values, and internally maintains sufficient statistics, was added here: https://github.com/probcomp/Gen.jl/blob/b51105619075571f757a4af7350e8bd977d36bbc/src/primitives/crp_joint_generator.jl

The joint generator may or may not be used for this DPMM example. The joint generator is more desirable than explicit draw and incorporate! sequence in the probabilistic program because the sufficient statistics are naturally and automatically associated with the CRP generator. In the sequential version, the sufficient statistics are manually recorded with a separate tag directive, and the inference programmer needs to make this association themselves.

marcoct commented 6 years ago

Added generic serial basic SMC and conditional SMC algorithms for state-space models without rejuvenation to Gen in branch https://github.com/probcomp/Gen.jl/blob/20170804-marcoct-generators/src/inference/state_space_smc.jl

Tested these with particle marginal MH and particle Gibbs on a toy model from the particle MCMC paper in https://github.com/probcomp/gen-examples/tree/20170810-marcoct-generators/particle-mcmc