| Title: | Spatial Logistic Gaussian Process for Field Density Estimation |
|---|---|
| Description: | Provides tools for conditional and spatially dependent density estimation using Spatial Logistic Gaussian Processes (SLGPs). The approach represents probability densities through finite-rank Gaussian process priors transformed via a spatial logistic density transformation, enabling flexible non-parametric modeling of heterogeneous data. Functionality includes density prediction, quantile and moment estimation, sampling methods, and preprocessing routines for basis functions. Applications arise in spatial statistics, machine learning, and uncertainty quantification. The methodology builds on the framework of Leonard (1978) <doi:10.1111/j.2517-6161.1978.tb01655.x>, Lenk (1988) <doi:10.1080/01621459.1988.10478625>, Tokdar (2007) <doi:10.1198/106186007X210206>, Tokdar (2010) <doi:10.1214/10-BA605>, and is further aligned with recent developments in Bayesian non-parametric modelling: see Gautier (2023) <https://boristheses.unibe.ch/4377/>, and Gautier (2025) <doi:10.48550/arXiv.2110.02876>). |
| Authors: | Athénaïs Gautier [aut, cre] |
| Maintainer: | Athénaïs Gautier <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 2.0.0 |
| Built: | 2026-09-24 15:28:54 UTC |
| Source: | https://github.com/cran/SLGP |
The SLGP package provides tools for fitting, summarising, predicting, simulating, updating, and visualising Spatial Logistic Gaussian Processes models (SLGP). SLGP models define flexible conditional distributions through finite-rank Gaussian process representations and can be fitted by MAP, Laplace approximation, or MCMC
The recommended workflow is based on standard R generics:
slgp: fit or initialise an SLGP model.
summary: summarise a fitted SLGP object.
plot: visualise fitted conditional densities.
predict: compute densities, CDFs, quantiles,
or moments.
simulate: draw conditional samples.
update: refit an existing SLGP object.
The package also retains lower-level computational routines such as
predictSLGP_newNode, predictSLGP_cdf,
predictSLGP_quantiles, predictSLGP_moments,
sampleSLGP, and retrainSLGP. These functions are
primarily intended for advanced use and backward compatibility. For ordinary
use, prefer the standard methods listed above.
A typical analysis consists of:
Fitting an SLGP model with slgp.
Computing predictive quantities with
predict.
Drawing samples from the predictive distributions with
simulate.
Updating the fitted model with update, if
required.
Maintainer: Athénaïs Gautier [email protected]
Gautier, Athénaïs (2023). "Modelling and Predicting Distribution-Valued Fields with Applications to Inversion Under Uncertainty." Thesis, Universität Bern, Bern. See the thesis online at https://boristheses.unibe.ch/4377/
set.seed(1) d <- data.frame( x = rep(seq(0, 1, length.out = 6), each = 5) ) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp( y ~ x, data = d, method = "MAP", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2), seed = 1 ) summary(fit) plot(fit, draw = c("mean", 1:5))set.seed(1) d <- data.frame( x = rep(seq(0, 1, length.out = 6), each = 5) ) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp( y ~ x, data = d, method = "MAP", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2), seed = 1 ) summary(fit) plot(fit, draw = c("mean", 1:5))
Extract the coefficient draws of an SLGP model
## S4 method for signature 'SLGP' coef(object, ...)## S4 method for signature 'SLGP' coef(object, ...)
object |
An object of class |
... |
Ignored. |
The matrix of finite-rank GP coefficients (draws in rows, basis functions in columns).
Model formula of an SLGP object
## S4 method for signature 'SLGP' formula(x, ...)## S4 method for signature 'SLGP' formula(x, ...)
x |
An object of class |
... |
Ignored. |
The model formula.
Number of observations used to fit an SLGP model
## S4 method for signature 'SLGP' nobs(object, ...)## S4 method for signature 'SLGP' nobs(object, ...)
object |
An object of class |
... |
Ignored. |
Integer number of observations.
Visualises the conditional densities implied by a fitted (or prior)
SLGP-class model. For a single covariate, the densities are
drawn as response curves at a sequence of covariate slices.
## S4 method for signature 'SLGP,missing' plot( x, y, newdata = NULL, n_slices = 6, n_response = NULL, interpolateBasisFun = "WNN", draw = "mean", panels = TRUE, discrete = .slgp_discrete(x), ... )## S4 method for signature 'SLGP,missing' plot( x, y, newdata = NULL, n_slices = 6, n_response = NULL, interpolateBasisFun = "WNN", draw = "mean", panels = TRUE, discrete = .slgp_discrete(x), ... )
x |
An object of class |
y |
Ignored (present for generic compatibility).#' |
newdata |
Optional data frame of covariate values at which to draw
slices. If |
n_slices |
Number of covariate slices to display (single-covariate models only). Default 8. |
n_response |
Number of response grid points per slice. If |
interpolateBasisFun |
Integral-approximation scheme; default |
draw |
Integer vector selecting coefficient draws to display, or
|
panels |
Logical; if |
discrete |
Logical; whether the response is treated as discrete.
Defaults to the value recorded in |
... |
Further graphical parameters passed to |
This method draws with base graphics so that the package gains a plot
method without taking on a hard ggplot2 dependency. It returns, the
computed prediction data.frame invisibly, so users who prefer
ggplot2 can build their own figure from it.
The prediction data.frame, invisibly.
set.seed(1) d <- data.frame(x = rep(seq(0, 1, length.out = 6), each = 5)) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp(y ~ x, data = d, method = "MAP", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), seed = 1, opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2)) plot(fit, draw = "mean") plot(fit, draw = c("mean", 1:5))set.seed(1) d <- data.frame(x = rep(seq(0, 1, length.out = 6), each = 5)) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp(y ~ x, data = d, method = "MAP", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), seed = 1, opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2)) plot(fit, draw = "mean") plot(fit, draw = c("mean", 1:5))
Single entry point for all distributional summaries produced by an
SLGP-class model. The type argument selects what is
returned and dispatches to the corresponding workhorse function:
"density"conditional density values, newdata must
contain both the
response and the covariate columns.
"cdf"conditional CDF values, newdata as above.
"quantiles"conditional quantiles at probabilities,
newdata contains covariate columns only.
"moments"conditional moments of order(s) power,
newdata contains covariate columns only.
## S4 method for signature 'SLGP' predict( object, newdata, type = c("density", "cdf", "quantiles", "moments"), probs = NULL, power = NULL, centered = FALSE, interpolateBasisFun = "WNN", nIntegral = .slgp_nIntegral(object), nDiscret = 101, discrete = .slgp_discrete(object), ... )## S4 method for signature 'SLGP' predict( object, newdata, type = c("density", "cdf", "quantiles", "moments"), probs = NULL, power = NULL, centered = FALSE, interpolateBasisFun = "WNN", nIntegral = .slgp_nIntegral(object), nDiscret = 101, discrete = .slgp_discrete(object), ... )
object |
An object of class |
newdata |
A |
type |
Character; one of |
probs |
Numeric vector of probabilities in |
power |
Numeric vector of moment orders; required when
|
centered |
Logical; for |
interpolateBasisFun |
Integral-approximation scheme, one of
|
nIntegral, nDiscret
|
Integration / discretisation resolutions passed
through to the utilitarian functions. |
discrete |
Logical; treat the response as discrete. Defaults to the
value recorded in |
... |
Ignored. |
A data.frame as returned by the corresponding
predictSLGP_* function.
set.seed(1) d <- data.frame(x = rep(seq(0, 1, length.out = 6), each = 5)) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp(y ~ x, data = d, method = "MAP", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), seed = 1, opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2)) ## Prediction grid for density and CDF evaluations: grid <- expand.grid(y = seq(min(d$y), max(d$y), length.out = 100), x = c(0.25, 0.75)) ## Predict conditional densities pred_density <- predict(fit, newdata = grid, type = "density") ## Predict conditional cumulative distribution functions pred_cdf <- predict(fit, newdata = grid, type = "cdf") ## Prediction locations for summaries depending only on the covariates newx <- data.frame(x = c(0.25, 0.75)) ## Predict conditional quantiles pred_q <- predict(fit, newdata = newx, type = "quantiles", probs = c(0.25, 0.5, 0.75)) ## Predict the first two raw moments pred_m <- predict(fit, newdata = newx, type = "moments", power = c(1, 2))set.seed(1) d <- data.frame(x = rep(seq(0, 1, length.out = 6), each = 5)) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp(y ~ x, data = d, method = "MAP", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), seed = 1, opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2)) ## Prediction grid for density and CDF evaluations: grid <- expand.grid(y = seq(min(d$y), max(d$y), length.out = 100), x = c(0.25, 0.75)) ## Predict conditional densities pred_density <- predict(fit, newdata = grid, type = "density") ## Predict conditional cumulative distribution functions pred_cdf <- predict(fit, newdata = grid, type = "cdf") ## Prediction locations for summaries depending only on the covariates newx <- data.frame(x = c(0.25, 0.75)) ## Predict conditional quantiles pred_q <- predict(fit, newdata = newx, type = "quantiles", probs = c(0.25, 0.5, 0.75)) ## Predict the first two raw moments pred_m <- predict(fit, newdata = newx, type = "moments", power = c(1, 2))
predictSLGP_cdf() is deprecated; use
predict(object, type = "cdf") instead.
Computes posterior predictive cumulative distribution function values at specified response and covariate locations for a fitted Spatial Logistic Gaussian Process (SLGP) model.
predictSLGP_cdf( SLGPmodel, newNodes, interpolateBasisFun = "WNN", nIntegral = 101, nDiscret = 101, discrete = FALSE )predictSLGP_cdf( SLGPmodel, newNodes, interpolateBasisFun = "WNN", nIntegral = 101, nDiscret = 101, discrete = FALSE )
SLGPmodel |
An object of class |
newNodes |
A data frame containing both the response column and the covariate columns at which the CDF is evaluated. |
interpolateBasisFun |
Character string indicating the interpolation scheme for basis functions:
one of |
nIntegral |
Number of integration points along the response axis. |
nDiscret |
discretisation resolution for interpolation (optional). |
discrete |
Boolean, indicates if we work with continuous pdfs (default, FALSE) or discrete probabilities |
A data frame combining newNodes with columns named
cdf_1, cdf_2, ..., containing predictive CDF evaluations
for each coefficient draw stored in SLGPmodel.
predict for the recommended user interface.
predictSLGP_moments() is deprecated; use
predict(object, type = "moments") instead.
Computes raw or centered moments of the posterior predictive distributions at specified covariate locations.
predictSLGP_moments( SLGPmodel, newNodes, power, centered = FALSE, interpolateBasisFun = "WNN", nIntegral = 101, nDiscret = 101, discrete = FALSE )predictSLGP_moments( SLGPmodel, newNodes, power, centered = FALSE, interpolateBasisFun = "WNN", nIntegral = 101, nDiscret = 101, discrete = FALSE )
SLGPmodel |
An object of class |
newNodes |
A data frame of new covariate values. |
power |
Scalar or vector of positive integers indicating the moment orders to compute. |
centered |
Logical; if |
interpolateBasisFun |
Interpolation mode for basis functions: |
nIntegral |
Number of integration points for computing densities. |
nDiscret |
discretisation resolution of the response space. |
discrete |
Boolean, indicates if we work with continuous pdfs (default, FALSE) or discrete probabilities |
A data frame containing the covariates in newNodes, a column
power, and columns named mSLGP_1, mSLGP_2, ...,
containing predictive moments for each coefficient draw stored in
SLGPmodel.
predict for the recommended user interface.
predictSLGP_newNode() is deprecated; use
predict(object, type = "density") instead.
Computes the posterior predictive probability densities at new covariate points using a fitted Spatial Logistic Gaussian Process (SLGP) model.
predictSLGP_newNode( SLGPmodel, newNodes, interpolateBasisFun = "WNN", nIntegral = 101, nDiscret = 101, normalize = TRUE, discrete = FALSE )predictSLGP_newNode( SLGPmodel, newNodes, interpolateBasisFun = "WNN", nIntegral = 101, nDiscret = 101, normalize = TRUE, discrete = FALSE )
SLGPmodel |
An object of class |
newNodes |
A data frame containing new covariate values at which to evaluate the SLGP. |
interpolateBasisFun |
Character string indicating how basis functions are evaluated:
one of |
nIntegral |
Integer specifying the number of quadrature points over the response space. |
nDiscret |
Integer specifying the discretisation step for interpolation (only used if applicable). |
normalize |
Boolean, indicates if we return normalized or unnormalized pdfs. (defaults to TRUE) |
discrete |
Boolean, indicates if we work with continuous pdfs (default, FALSE) or discrete probabilities |
A data frame combining newNodes with columns named pdf_1, pdf_2, ...,
representing the posterior predictive density for each coefficient draw stored in SLGPmodel.
predict for the recommended user interface.
predictSLGP_quantiles() is deprecated; use
predict(object, type = "quantiles") instead.
Computes predictive quantiles at specified covariate locations by numerical inversion of the posterior predictive CDF.
predictSLGP_quantiles( SLGPmodel, newNodes, probs, interpolateBasisFun = "WNN", nIntegral = 101, nDiscret = 101, discrete = FALSE )predictSLGP_quantiles( SLGPmodel, newNodes, probs, interpolateBasisFun = "WNN", nIntegral = 101, nDiscret = 101, discrete = FALSE )
SLGPmodel |
An object of class |
newNodes |
A data frame containing the covariate columns at which quantiles are evaluated. |
probs |
Numeric vector of probabilities in |
interpolateBasisFun |
Character string specifying interpolation scheme:
one of |
nIntegral |
Number of integration points for computing the SLGP outputs. |
nDiscret |
discretisation resolution used for CDF inversion. |
discrete |
Boolean, indicates if we work with continuous pdfs (default, FALSE) or discrete probabilities |
A data frame containing the covariates in newNodes, a column
probs, and columns named qSLGP_1, qSLGP_2, ...,
containing predictive quantiles for each coefficient draw stored in
SLGPmodel.
predict for the recommended user interface.
Compact, one-screen summary of a fitted (or prior) SLGP-class
object: the model formula, the estimation method, the basis family and its
rank, the response range, the data dimensions, and the key hyperparameters.
No internal slots are dumped.
## S4 method for signature 'SLGP' print(x, ...) ## S4 method for signature 'SLGP' show(object)## S4 method for signature 'SLGP' print(x, ...) ## S4 method for signature 'SLGP' show(object)
x |
An object of class |
... |
Ignored, for S3/S4 generic compatibility. |
object |
An object of class |
x, invisibly.
set.seed(1) d <- data.frame(x = rep(seq(0, 1, length.out = 6), each = 5)) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp(y ~ x, data = d, method = "MAP", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), seed = 1, opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2)) fitset.seed(1) d <- data.frame(x = rep(seq(0, 1, length.out = 6), each = 5)) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp(y ~ x, data = d, method = "MAP", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), seed = 1, opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2)) fit
Print method for SLGP summaries
## S3 method for class 'summary.SLGP' print(x, ...)## S3 method for class 'summary.SLGP' print(x, ...)
x |
An object of class |
... |
Ignored. |
x, invisibly.
retrainSLGP() is deprecated; use
update(object, ...) instead.
Re-estimates an existing SLGP model, optionally with new data, under a chosen estimation method while reusing the existing basis representation and model ranges.
retrainSLGP( SLGPmodel, newdata = NULL, epsilonStart = NULL, method, interpolateBasisFun = "WNN", nIntegral = NULL, nDiscret = 101, hyperparams = NULL, sigmaEstimationMethod = "none", seed = NULL, opts = list(), trend = NULL, discrete = NULL, verbose = FALSE )retrainSLGP( SLGPmodel, newdata = NULL, epsilonStart = NULL, method, interpolateBasisFun = "WNN", nIntegral = NULL, nDiscret = 101, hyperparams = NULL, sigmaEstimationMethod = "none", seed = NULL, opts = list(), trend = NULL, discrete = NULL, verbose = FALSE )
SLGPmodel |
An object of class |
newdata |
Optional data frame containing new observations. If |
epsilonStart |
Optional numeric vector with initial values for the coefficients |
method |
Character string specifying the training method: one of
|
interpolateBasisFun |
Character string specifying how basis functions are evaluated:
|
nIntegral |
Integer specifying the number of quadrature points used to approximate integrals over the response domain. |
nDiscret |
Integer specifying the discretisation grid size (used only if interpolation is enabled). |
hyperparams |
Optional list with updated hyperparameters. Must include:
|
sigmaEstimationMethod |
Character string indicating how to estimate |
seed |
Optional integer to set the random seed for reproducibility. |
opts |
Optional list of additional options passed to inference routines:
|
trend |
Optional function returning the trend of the transformed GP. If not provided, a zero trend is used. |
discrete |
Logical; whether the response is treated as discrete.
If |
verbose |
Logical; if |
An updated object of class SLGP-class with retrained coefficients and updated posterior information.
update for the recommended user interface.
sampleSLGP() is deprecated; use
simulate(object) instead.
Draws samples from the posterior predictive distributions at specified covariate locations using inverse transform sampling based on the estimated predictive CDF.
sampleSLGP( SLGPmodel, newX, n, interpolateBasisFun = "WNN", nIntegral = 101, nDiscret = 101, seed = NULL, discrete = FALSE )sampleSLGP( SLGPmodel, newX, n, interpolateBasisFun = "WNN", nIntegral = 101, nDiscret = 101, seed = NULL, discrete = FALSE )
SLGPmodel |
A trained SLGP model object ( |
newX |
A data frame of new covariate values at which to draw samples. |
n |
Integer or integer vector specifying how many samples to draw at each input point. |
interpolateBasisFun |
Character string specifying interpolation scheme for basis evaluation.
One of |
nIntegral |
Integer; number of quadrature points for density approximation. |
nDiscret |
Integer; discretisation step for the response axis. |
seed |
Optional integer to set a random seed for reproducibility. |
discrete |
Boolean, indicates if we work with continuous pdfs (default, FALSE) or discrete probabilities |
A data frame containing simulated responses, with the covariate
columns from newX and one response column named after the response
variable of SLGPmodel.
simulate for the recommended user interface.
This method provides the standard user interface for simulating from a fitted
SLGP-class object.
## S4 method for signature 'SLGP' simulate( object, nsim = 1, seed = NULL, newdata, type = "predictive", interpolateBasisFun = "WNN", nIntegral = .slgp_nIntegral(object), nDiscret = 101, discrete = .slgp_discrete(object), ... )## S4 method for signature 'SLGP' simulate( object, nsim = 1, seed = NULL, newdata, type = "predictive", interpolateBasisFun = "WNN", nIntegral = .slgp_nIntegral(object), nDiscret = 101, discrete = .slgp_discrete(object), ... )
object |
An object of class |
nsim |
Number of samples to draw at each covariate value. Default 1. |
seed |
Optional integer seed for reproducibility. |
newdata |
A |
type |
Character string; either |
interpolateBasisFun |
Integral-approximation scheme; default |
nIntegral, nDiscret
|
Integration / discretisation resolutions.
|
discrete |
Logical: if |
... |
Ignored. |
A data.frame of sampled responses with the covariate columns
from newdata.
set.seed(1) d <- data.frame(x = rep(seq(0, 1, length.out = 6), each = 5)) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp(y ~ x, data = d, method = "MAP", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), seed = 1, opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2)) ## Draw 10 samples from the conditional distributions at two locations sim <- simulate(fit, type = "predictive", newdata = data.frame(x = c(0.25, 0.75)), nsim = 10) head(sim)set.seed(1) d <- data.frame(x = rep(seq(0, 1, length.out = 6), each = 5)) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp(y ~ x, data = d, method = "MAP", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), seed = 1, opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2)) ## Draw 10 samples from the conditional distributions at two locations sim <- simulate(fit, type = "predictive", newdata = data.frame(x = c(0.25, 0.75)), nsim = 10) head(sim)
Builds a finite-rank Spatial Logistic Gaussian Process (SLGP) model for
conditional density estimation. The model can be fitted by MAP, MCMC, or
Laplace approximation, or initialised without fitting by setting
method = "none".
slgp( formula, data, epsilonStart = NULL, method, basisFunctionsUsed, interpolateBasisFun = "NN", nIntegral = 101, nDiscret = 101, hyperparams = NULL, predictorsUpper = NULL, predictorsLower = NULL, responseRange = NULL, sigmaEstimationMethod = "none", seed = NULL, opts_BasisFun = list(), BasisFunParam = NULL, opts = list(), trend = NULL, discrete = FALSE, verbose = FALSE )slgp( formula, data, epsilonStart = NULL, method, basisFunctionsUsed, interpolateBasisFun = "NN", nIntegral = 101, nDiscret = 101, hyperparams = NULL, predictorsUpper = NULL, predictorsLower = NULL, responseRange = NULL, sigmaEstimationMethod = "none", seed = NULL, opts_BasisFun = list(), BasisFunParam = NULL, opts = list(), trend = NULL, discrete = FALSE, verbose = FALSE )
formula |
A formula specifying the model structure, with the response on the left-hand side and covariates on the right. |
data |
A data frame containing the variables used in the formula. |
epsilonStart |
Optional numeric vector of initial weights for the finite-rank GP:
|
method |
Character string specifying the training method: one of
|
basisFunctionsUsed |
Character string describing the basis function type: one of "inducing points", "RFF", "Discrete FF", "filling FF", or "custom cosines". |
interpolateBasisFun |
Character string indicating how to evaluate basis functions: "nothing" (exact eval), "NN" (nearest-neighbor), or "WNN" (weighted inverse-distance). Default is "NN". |
nIntegral |
Number of quadrature points used for numerical integration over the response domain. |
nDiscret |
Integer controlling the resolution of the interpolation grid (used only for "NN" or "WNN"). |
hyperparams |
Optional list of hyperparameters. Should contain:
|
predictorsUpper |
Optional numeric vector for the upper bounds of the covariates (used for scaling). |
predictorsLower |
Optional numeric vector for the lower bounds of the covariates. |
responseRange |
Optional numeric vector of length 2 with the lower and upper bounds of the response. |
sigmaEstimationMethod |
Method to heuristically estimate the variance |
seed |
Optional integer for reproducibility. |
opts_BasisFun |
List of optional configuration parameters passed to the basis function initializer. |
BasisFunParam |
Optional list of precomputed basis function parameters. |
opts |
Optional list of extra settings passed to inference routines (e.g., |
trend |
Optional function returning the trend of the transformed GP. If not provided, a zero trend is used. |
discrete |
Logical; whether the response is treated as discrete,d efaults to |
verbose |
Logical; if |
An object of S4 class SLGP-class. Standard methods are
available for fitted objects, including summary,
plot, predict,
simulate, update,
coef, formula, and
nobs.
Gautier, Athénaïs (2023). "Modelling and Predicting Distribution-Valued Fields with Applications to Inversion Under Uncertainty." Thesis, Universität Bern, Bern. https://boristheses.unibe.ch/4377/
set.seed(1) d <- data.frame( x = rep(seq(0, 1, length.out = 6), each = 5) ) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp( y ~ x, data = d, method = "Prior", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2), seed = 1 ) fit summary(fit)set.seed(1) d <- data.frame( x = rep(seq(0, 1, length.out = 6), each = 5) ) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit <- slgp( y ~ x, data = d, method = "Prior", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2), seed = 1 ) fit summary(fit)
This S4 class represents a Spatial Logistic Gaussian Process (SLGP) model, designed for modelling conditional or spatially dependent probability distributions. It encapsulates all necessary components for training, sampling, and prediction, including the basis function setup, learned coefficients, and fitted hyperparameters.
formulaA formula specifying the model structure and covariates.
dataA data.frame containing the observations used to train the model.
responseNameA character string specifying the name of the response variable.
covariateNameA character vector specifying the names of the covariates.
responseRangeA numeric vector of length 2 indicating the lower and upper bounds of the response.
predictorsRangeA list containing:
predictorsLower: lower bounds of the covariates;
predictorsUpper: upper bounds of the covariates.
methodA character string indicating the training method used: one of {"MCMC", "MAP", "Laplace", "none"}.
pAn integer indicating the number of basis functions used.
basisFunctionsUsedA character string specifying the type of basis functions used:
"inducing points", "RFF", "Discrete FF", "filling FF", or "custom cosines".
opts_BasisFunA list of additional options used to configure the basis functions.
BasisFunParamA list containing the computed parameters of the basis functions,
e.g., Fourier frequencies or interpolation weights.
coefficientsA matrix of coefficients for the finite-rank Gaussian process.
Each row corresponds to a realization of the latent field:
.
hyperparamsA list of hyperparameters, including:
sigma: numeric signal standard deviation;
lengthscale: a vector of lengthscales for each input dimension.
trendA function that returns the trend of the transformed GP (not to be estimated).
discreteA logical indicating whether the response is treated as
discrete, i.e. supported on the nIntegral nodes spanning
responseRange, in which case the normalising integral is an exact
finite sum rather than a quadrature approximation.
nIntegralAn integer giving the number of quadrature nodes used
at fitting. For a discrete response this is the size of the support.
diagnosticsA list of fit diagnostics produced by the
estimation scheme: convergence summaries (R-hat, effective sample sizes,
divergent transitions) for "MCMC", the nugget and conditioning of
the Hessian for "Laplace", and the optimiser return code for
"MAP". It also contains a timing element giving the
wall-clock cost of the fit, split into setup (normalisation,
quadrature pre-computation, basis evaluation) and estimation.
See summary.
logPostA numeric value representing the (unnormalized) log-posterior of the model.
Currently available only for MAP and Laplace-trained models.
Extends print with diagnostics. Two kinds are reported.
## S4 method for signature 'SLGP' summary(object, diagnostics = FALSE, newdata = NULL, ...)## S4 method for signature 'SLGP' summary(object, diagnostics = FALSE, newdata = NULL, ...)
object |
An object of class |
diagnostics |
Logical; if |
newdata |
Optional |
... |
Ignored. |
Sampler diagnostics describe how well the estimation scheme worked.
This is the by-products of fitting, stored in the model, and always shown:
R-hat, effective sample sizes, divergent transitions and BFMI for
"MCMC"; the nugget added to the Hessian and its conditioning for
"Laplace"; the optimiser return code for "MAP".
Predictive diagnostics describe how well the fitted field describes
data: the mean log predictive density per observation, and the probability integral
transform (PIT) of the observations with a Kolmogorov-Smirnov statistic
against the uniform. These require evaluating the model at every observation
and are therefore computed only when diagnostics = TRUE.
For a Laplace fit, the importance-sampling effective sample size of the Gaussian draws relative to the true posterior is also reported: it says how many of the stored draws are worth, in effective terms, once reweighted, and hence reflects whether the Gaussian approximation is adequate.
An object of class "summary.SLGP" (a list), returned invisibly.
Returns the time spent fitting, split into the two phases that scale
differently: setup (normalisation, quadrature pre-computation and
basis evaluation, which grow with the number of distinct covariate values and
with nDiscret) and estimation (the call to rstan, which
grows with the rank and, for MCMC, with the number of iterations).
timing(object, ...) ## S4 method for signature 'SLGP' timing(object, ...)timing(object, ...) ## S4 method for signature 'SLGP' timing(object, ...)
object |
An object of class |
... |
Ignored. |
The result is a one-row data.frame, so that timings collected over a
set of fits can be stacked with rbind and plotted
directly.
All times are wall-clock seconds. With more than one core the cumulated CPU time exceeds the elapsed time, so only elapsed times are comparable across settings and platforms.
A data.frame with one row and the columns method,
p, nobs, ndraws, setup, estimation,
total and, for MCMC, n_chains, warmup and
sample (means over chains). Returns NULL for models fitted
with a version of the package that did not record timings.
## Not run: ## Compare estimation schemes over several replicates fits <- lapply(1:10, function(i) slgp(depth ~ long, data = quakes, method = "MAP", basisFunctionsUsed = "RFF", seed = i, opts_BasisFun = list(nFreq = 200, MatParam = 5/2))) tm <- do.call(rbind, lapply(fits, timing)) boxplot(total ~ method, data = tm, ylab = "Fitting time [s]") ## End(Not run)## Not run: ## Compare estimation schemes over several replicates fits <- lapply(1:10, function(i) slgp(depth ~ long, data = quakes, method = "MAP", basisFunctionsUsed = "RFF", seed = i, opts_BasisFun = list(nFreq = 200, MatParam = 5/2))) tm <- do.call(rbind, lapply(fits, timing)) boxplot(total ~ method, data = tm, ylab = "Fitting time [s]") ## End(Not run)
Standard-generic front end to retrainSLGP: re-estimates an
existing SLGP-class model, optionally with new data, under a
chosen estimation method, reusing the existing basis and ranges.
## S4 method for signature 'SLGP' update( object, method, newdata = NULL, epsilonStart = NULL, interpolateBasisFun = "WNN", nIntegral = NULL, nDiscret = 101, discrete = NULL, hyperparams = NULL, sigmaEstimationMethod = "none", seed = NULL, opts = list(), trend = NULL, verbose = FALSE, ... )## S4 method for signature 'SLGP' update( object, method, newdata = NULL, epsilonStart = NULL, interpolateBasisFun = "WNN", nIntegral = NULL, nDiscret = 101, discrete = NULL, hyperparams = NULL, sigmaEstimationMethod = "none", seed = NULL, opts = list(), trend = NULL, verbose = FALSE, ... )
object |
An object of class |
method |
Estimation method: one of |
newdata |
Optional new |
epsilonStart |
Optional initial coefficient values. |
interpolateBasisFun |
Integral-approximation scheme; default |
nIntegral, nDiscret
|
Integration / discretisation resolutions. If
|
discrete |
Logical; whether the response is treated as discrete.
If |
hyperparams |
Optional list of hyperparameters; if |
sigmaEstimationMethod |
Variance-selection method; default |
seed |
Optional integer seed. |
opts |
List of method-specific options (e.g. |
trend |
Optional trend function. |
verbose |
Logical; verbosity. Default |
... |
Ignored. |
An updated object of class SLGP-class.
retrainSLGP for the low-level routine.
set.seed(1) d <- data.frame(x = rep(seq(0, 1, length.out = 6), each = 5)) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit_prior <- slgp(y ~ x, data = d, method = "Prior", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), seed = 1, opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2)) ## Refit the same model structure by MAP fit_map <- update(fit_prior, method = "MAP")set.seed(1) d <- data.frame(x = rep(seq(0, 1, length.out = 6), each = 5)) d$y <- rnorm(nrow(d), mean = sin(2 * pi * d$x), sd = 0.2) fit_prior <- slgp(y ~ x, data = d, method = "Prior", basisFunctionsUsed = "RFF", predictorsLower = 0, predictorsUpper = 1, responseRange = range(d$y), seed = 1, opts_BasisFun = list(nFreq = 20, MatParam = 5 / 2)) ## Refit the same model structure by MAP fit_map <- update(fit_prior, method = "MAP")