Hi all! Last week I published Latte.jl, a probabilistic programming framework for latent Gaussian models.
What’s a latent Gaussian model?
Many interesting problems in Bayesian inference can be approached via latent Gaussian models. These are hierarchical models with a certain structure: You have some hyperparameters \theta, a latent field x that depends on \theta, and data y that depends on both. Formally, p(y, x, \theta) = p(\theta) p(x \mid \theta) p(y \mid x, \theta). We further assume that p(x \mid \theta) is either Gaussian directly or is amenable to a Laplace approximation through repeated linearisation. Examples of where such models are relevant include spatial disease maps, time series, hierarchical GLMMs, species distribution modelling, Gaussian processes more broadly, etc…
Why Latte?
Latent Gaussian models are highly structured and MCMC often takes a long time to converge on them. Hence, people have developed specialised inference algorithms for these models that leverage this structure. Probably the most famous one is Integrated Nested Laplace Approximation (INLA), which uses Laplace approximations on the latent field + quadrature on the hyperparameters to get accurate posteriors deterministically and at low runtime. Then there’s TMB, which has a much more flexible (template-based) modelling language, and uses the delta method to get uncertainties. Another method combines Laplace over the latent with HMC over the hyperparameters.
These methods share a lot of machinery, yet at the moment they live in fractured packages (mostly in R), fractured communities, and even fractured lingo.
My goal with Latte is to provide a unified PPL framework (based on DynamicPPL.jl <3) that gives you simplicity and flexibility in your modelling, and makes it easy for you to switch between these different inference methods.
Currently, Latte offers INLA (with many of its tricks), the TMB-style delta method, and HMC-Laplace. You can also convert a Latte model to a DPPL model to hand off to Turing.jl.
Usage example
using Latte, Distributions, LinearAlgebra
@latte function hier_poisson(y, x, group, n_groups)
τ_u ~ Gamma(2.0, 1.0)
β ~ MvNormal(zeros(2), 100.0 * I(2))
u ~ IIDModel(n_groups, constraint = :sumtozero)(τ = τ_u)
for i in eachindex(y)
y[i] ~ Poisson(exp(β[1] + β[2] * x[i] + u[group[i]]))
end
end
lgm = hier_poisson(y, x, group, n_groups)
r_inla = inla(lgm, y) # grid integration over θ (default)
r_tmb = tmb(lgm, y) # MAP + Laplace (delta-method) covariance
r_hmc = hmc_laplace(lgm, y) # NUTS on the Laplace marginal L(θ)
The website has a bunch of tutorials covering a variety of topics, as well as benchmarks comparing to R-INLA.
Outlook
Latte.jl is in v0.1.0. This doesn’t mean it’s unusable, quite the opposite; I’ve had success in throwing it at a bunch of different problems. But of course that doesn’t guarantee that it’ll always work the way it should. So if things break or are suspiciously slow for your use case, or if you have any other kind of feedback, I’d greatly appreciate it.
If you happen to be at ICML next week, I’ll showcase Latte there on Monday in the Probabilistic Numerics tutorial to identify an oil leak in a harbor. I’ll also give a talk at JuliaCon in August that uses Latte for spatial modelling.
