Solver Interface

Constructing Solvers

GaussianMarkovRandomFields.construct_solverFunction
construct_solver(blueprint::AbstractSolverBlueprint, mean::AbstractVector, precision::LinearMaps.LinearMap)

Construct a solver for a GMRF using a blueprint.

Arguments

  • blueprint::AbstractSolverBlueprint: The solver blueprint specifying the solver type and configuration.
  • mean::AbstractVector: The mean vector of the GMRF.
  • precision::LinearMaps.LinearMap: The precision matrix (inverse covariance) of the GMRF.

Returns

A solver instance that can compute means, variances, samples, and other GMRF quantities.

Notes

This is the primary interface for constructing solvers. The solver stores references to the mean and precision, and provides methods like compute_mean, compute_variance, compute_rand!, etc.

For conditional GMRFs, use construct_conditional_solver instead.

source
GaussianMarkovRandomFields.construct_conditional_solverFunction
construct_conditional_solver(blueprint, prior_mean, posterior_precision, A, Q_ε, y, b)

Construct a solver for a conditional GMRF using a blueprint.

Arguments

  • blueprint::AbstractSolverBlueprint: The solver blueprint specifying the solver type and configuration.
  • prior_mean::AbstractVector: The mean vector of the prior GMRF.
  • posterior_precision::LinearMaps.LinearMap: The posterior precision matrix (Qprior + A' * Qε * A).
  • A::LinearMaps.LinearMap: The observation matrix.
  • Q_ε::LinearMaps.LinearMap: The precision matrix of the observation noise.
  • y::AbstractVector: The observation vector.
  • b::AbstractVector: The offset vector.

Returns

A conditional solver instance that can compute posterior means, variances, samples, etc.

Notes

This interface is used internally by LinearConditionalGMRF. The posterior precision is pre-computed as Q_prior + A' * Q_ε * A to avoid recomputation in the solver.

source
GaussianMarkovRandomFields.postprocess!Function
postprocess!(solver::AbstractSolver, gmrf::AbstractGMRF)

Postprocess a solver after GMRF construction is complete. This allows the solver to optimize itself using full GMRF context, such as setting up tailored preconditioners.

The default implementation is a no-op.

source

Solver Access

All GMRF types store their solver as a direct field:

# Access the solver instance
solver = gmrf.solver

# Use solver methods directly
mean_vec = compute_mean(solver)
variance_vec = compute_variance(solver)
sample_vec = compute_rand!(solver, rng, zeros(length(gmrf)))

Solver Construction Process

When constructing a GMRF, the solver is automatically created using:

  1. construct_solver(blueprint, mean, precision) - creates the solver instance
  2. postprocess!(solver, gmrf) - allows the solver to optimize itself using the full GMRF context

This two-step process ensures solvers can set up specialized preconditioners or other optimizations that require knowledge of the complete GMRF structure.