Table of Contents
Fetching ...

PyINLA: Fast Bayesian Inference for Latent Gaussian Models in Python

Esmail Abdul Fattah, Elias Krainski, Havard Rue

Abstract

Bayesian inference often relies on Markov chain Monte Carlo (MCMC) methods, particularly required for non-Gaussian data families. When dealing with complex hierarchical models, the MCMC approach can be computationally demanding in workflows that require repeated model fitting or when working with models of large dimensions with limited hardware resources. The Integrated Nested Laplace Approximations (INLA) is a deterministic alternative for models with non-Gaussian data that belong to the class of latent Gaussian models (LGMs), yielding accurate approximations to posterior marginals in many applied settings. The INLA method was implemented in C as a standalone program, inla, that is widely used in R through the INLA package. This paper introduces PyINLA, a dedicated Python package that provides a Pythonic interface directly to the inla program. Therefore, PyINLA enables specifying LGMs, running INLA-based inference, and accessing posterior summaries directly from Python while leveraging the established INLA implementation. We describe the package design and illustrate its use on representative models, including generalized linear mixed models, time series forecasting, disease mapping, and geostatistical prediction, demonstrating how deterministic Bayesian inference can be performed in Python using INLA in a way that integrates naturally with common scientific computing workflows.

PyINLA: Fast Bayesian Inference for Latent Gaussian Models in Python

Abstract

Bayesian inference often relies on Markov chain Monte Carlo (MCMC) methods, particularly required for non-Gaussian data families. When dealing with complex hierarchical models, the MCMC approach can be computationally demanding in workflows that require repeated model fitting or when working with models of large dimensions with limited hardware resources. The Integrated Nested Laplace Approximations (INLA) is a deterministic alternative for models with non-Gaussian data that belong to the class of latent Gaussian models (LGMs), yielding accurate approximations to posterior marginals in many applied settings. The INLA method was implemented in C as a standalone program, inla, that is widely used in R through the INLA package. This paper introduces PyINLA, a dedicated Python package that provides a Pythonic interface directly to the inla program. Therefore, PyINLA enables specifying LGMs, running INLA-based inference, and accessing posterior summaries directly from Python while leveraging the established INLA implementation. We describe the package design and illustrate its use on representative models, including generalized linear mixed models, time series forecasting, disease mapping, and geostatistical prediction, demonstrating how deterministic Bayesian inference can be performed in Python using INLA in a way that integrates naturally with common scientific computing workflows.

Paper Structure

This paper contains 68 sections, 23 equations, 10 figures, 7 tables.

Figures (10)

  • Figure 1: Hierarchical structure of a latent Gaussian model. Hyperparameters split into latent hyperparameters $\boldsymbol{\theta}_1$, which govern the precision structure of the latent field $\boldsymbol{x}$, and likelihood hyperparameters $\boldsymbol{\theta}_2$ (e.g., observation noise variance), with $\boldsymbol{\theta} = (\boldsymbol{\theta}_1, \boldsymbol{\theta}_2)$. The linear predictor $\boldsymbol{\eta}$ links $\boldsymbol{x}$ to observations $\boldsymbol{y}$ through the likelihood $p(\cdot)$.
  • Figure 2: Posterior marginal density for the slope parameter. The dashed red line indicates the true value (1.5) used in data generation.
  • Figure 3: Validation of PyINLA against MCMC. Left: INLA marginal density (red curve) overlaid on MCMC histogram (grey) for the home-advantage parameter. Center/Right: Attack effects for Manchester City and Liverpool. The close agreement confirms that the INLA approximation is accurate for this model class.
  • Figure 4: Season simulation results. (a) Top-4 qualification probability: PyINLA vs MCMC ($r = 0.9999$). (b) Expected final points ($r = 0.9998$). (c) Predicted vs actual final points for both methods. Both approaches correctly identify Liverpool and Manchester City as title contenders and Huddersfield, Fulham, and Cardiff as relegation candidates.
  • Figure 5: Forecast comparison for Peyton Manning Wikipedia page views. Left: PyINLA forecast (red) with 95% credible interval (shaded). Right: NeuralProphet forecast (purple). Black line shows actual test data.
  • ...and 5 more figures