Skip to content

Repository files navigation

GaussianMarkovRandomFields.jl

Logo for the GaussianMarkovRandomFields.jl package.
⚡ Fast, flexible and user-centered Julia package for Bayesian inference with sparse Gaussians

Build Status Coverage Aqua code style: runic DOI

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.

Contents

Installation

GaussianMarkovRandomFields.jl is a registered Julia package. To install it, launch the Julia REPL and type ] add GaussianMarkovRandomFields.

Your first GMRF

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= 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!

Make sure to check the documentation for further examples!

Getting help

Questions, bug reports and feature requests all belong in the issue tracker. Please open an issue rather than emailing the maintainer, so that answers stay searchable for everyone.

See Getting Help for what to include, and Support and Governance for what to expect regarding response times and project scope.

Citing

If you use GaussianMarkovRandomFields.jl in your research, please cite it via its Zenodo archive. The DOI below always resolves to the latest release; the Zenodo page additionally lets you cite a specific version and offers BibTeX and other export formats.

Tim Weiland. GaussianMarkovRandomFields.jl. Zenodo. https://doi.org/10.5281/zenodo.18088214

@software{weiland_gmrf_jl,
  author    = {Weiland, Tim},
  title     = {{GaussianMarkovRandomFields.jl}},
  publisher = {Zenodo},
  year      = {2025},
  doi       = {10.5281/zenodo.18088214},
  url       = {https://doi.org/10.5281/zenodo.18088214}
}

GitHub's Cite this repository button exposes the same metadata, which lives in CITATION.cff.

Contributing

Check our contribution guidelines.

About

Bayesian inference on spatial and spatiotemporal data, faster than you can say "Cholesky!"

Topics

Resources

Contributing

Stars

19 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages