| Title: | FEM Matern Gaussian Random Fields for Adlaplace |
|---|---|
| Description: | Tensor-product B-spline finite-element ingredients for Matern Gaussian random fields (mass, stiffness, and higher-order Grams) for use with the adlaplace Laplace approximation framework. Provides design and Gram matrix construction on regular grids, with optional terra SpatRaster / SpatVector input, and AD tape builders for random_fem_ssq_* / random_fem_det_*. |
| Authors: | Patrick Brown [aut, cre, cph] |
| Maintainer: | Patrick Brown <[email protected]> |
| License: | MPL-2.0 |
| Version: | 0.5.2 |
| Built: | 2026-07-17 23:38:41 UTC |
| Source: | https://github.com/eborgnine/adlaplace |
Builds the permutation and unit-lower pattern required by
adlaplace's chol_update for a precision with the same sparsity as
Q_structure (typically the union of FEM Gram patterns).
fem_chol_pattern(Q_structure)fem_chol_pattern(Q_structure)
Q_structure |
Symmetric sparse matrix with the structural nonzeros of
|
A list with perm (0-based), L1 (dtCMatrix / unit lower), and
perm_inv (0-based), suitable for the chol slot of a random_fem_*
precision payload.
Assemble FEM Matern precision Q2 or Q3 from Grams
fem_precision(kappa, tau, C, G, G2, G3 = NULL, alpha = 2L)fem_precision(kappa, tau, C, G, G2, G3 = NULL, alpha = 2L)
kappa, tau
|
Positive SPDE parameters. |
C, G, G2, G3
|
Sparse Grams from |
alpha |
|
Sparse dgCMatrix precision.
random_fem_ssq_* / random_fem_det_* precision payload for adlaplaceBuild random_fem_ssq_* / random_fem_det_* precision payload for adlaplace
fem_precision_payload(fem, alpha = 2L)fem_precision_payload(fem, alpha = 2L)
fem |
Result of |
alpha |
|
List for ad_data@precision: Grams, chol pattern, and Q CSC
coefficients aligned for on-tape assembly.
Structural nonzero pattern for Q2 or Q3 from Grams
fem_Q_structure(C, G, G2, G3 = NULL)fem_Q_structure(C, G, G2, G3 = NULL)
C, G, G2, G3
|
Sparse Grams from |
Symmetric sparse matrix with the union of Gram nonzero patterns.
Builds the design matrix of tensor-product B-splines at evaluation coordinates together with sparse mass, stiffness, and higher-order Gram matrices used in the SPDE FEM precision for operator orders alpha = 2 and 3.
grf_bspline(coords, knots, degree = 2L, ...) ## S4 method for signature 'list' grf_bspline(coords, knots, degree = 2L, ...) ## S4 method for signature 'data.frame' grf_bspline(coords, knots, degree = 2L, ...)grf_bspline(coords, knots, degree = 2L, ...) ## S4 method for signature 'list' grf_bspline(coords, knots, degree = 2L, ...) ## S4 method for signature 'data.frame' grf_bspline(coords, knots, degree = 2L, ...)
coords |
Evaluation locations. For a |
knots |
Knot-line positions on each axis: |
degree |
B-spline degree; must be |
... |
Passed to methods (unused for |
Coefficient ordering is column-major (vec) over the n_x by n_y array of
tensor basis indices: basis (i, j) maps to column i + (j - 1) * n_x.
A list with:
dgCMatrix design, n by n_x * n_y
sparse Grams
sparse Gram or NULL if degree < 3
metadata (n_basis = c(n_x, n_y))
sites_list <- list(x = seq(0, 1, by = 0.25), y = seq(0, 1, by = 0.25)) sites_eval <- do.call(expand.grid, sites_list) fem <- grf_bspline(sites_eval, sites_list, degree = 2L)sites_list <- list(x = seq(0, 1, by = 0.25), y = seq(0, 1, by = 0.25)) sites_eval <- do.call(expand.grid, sites_list) fem <- grf_bspline(sites_eval, sites_list, degree = 2L)
Evaluates the fitted Matern GRF on eval_grid under the Laplace
approximation for the random effects (outer parameters fixed at the MLE).
Returns a SpatRaster with layers mean, sd, and optionally sim1 ... simn.
matern_est(fit, eval_grid, n = 0L)matern_est(fit, eval_grid, n = 0L)
fit |
An |
eval_grid |
A terra |
n |
Number of posterior simulations of the field. Default |
A SpatRaster with n + 2 layers: mean, sd, and sim1...simn
when n > 0.
Formula term for a 2D Matern GRF via tensor-product B-spline FEM, wired to
adlaplaceGrf kernels random_fem_ssq_2 / random_fem_det_2 (shape nu = 1)
or random_fem_ssq_3 / random_fem_det_3 (nu = 2). The quadratic form is a
random shard; the log-determinant is a parameters companion via
adlaplace::extra_ad_fun().
The first argument is a column name in data (like adlaplace::iid()):
that column holds observation locations as a 2-column matrix, WKT text, or
HEX WKB points. Knot lines are supplied at construction; the observation
design matrix is built later in adlaplace::design() from data.
matern( x, knots, shape = 1L, init = c(1, 1), lower = c(1e-09, 1e-09), upper = c(Inf, Inf), parscale = c(1, 1) ) ## S4 method for signature 'matern' extra_ad_fun(term) ## S4 method for signature 'matern' design(term, data) ## S4 method for signature 'matern' precision(term, data) ## S4 method for signature 'matern' random_info(term, data) ## S4 method for signature 'matern' theta_info(term) ## S4 method for signature 'matern' beta_info(term, data)matern( x, knots, shape = 1L, init = c(1, 1), lower = c(1e-09, 1e-09), upper = c(Inf, Inf), parscale = c(1, 1) ) ## S4 method for signature 'matern' extra_ad_fun(term) ## S4 method for signature 'matern' design(term, data) ## S4 method for signature 'matern' precision(term, data) ## S4 method for signature 'matern' random_info(term, data) ## S4 method for signature 'matern' theta_info(term) ## S4 method for signature 'matern' beta_info(term, data)
x |
Name of the geometry / coordinate column in |
knots |
Knot lines as |
shape |
Matern smoothness nu ( |
init |
Initial values for |
lower, upper
|
Bounds for |
parscale |
Optimization scales for |
term |
A |
data |
Model data frame (passed by adlaplace generics). |
In 2D, B-spline degree and SPDE order alpha equal shape + 1.
A matern term object.
extra_ad_fun(matern): Companion parameters density for the FEM
log-determinant shard.
design(matern): Design matrix of B-spline basis evaluations at
coordinates in data[[term@term]].
precision(matern): FEM precision payload for random_fem_*.
random_info(matern): Random-effect metadata (one row per basis weight).
theta_info(matern): Theta info for practical range = sqrt(8*nu)/kappa
and field sd (log scale when transform_theta is TRUE).
beta_info(matern): Beta info (none).