Implements relaxed inference for compartmental models #2513
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.
Addresses #2426
Replaces #2510
This implements an asymptotically exact relaxed inference strategy for
CompartmentalModel
whereby:differentiably_quantize()
function that quantizes but keeps gradients. This avoids the cost of enumeration which is exponential in number of compartments, and also avoids coupling through time so that sparse observations are cheaper (do not require an additional auxiliary variable).This method differs from bouncy ball MCMC (Nimshimura, Dunson, Lu 2017) in that we still use an L2 Gaussian kinetic energy rather than an L1 Laplace kinetic energy, thus permitting reuse of existing implementations of HMC and NUTS. And despite the gradients in (2) being approximate, this method is still asymptotically correct because the exact density is used (and hence the MH correction compensates for bad gradients). Indeed for Binomial potentials the gradients are quite accurate (see notebook):
Mixing Issues
In practice this mixes poorly. I believe the cause is inability to propagate gradients to avoid feasibility boundaries. Experiments show that early in learning trajectories become infeasible, and HMC step size is reduced to very small.
Tested