⚡ Fast, flexible and user-centered Julia package for Bayesian inference with sparse Gaussians
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, we support 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.
GaussianMarkovRandomFields.jl is not yet a registered Julia package. Until it is, you can install it from this GitHub repository. To do so:
-
Launch the Julia REPL and type
] add https://github.com/timweiland/GaussianMarkovRandomFields.jl
.
Let's 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(range = 0.3) # Construct GMRF with specified range
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 new helpers
using Distributions: Normal
obs_model = PointEvaluationObsModel(model.discretization, points, 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!
Make sure to check the documentation for further examples!
Check our contribution guidelines.