2025
GaussianMarkovRandomFields.jl
Fast, flexible and user-centered Julia package for Bayesian inference with sparse Gaussians
About
Gaussian Markov Random Fields (GMRFs) are Gaussian distributions with sparse precision (inverse covariance) matrices. GaussianMarkovRandomFields.jl provides utilities for working with GMRFs in Julia. The goal is to enable flexible and efficient Bayesian inference from GMRFs, powered by sparse linear algebra.
In particular, the package supports the creation of GMRFs through finite element method discretizations of stochastic partial differential equations (SPDEs). This unlocks efficient GMRF-based approximations to commonly used Gaussian process priors. Furthermore, the expressive power of SPDEs allows for flexible, problem-tailored priors.
Installation
GaussianMarkovRandomFields.jl is a registered Julia package. To install it, launch the Julia REPL and type:
] add GaussianMarkovRandomFields
Your first GMRF
Construct a GMRF approximation to a Matérn process from observation points:
using GaussianMarkovRandomFields
# Define observation points
points = [0.1 0.0; -0.3 0.55; 0.2 0.8; -0.1 -0.2] # N×2 matrix
# Create Matérn latent model (automatically generates mesh and discretization)
model = MaternModel(points; smoothness = 1)
x = model(τ = 1.0, range = 0.3) # Construct GMRF with specified parameters
x is a Gaussian distribution, and we can compute all the things Gaussians are known for.
# Get interesting quantities
μ = mean(x)
σ_marginal = std(x)
samp = rand(x) # Sample
Q = precision_map(x) # Sparse precision matrix
# Form posterior under point observations
using Distributions: Normal
obs_model = PointEvaluationObsModel(model, Normal)
y = [0.83, 0.12, 0.45, -0.21]
obs_likelihood = obs_model(y; σ = 0.1)
x_cond = gaussian_approximation(x, obs_likelihood) # Posterior GMRF!
Check the documentation for further examples.
Citing
If you use the package in your research, please cite it via its Zenodo archive.
TOPICS
julia · bayesian inference · gaussian processes · spatial statistics · finite element method · open source