| Title: | Deep Compositional Spatial Models |
|---|---|
| Description: | Deep compositional spatial models are standard spatial covariance models coupled with an injective warping function of the spatial domain. The warping function is constructed through a composition of multiple elemental injective functions in a deep-learning framework. The package implements two cases for the univariate setting; first, when these warping functions are known up to some weights that need to be estimated, and, second, when the weights in each layer are random. In the multivariate setting only the former case is available. Estimation and inference is done using `tensorflow`, which makes use of graphics processing units. For more details see Zammit-Mangion et al. (2022) <doi:10.1080/01621459.2021.1887741>, Vu et al. (2022) <doi:10.5705/ss.202020.0156>, Vu et al. (2023) <doi:10.1016/j.spasta.2023.100742>, and Shao et al. (2025) <doi:10.48550/arXiv.2505.12548>. |
| Authors: | Andrew Zammit-Mangion [aut], Quan Vu [aut, cre], Xuanjie Shao [aut] |
| Maintainer: | Quan Vu <[email protected]> |
| License: | Apache License 2.0 |
| Version: | 0.3.1 |
| Built: | 2026-06-02 11:33:04 UTC |
| Source: | https://github.com/andrewzm/deepspat |
Sets up an affine transformation on a 1D domain
AFF_1D(a = c(0, 1), dtype = "float32")AFF_1D(a = c(0, 1), dtype = "float32")
a |
vector of two real numbers describing an affine transformation on a 1D domain |
dtype |
data type |
AFF_1D returns a list containing a list with the following components:
An encapsulated function that takes an input and evaluates the affine transformation using TensorFlow
Same as f but uses R
The number of basis functions (fixed to 1 in this case)
The transformation applied to the weights before estimation (in this case the identity)
Flag indicating whether the weights are fixed or not (TRUE in this case)
Name of layer
List of parameters describing the affine transformation as TensorFlow objects
Sets up an affine transformation on a 2D domain
AFF_2D(a = c(0, 1, 0, 0, 0, 1), dtype = "float32")AFF_2D(a = c(0, 1, 0, 0, 0, 1), dtype = "float32")
a |
vector of six real numbers describing an affine transformation on a 2D domain |
dtype |
data type |
AFF_2D returns a list containing a list with the following components:
An encapsulated function that takes an input and evaluates the affine transformation using TensorFlow
Same as f but uses R
The number of basis functions (fixed to 1 in this case)
The transformation applied to the weights before estimation (in this case the identity)
Flag indicating whether the weights are fixed or not (TRUE in this case)
Name of layer
List of parameters describing the affine transformation as TensorFlow objects
Sets up an axial warping unit (AWU) for used in a deep compositional spatial model. The function sets up sigmoids on a prescribed domain at regular intervals, with 'steepness' indicated by the user. It returns a list of length 1 containing an axial warping unit (AWU) and several encapsulated functions that evaluate the AWU over inputs of different types. See Value for more details.
AWU(r = 50L, dim = 1L, grad = 200, lims = c(-0.5, 0.5), dtype = "float32")AWU(r = 50L, dim = 1L, grad = 200, lims = c(-0.5, 0.5), dtype = "float32")
r |
number of basis functions |
dim |
dimension to warp |
grad |
steepness of the sigmoid functions |
lims |
the bounded 1D domain on which to set up the sigmoids |
dtype |
data type |
AWU returns a list containing a list with the following components:
An encapsulated function that takes an input and evaluates the sigmoids over the dim-th dimension using TensorFlow
Same as f but uses R
Same as f but does it in parallel for several inputs index by the first dimension of the tensor
The number of sigmoid basis functions
The transformation applied to the weights before estimation
Flag indicating whether the weights are fixed or not (FALSE for AWUs)
Name of layer
if (reticulate::py_module_available("tensorflow")) { layer <- AWU(r = 50L, dim = 1L, grad = 200, lims = c(-0.5, 0.5)) }if (reticulate::py_module_available("tensorflow")) { layer <- AWU(r = 50L, dim = 1L, grad = 200, lims = c(-0.5, 0.5)) }
Sets up a top-layer set of bisquare basis functions on a bounded 1D domain of
length 1 for modelling the process . It returns a list of length 1 containing the basis functions and encapsulated
functions that evaluate the bisquare functions over inputs of different types. See Value for more details.
bisquares1D(r = 30, lims = c(-0.5, 0.5), dtype = "float32")bisquares1D(r = 30, lims = c(-0.5, 0.5), dtype = "float32")
r |
30 |
lims |
the limits of one side of the square bounded 2D domain on which to set up the bisquare functions |
dtype |
data type |
bisquares1D returns a list containing a list with the following components:
An encapsulated function that takes an input and evaluates the sigmoids over the dim-th dimension using TensorFlow
The number of sigmoid basis functions
The centroids of the basis functions as a TensorFlow object
Sets up a top-layer set of bisquare basis functions on a square 2D domain of
size 1 x 1 for modelling the process . It returns a list of length 1 containing the basis functions and encapsulated
functions that evaluate the bisquare functions over inputs of different types. See Value for more details.
bisquares2D(r = 30, lims = c(-0.5, 0.5), dtype = "float32")bisquares2D(r = 30, lims = c(-0.5, 0.5), dtype = "float32")
r |
30 |
lims |
the bounded 1D domain on which to set up the bisquare functions |
dtype |
data type |
bisquares1D returns a list containing a list with the following components:
An encapsulated function that takes an input and evaluates the sigmoids over the dim-th dimension using TensorFlow
Same as f but uses R
The number of sigmoid basis functions
The centroids of the basis functions as a TensorFlow object
The centroids of the basis functions as an R object
Deep compositional spatial models are standard low-rank spatial models coupled with a bijective warping function of the spatial domain. The warping function is constructed through a composition of multiple elemental bijective functions in a deep-learning framework. The package implements two cases; first, when these functions are known up to some weights that need to be estimated, and, second, when the weights in each layer are random. Estimation and inference is done using TensorFlow, which makes use of graphical processing units.
Constructs a deep compositional spatial model
deepspat( f, data, layers = NULL, method = c("VB", "ML"), par_init = initvars(), learn_rates = init_learn_rates(), MC = 10L, nsteps )deepspat( f, data, layers = NULL, method = c("VB", "ML"), par_init = initvars(), learn_rates = init_learn_rates(), MC = 10L, nsteps )
f |
formula identifying the dependent variable and the spatial inputs (RHS can only have one or two variables) |
data |
data frame containing the required data |
layers |
list containing the warping layers |
method |
either 'ML' (for the SIWGP) or 'VB' (for the SDSP) |
par_init |
list of initial parameter values. Call the function |
learn_rates |
learning rates for the various quantities in the model. Call the function |
MC |
number of MC samples when doing stochastic variational inference |
nsteps |
number of steps when doing gradient descent times three (first time the weights are optimised, then the covariance-function parameters, then everything together) |
deepspat returns an object of class deepspat with the following items
The final value of the cost (NMLL for the SIWGP and the lower bound for the SDSP, plus a constant)
Posterior means of the weights in the top layer as a TensorFlow object
Posterior precision of the weights in the top layer as a TensorFlow object
Estimated or posterior means of the weights in the warping layers as a list of TensorFlow objects
Precision of measurement error, as a TensorFlow object
Variance of the weights in the top layer, as a TensorFlow object
Length scale used to construct the covariance matrix of the weights in the top layer, as a TensorFlow object
Minima and maxima used to scale the unscaled unit outputs for each layer, as a list of TensorFlow objects
Either 'ML' or 'VB'
Number of layers in the model (including the top layer)
Number of MC samples when doing stochastic variational inference
TensorFlow session for evaluating the TensorFlow objects
The formula used to construct the deepspat model
The data used to construct the deepspat model
Vector of costs after each gradient-descent evaluation
Empirical mean of the original data
Empirical mean of the original data as a TensorFlow object
Maintainer: Quan Vu [email protected]
Authors:
Andrew Zammit-Mangion
Xuanjie Shao
Useful links:
if (reticulate::py_module_available("tensorflow") && reticulate::py_module_available("scipy")) { df <- data.frame(s1 = rnorm(100), s2 = rnorm(100), z = rnorm(100)) layers <- c(AWU(r = 50L, dim = 1L, grad = 200, lims = c(-0.5, 0.5)), AWU(r = 50L, dim = 2L, grad = 200, lims = c(-0.5, 0.5)), bisquares2D(r = 100)) d <- deepspat(f = z ~ s1 + s2 - 1, data = df, layers = layers, method = "ML", nsteps = 10L) }if (reticulate::py_module_available("tensorflow") && reticulate::py_module_available("scipy")) { df <- data.frame(s1 = rnorm(100), s2 = rnorm(100), z = rnorm(100)) layers <- c(AWU(r = 50L, dim = 1L, grad = 200, lims = c(-0.5, 0.5)), AWU(r = 50L, dim = 2L, grad = 200, lims = c(-0.5, 0.5)), bisquares2D(r = 100)) d <- deepspat(f = z ~ s1 + s2 - 1, data = df, layers = layers, method = "ML", nsteps = 10L) }
Constructs a deep bivariate compositional spatial model
deepspat_bivar_GP( f, data, g = ~1, layers_asym = NULL, layers = NULL, method = "REML", family = c("exp_stat_symm", "exp_stat_asymm", "exp_nonstat_symm", "exp_nonstat_asymm", "matern_stat_symm", "matern_stat_asymm", "matern_nonstat_symm", "matern_nonstat_asymm"), par_init = initvars(), learn_rates = init_learn_rates(), nsteps = 150L )deepspat_bivar_GP( f, data, g = ~1, layers_asym = NULL, layers = NULL, method = "REML", family = c("exp_stat_symm", "exp_stat_asymm", "exp_nonstat_symm", "exp_nonstat_asymm", "matern_stat_symm", "matern_stat_asymm", "matern_nonstat_symm", "matern_nonstat_asymm"), par_init = initvars(), learn_rates = init_learn_rates(), nsteps = 150L )
f |
formula identifying the dependent variables and the spatial inputs in the covariance |
data |
data frame containing the required data |
g |
formula identifying the independent variables in the linear trend |
layers_asym |
list containing the aligning function layers |
layers |
list containing the nonstationary warping layers |
method |
identifying the method for finding the estimates |
family |
identifying the family of the model constructed |
par_init |
list of initial parameter values. Call the function |
learn_rates |
learning rates for the various quantities in the model. Call the function |
nsteps |
number of steps when doing gradient descent times two, three or five (depending on the family of model) |
deepspat_bivar_GP returns an object of class deepspat_bivar_GP with the following items
The formula used to construct the covariance model
The formula used to construct the linear trend model
The data used to construct the deepspat model
The model matrix of the linear trend
The warping function layers in the model
The aligning function layers in the model
The final value of the cost
Estimated weights in the warping layers as a list of TensorFlow objects
Estimated weights in the aligning layers as a list of TensorFlow objects
Estimated parameters in the LFT layers
Estimated parameters in the AFF layers of the aligning function
Estimated coefficients of the linear trend
Precision of measurement error of the first process, as a TensorFlow object
Precision of measurement error of the second process, as a TensorFlow object
Variance parameter (first process) in the covariance matrix, as a TensorFlow object
Variance parameter (second process) in the covariance matrix, as a TensorFlow object
Covariance parameter in the covariance matrix, as a TensorFlow object
Length scale parameter (first process) in the covariance matrix, as a TensorFlow object
Length scale parameter (second process) in the covariance matrix, as a TensorFlow object
Length scale parameter (cross-covariance) in the covariance matrix, as a TensorFlow object
Smoothness parameter (first process) in the covariance matrix, as a TensorFlow object
Smoothness parameter (second process) in the covariance matrix, as a TensorFlow object
Smoothness parameter (cross-covariance) in the covariance matrix, as a TensorFlow object
Minima and maxima used to scale the unscaled unit outputs for each warping layer, as a list of TensorFlow objects
Minima and maxima used to scale the unscaled unit outputs for each aligning layer, as a list of TensorFlow objects
Method used for inference
Number of warping layers in the model
Number of aligning layers in the model
Spatial locations of the first process on the warped domain
Spatial locations of the second process on the warped domain
Vector of costs after each gradient-descent evaluation
Data of the first process
Data of the second process
Family of the model
if (reticulate::py_module_available("tensorflow") && reticulate::py_module_available("scipy")) { df <- data.frame(s1 = rnorm(100), s2 = rnorm(100), z1 = rnorm(100), z2 = rnorm(100)) layers <- c(AWU(r = 50L, dim = 1L, grad = 200, lims = c(-0.5, 0.5)), AWU(r = 50L, dim = 2L, grad = 200, lims = c(-0.5, 0.5))) d <- deepspat_bivar_GP(f = z1 + z2 ~ s1 + s2 - 1, data = df, g = ~ 1, layers = layers, method = "REML", family = "matern_nonstat_symm", nsteps = 10L) }if (reticulate::py_module_available("tensorflow") && reticulate::py_module_available("scipy")) { df <- data.frame(s1 = rnorm(100), s2 = rnorm(100), z1 = rnorm(100), z2 = rnorm(100)) layers <- c(AWU(r = 50L, dim = 1L, grad = 200, lims = c(-0.5, 0.5)), AWU(r = 50L, dim = 2L, grad = 200, lims = c(-0.5, 0.5))) d <- deepspat_bivar_GP(f = z1 + z2 ~ s1 + s2 - 1, data = df, g = ~ 1, layers = layers, method = "REML", family = "matern_nonstat_symm", nsteps = 10L) }
Constructs a deep compositional spatial model
deepspat_GP( f, data, g = ~1, layers = NULL, method = c("REML"), family = c("exp_stat", "exp_nonstat", "matern_stat", "matern_nonstat"), par_init = initvars(), learn_rates = init_learn_rates(), nsteps = 150L )deepspat_GP( f, data, g = ~1, layers = NULL, method = c("REML"), family = c("exp_stat", "exp_nonstat", "matern_stat", "matern_nonstat"), par_init = initvars(), learn_rates = init_learn_rates(), nsteps = 150L )
f |
formula identifying the dependent variables and the spatial inputs in the covariance |
data |
data frame containing the required data |
g |
formula identifying the independent variables in the linear trend |
layers |
list containing the nonstationary warping layers |
method |
identifying the method for finding the estimates |
family |
identifying the family of the model constructed |
par_init |
list of initial parameter values. Call the function |
learn_rates |
learning rates for the various quantities in the model. Call the function |
nsteps |
number of steps when doing gradient descent times two or three (depending on the family of model) |
deepspat_GP returns an object of class deepspat_GP with the following items
The formula used to construct the covariance model
The formula used to construct the linear trend model
The data used to construct the deepspat model
The model matrix of the linear trend
The warping function layers in the model
The final value of the cost
Estimated weights in the warping layers as a list of TensorFlow objects
Estimated parameters in the LFT layers
Estimated coefficients of the linear trend
Precision of measurement error, as a TensorFlow object
Variance parameter in the covariance matrix, as a TensorFlow object
Length scale parameter in the covariance matrix, as a TensorFlow object
Smoothness parameter in the covariance matrix, as a TensorFlow object
Minima and maxima used to scale the unscaled unit outputs for each warping layer, as a list of TensorFlow objects
Method used for inference
Number of warping layers in the model
Spatial locations on the warped domain
Vector of costs after each gradient-descent evaluation
Data of the process
Family of the model
if (reticulate::py_module_available("tensorflow") && reticulate::py_module_available("scipy")) { df <- data.frame(s1 = rnorm(100), s2 = rnorm(100), z = rnorm(100)) layers <- c(AWU(r = 50L, dim = 1L, grad = 200, lims = c(-0.5, 0.5)), AWU(r = 50L, dim = 2L, grad = 200, lims = c(-0.5, 0.5))) d <- deepspat_GP(f = z ~ s1 + s2 - 1, data = df, g = ~ 1, layers = layers, method = "REML", family = "matern_nonstat", nsteps = 10L) }if (reticulate::py_module_available("tensorflow") && reticulate::py_module_available("scipy")) { df <- data.frame(s1 = rnorm(100), s2 = rnorm(100), z = rnorm(100)) layers <- c(AWU(r = 50L, dim = 1L, grad = 200, lims = c(-0.5, 0.5)), AWU(r = 50L, dim = 2L, grad = 200, lims = c(-0.5, 0.5))) d <- deepspat_GP(f = z ~ s1 + s2 - 1, data = df, g = ~ 1, layers = layers, method = "REML", family = "matern_nonstat", nsteps = 10L) }
Constructs an extended deep compositional spatial model that supports different estimation methods ("MPL", "MRPL", or "WLS") and spatial dependence families (stationary or non-stationary). This function extends the basic deepspat model by incorporating additional dependence modeling and pre-training steps for the warping layers.
deepspat_MSP( f, data, layers = NULL, method = c("MPL", "MRPL", "WLS"), par_init = initvars(), learn_rates = init_learn_rates(), family = c("power_stat", "power_nonstat"), dtype = "float64", nsteps = 100L, nsteps_pre = 100L, edm_emp = NULL, p = c(0, 1), pen_coef = 0, show = TRUE, ... )deepspat_MSP( f, data, layers = NULL, method = c("MPL", "MRPL", "WLS"), par_init = initvars(), learn_rates = init_learn_rates(), family = c("power_stat", "power_nonstat"), dtype = "float64", nsteps = 100L, nsteps_pre = 100L, edm_emp = NULL, p = c(0, 1), pen_coef = 0, show = TRUE, ... )
f |
A formula identifying the dependent variable(s) and the spatial inputs. Use |
data |
A data frame containing the required data. |
layers |
A list containing the warping layers; required for non-stationary models (i.e., when |
method |
A character string specifying the estimation method. Must be one of |
par_init |
A list of initial parameter values. Call the function |
learn_rates |
A list of learning rates for the various quantities in the model. Call the function |
family |
A character string specifying the spatial dependence model. Use |
dtype |
A character string indicating the data type for TensorFlow computations ( |
nsteps |
An integer specifying the number of training steps for dependence parameter learning. |
nsteps_pre |
An integer specifying the number of pre-training steps for warping layer parameters. |
edm_emp |
For the WLS method, a numeric vector or matrix providing an empirical extremal coefficients. |
p |
For pairwise likelihood based methods, p is used to specify the size of pair subset for pairwise likelihood, or the probability parameter of Bernoulli r.v. for randomized pairwise likelihood. |
pen_coef |
A penalty parameter for weights of SR-RBF(2) to relieve overfitting. |
show |
Logical; if |
... |
Currently unused. |
deepspat_MSP returns an object of class deepspat_MSP which is a list containing the following components:
layersThe list of warping layers used in the model.
CostThe final cost value after training (e.g., negative log-likelihood, least squares, or gradient score).
transeta_tfTensorFlow objects for the transformed dependence parameters in the warping layers.
eta_tfTensorFlow objects for the warped dependence parameters.
a_tfTensorFlow object for the parameters of the LFT layers (if applicable).
logphi_tfTensorFlow variable representing the logarithm of the spatial range parameter.
logitkappa_tfTensorFlow variable representing the logit-transformed degrees of freedom.
scalingsA list of scaling limits (minima and maxima) for the input and warped spatial coordinates.
s_tfTensorFlow object for the scaled spatial coordinates.
z_tfTensorFlow object for the observed response values.
swarped_tfList of TensorFlow objects representing the warped spatial coordinates at each layer.
swarpedMatrix of final warped spatial coordinates.
methodThe estimation method used ("MPL", "MRPL", or "WLS").
familyThe spatial dependence family ("power_stat" or "power_nonstat").
dtypeThe data type used in TensorFlow computations.
nlayersNumber of warping layers (for non-stationary models).
fThe model formula.
dataThe data frame used for model fitting.
ndataNumber of observations in data.
negcostVector of cost values recorded during training.
pairs_tfTensorFlow variable representing the spatial location pairs (and, for MRPL, the replicate indices) used in the pairwise / randomized pairwise likelihood or WLS objective..
pThe parameter of Bernoulli r.v. for pairwise likelihood and randomized pairwise likelihood.
timeElapsed time for model fitting.
Constructs a deep compositional spatial model (with nearest neighbors)
deepspat_nn_GP( f, data, g = ~1, layers = NULL, m = 25L, order_id, nn_id, method = c("REML"), family = c("exp_stat", "exp_nonstat"), par_init = initvars(), learn_rates = init_learn_rates(), nsteps = 150L )deepspat_nn_GP( f, data, g = ~1, layers = NULL, m = 25L, order_id, nn_id, method = c("REML"), family = c("exp_stat", "exp_nonstat"), par_init = initvars(), learn_rates = init_learn_rates(), nsteps = 150L )
f |
formula identifying the dependent variables and the spatial inputs in the covariance |
data |
data frame containing the required data |
g |
formula identifying the independent variables in the linear trend |
layers |
list containing the nonstationary warping layers |
m |
number of nearest neighbors |
order_id |
indices of the order of the observations |
nn_id |
indices of the nearest neighbors of the ordered observations |
method |
identifying the method for finding the estimates |
family |
identifying the family of the model constructed |
par_init |
list of initial parameter values. Call the function |
learn_rates |
learning rates for the various quantities in the model. Call the function |
nsteps |
number of steps when doing gradient descent times two or three (depending on the family of model) |
deepspat_nn_GP returns an object of class deepspat_nn_GP with the following items
The formula used to construct the covariance model
The formula used to construct the linear trend model
The data used to construct the deepspat model
The model matrix of the linear trend
The warping function layers in the model
The final value of the cost
Estimated weights in the warping layers as a list of TensorFlow objects
Estimated parameters in the LFT layers
Estimated coefficients of the linear trend
Precision of measurement error, as a TensorFlow object
Variance parameter in the covariance matrix, as a TensorFlow object
Length scale parameter in the covariance matrix, as a TensorFlow object
Minima and maxima used to scale the unscaled unit outputs for each warping layer, as a list of TensorFlow objects
Method used for inference
Number of warping layers in the model
Spatial locations on the warped domain
Vector of costs after each gradient-descent evaluation
Data of the process
The number of nearest neighbors
Family of the model
Constructs a deep compositional spatio-temporal model (with nearest neighbors)
deepspat_nn_ST_GP( f, data, g = ~1, layers_spat = NULL, layers_temp = NULL, m = 25L, order_id, nn_id, method = c("REML"), family = c("exp_stat_sep", "exp_stat_asym", "exp_nonstat_sep", "exp_nonstat_asym"), par_init = initvars(), learn_rates = init_learn_rates(), nsteps = 150L )deepspat_nn_ST_GP( f, data, g = ~1, layers_spat = NULL, layers_temp = NULL, m = 25L, order_id, nn_id, method = c("REML"), family = c("exp_stat_sep", "exp_stat_asym", "exp_nonstat_sep", "exp_nonstat_asym"), par_init = initvars(), learn_rates = init_learn_rates(), nsteps = 150L )
f |
formula identifying the dependent variables and the spatial inputs in the covariance |
data |
data frame containing the required data |
g |
formula identifying the independent variables in the linear trend |
layers_spat |
list containing the spatial warping layers |
layers_temp |
list containing the temporal warping layers |
m |
number of nearest neighbors |
order_id |
indices of the order of the observations |
nn_id |
indices of the nearest neighbors of the ordered observations |
method |
identifying the method for finding the estimates |
family |
identifying the family of the model constructed |
par_init |
list of initial parameter values. Call the function |
learn_rates |
learning rates for the various quantities in the model. Call the function |
nsteps |
number of steps when doing gradient descent times two or three (depending on the family of model) |
deepspat_nn_ST_GP returns an object of class deepspat_nn_ST_GP with the following items
The formula used to construct the covariance model
The formula used to construct the linear trend model
The data used to construct the deepspat model
The model matrix of the linear trend
The spatial warping function layers in the model
The temporal warping function layers in the model
The final value of the cost
Family of the model
Estimated weights in the spatial warping layers as a list of TensorFlow objects
Estimated weights in the temporal warping layers as a list of TensorFlow objects
Estimated parameters in the LFT layers
Estimated coefficients of the linear trend
Precision of measurement error, as a TensorFlow object
Variance parameter in the covariance matrix, as a TensorFlow object
Parameters of the covariance matrix (indicating asymmetric spatio-temporal covariance)
Length scale (for spatial dimension) parameter in the covariance matrix, as a TensorFlow object
Length scale (for temporal dimension) parameter in the covariance matrix, as a TensorFlow object
Minima and maxima used to scale the unscaled unit outputs for each spatial warping layer, as a list of TensorFlow objects
Minima and maxima used to scale the unscaled unit outputs for each temporal warping layer, as a list of TensorFlow objects
Method used for inference
Number of spatial warping layers in the model
Number of temporal warping layers in the model
Spatial locations on the warped domain
Temporal locations on the warped domain
Vector of costs after each gradient-descent evaluation
Data of the process
The number of nearest neighbors
Constructs an extended deep compositional spatial model that supports different estimation methods ("GSM" or "WLS") and spatial dependence families (stationary or non-stationary). This function extends the basic deepspat model by incorporating additional dependence modeling and pre-training steps for the warping layers.
deepspat_rPP( f, data, layers = NULL, method = c("WLS", "GSM"), par_init = initvars(), learn_rates = init_learn_rates(), family = c("power_stat", "power_nonstat"), dtype = "float32", nsteps = 100L, nsteps_pre = 100L, edm_emp = NULL, risk = NULL, thre = NULL, weight_fun = NULL, dWeight_fun = NULL, pen_coef = 0, show = TRUE, ... )deepspat_rPP( f, data, layers = NULL, method = c("WLS", "GSM"), par_init = initvars(), learn_rates = init_learn_rates(), family = c("power_stat", "power_nonstat"), dtype = "float32", nsteps = 100L, nsteps_pre = 100L, edm_emp = NULL, risk = NULL, thre = NULL, weight_fun = NULL, dWeight_fun = NULL, pen_coef = 0, show = TRUE, ... )
f |
A formula identifying the dependent variable(s) and the spatial inputs. Use |
data |
A data frame containing the required data. |
layers |
A list containing the warping layers; required for non-stationary models (i.e., when |
method |
A character string specifying the estimation method. Must be one of |
par_init |
A list of initial parameter values. Call the function |
learn_rates |
A list of learning rates for the various quantities in the model. Call the function |
family |
A character string specifying the spatial dependence model. Use |
dtype |
A character string indicating the data type for TensorFlow computations ( |
nsteps |
An integer specifying the number of training steps for dependence parameter learning. |
nsteps_pre |
An integer specifying the number of pre-training steps for warping layer parameters. |
edm_emp |
For the LS method, a numeric vector or matrix providing an empirical conditional exceedance probabilities. |
risk |
For the GS method, a numeric value indicating the risk parameter. |
thre |
A numeric threshold used in the GS method. |
weight_fun |
A function used to weight pairwise differences in the GS method. |
dWeight_fun |
A function representing the derivative of |
pen_coef |
A penalty parameter for weights of SR-RBF(2) to relieve overfitting. |
show |
Logical; if |
... |
Currently unused. |
deepspat_rPP returns an object of class deepspat_rPP which is a list containing the following components:
layersThe list of warping layers used in the model.
CostThe final cost value after training (e.g., negative log-likelihood, least squares, or gradient score).
transeta_tfTensorFlow objects for the transformed dependence parameters in the warping layers.
eta_tfTensorFlow objects for the warped dependence parameters.
a_tfTensorFlow object for the parameters of the LFT layers (if applicable).
logphi_tfTensorFlow variable representing the logarithm of the spatial range parameter.
logitkappa_tfTensorFlow variable representing the logit-transformed degrees of freedom.
scalingsA list of scaling limits (minima and maxima) for the input and warped spatial coordinates.
s_tfTensorFlow object for the scaled spatial coordinates.
z_tfTensorFlow object for the observed response values.
u_tfTensorFlow object for the threshold used in the GS method (if applicable).
swarped_tfList of TensorFlow objects representing the warped spatial coordinates at each layer.
swarpedMatrix of final warped spatial coordinates.
methodThe estimation method used ("WLS" or "GSM").
riskThe risk parameter used in the GS method (if applicable).
familyThe spatial dependence family ("power_stat" or "power_nonstat").
dtypeThe data type used in TensorFlow computations.
nlayersNumber of warping layers (for non-stationary models).
weight_funThe weighting function used in the GS method.
dWeight_funThe derivative of the weighting function used in the GS method.
fThe model formula.
dataThe data frame used for model fitting.
negcostVector of cost values recorded during training.
pairs_tfTensorFlow variable representing the spatial location pairs (and, for MRPL, the replicate indices) used in the pairwise / randomized pairwise likelihood or WLS objective..
pairs_t_tfTranposed pairs_tf.
timeElapsed time for model fitting.
Constructs a deep trivariate compositional spatial model
deepspat_trivar_GP( f, data, g = ~1, layers_asym_2 = NULL, layers_asym_3 = NULL, layers = NULL, method = c("REML"), family = c("matern_stat_symm", "matern_stat_asymm", "matern_nonstat_symm", "matern_nonstat_asymm"), par_init = initvars(), learn_rates = init_learn_rates(), nsteps = 150L )deepspat_trivar_GP( f, data, g = ~1, layers_asym_2 = NULL, layers_asym_3 = NULL, layers = NULL, method = c("REML"), family = c("matern_stat_symm", "matern_stat_asymm", "matern_nonstat_symm", "matern_nonstat_asymm"), par_init = initvars(), learn_rates = init_learn_rates(), nsteps = 150L )
f |
formula identifying the dependent variables and the spatial inputs in the covariance |
data |
data frame containing the required data |
g |
formula identifying the independent variables in the linear trend |
layers_asym_2 |
list containing the aligning function layers for the second process |
layers_asym_3 |
list containing the aligning function layers for the third process |
layers |
list containing the nonstationary warping layers |
method |
identifying the method for finding the estimates |
family |
identifying the family of the model constructed |
par_init |
list of initial parameter values. Call the function |
learn_rates |
learning rates for the various quantities in the model. Call the function |
nsteps |
number of steps when doing gradient descent times two, three or five (depending on the family of model) |
deepspat_trivar_GP returns an object of class deepspat_trivar_GP with the following items
The formula used to construct the covariance model
The formula used to construct the linear trend model
The data used to construct the deepspat model
The model matrix of the linear trend
The warping function layers in the model
The aligning function layers for the second process in the model
The aligning function layers for the third process in the model
The final value of the cost
Estimated weights in the warping layers as a list of TensorFlow objects
Estimated weights in the aligning layers for the second process as a list of TensorFlow objects
Estimated weights in the aligning layers for the third process as a list of TensorFlow objects
Estimated coefficients of the linear trend
Precision of measurement error of the first process, as a TensorFlow object
Precision of measurement error of the second process, as a TensorFlow object
Precision of measurement error of the third process, as a TensorFlow object
Variance parameter (first process) in the covariance matrix, as a TensorFlow object
Variance parameter (second process) in the covariance matrix, as a TensorFlow object
Variance parameter (third process) in the covariance matrix, as a TensorFlow object
Covariance parameter (between first and second process) in the covariance matrix, as a TensorFlow object
Covariance parameter (between first and third process) in the covariance matrix, as a TensorFlow object
Covariance parameter (between second and third process) in the covariance matrix, as a TensorFlow object
Length scale parameter (first process) in the covariance matrix, as a TensorFlow object
Length scale parameter (second process) in the covariance matrix, as a TensorFlow object
Length scale parameter (third process) in the covariance matrix, as a TensorFlow object
Length scale parameter (cross-covariance between first and second process) in the covariance matrix, as a TensorFlow object
Length scale parameter (cross-covariance between first and third process) in the covariance matrix, as a TensorFlow object
Length scale parameter (cross-covariance between second and third process) in the covariance matrix, as a TensorFlow object
Smoothness parameter (first process) in the covariance matrix, as a TensorFlow object
Smoothness parameter (second process) in the covariance matrix, as a TensorFlow object
Smoothness parameter (third process) in the covariance matrix, as a TensorFlow object
Smoothness parameter (cross-covariance between first and second process) in the covariance matrix, as a TensorFlow object
Smoothness parameter (cross-covariance between first and third process) in the covariance matrix, as a TensorFlow object
Smoothness parameter (cross-covariance between second and third process) in the covariance matrix, as a TensorFlow object
Minima and maxima used to scale the unscaled unit outputs for each warping layer, as a list of TensorFlow objects
Minima and maxima used to scale the unscaled unit outputs for each aligning layer, as a list of TensorFlow objects
Method used for inference
Number of warping layers in the model
Number of aligning layers in the model
TensorFlow session for evaluating the TensorFlow objects
Spatial locations of the first process on the warped domain
Spatial locations of the second process on the warped domain
Spatial locations of the third process on the warped domain
Vector of costs after each gradient-descent evaluation
Data of the first process
Data of the second process
Data of the third process
Family of the model
Provides utility to alter the learning rates when fitting a deepspat model
init_learn_rates( sigma2y = 5e-04, covfun = 0.01, sigma2eta = 1e-04, eta_mean = 0.1, eta_mean2 = 0.1, eta_sd = 0.1, LFTpars = 0.01, AFFpars = 0.01, rho = 0.1, vario = 0.1 )init_learn_rates( sigma2y = 5e-04, covfun = 0.01, sigma2eta = 1e-04, eta_mean = 0.1, eta_mean2 = 0.1, eta_sd = 0.1, LFTpars = 0.01, AFFpars = 0.01, rho = 0.1, vario = 0.1 )
sigma2y |
learning rate for the measurement-error variance |
covfun |
learning rate for the covariance-function (or matrix) parameters at the top layer |
sigma2eta |
learning rate for the process variance |
eta_mean |
learning rate for the weight estimates or variational means |
eta_mean2 |
learning rate for the weight estimates or variational means |
eta_sd |
learning rate for the variational standard deviations (SDSP only) |
LFTpars |
learning rate for the parameters of the Mobius transformation |
AFFpars |
learning rate for the parameters of the affine transformation |
rho |
learning rate for the correlation parameter in the multivariate model |
vario |
learning rate for the parameter in the variogram |
init_learn_rates returns a list with the learning rates. Call str(init_learn_rates()) to see the
structure of this list.
Provides utility to alter the initial weights and parameters when fitting a deepspat model
initvars( sigma2y = 0.1, l_top_layer = 0.5, sigma2eta_top_layer = 1, nu = 1.5, variogram_logrange = log(0.3), variogram_logitdf = 0.5, transeta_mean_init = list(AWU = -3, RBF = -0.8068528, RBF1 = -0.8068528, RBF2 = -0.8068528, LFT = 1, AFF_1D = 1, AFF_2D = 1), transeta_mean_prior = list(AWU = -3, RBF = -0.8068528, RBF1 = -0.8068528, RBF2 = -0.8068528, LFT = NA), transeta_sd_init = list(AWU = 0.01, RBF = 0.01, RBF1 = 0.01, RBF2 = 0.01, LFT = 0.01), transeta_sd_prior = list(AWU = 2, RBF = 2, RBF1 = 2, RBF2 = 0.01, LFT = NA) )initvars( sigma2y = 0.1, l_top_layer = 0.5, sigma2eta_top_layer = 1, nu = 1.5, variogram_logrange = log(0.3), variogram_logitdf = 0.5, transeta_mean_init = list(AWU = -3, RBF = -0.8068528, RBF1 = -0.8068528, RBF2 = -0.8068528, LFT = 1, AFF_1D = 1, AFF_2D = 1), transeta_mean_prior = list(AWU = -3, RBF = -0.8068528, RBF1 = -0.8068528, RBF2 = -0.8068528, LFT = NA), transeta_sd_init = list(AWU = 0.01, RBF = 0.01, RBF1 = 0.01, RBF2 = 0.01, LFT = 0.01), transeta_sd_prior = list(AWU = 2, RBF = 2, RBF1 = 2, RBF2 = 0.01, LFT = NA) )
sigma2y |
initial value for the measurement-error variance |
l_top_layer |
initial value for the length scale at the top layer |
sigma2eta_top_layer |
initial value for the variance of the weights at the top layer |
nu |
initial value for the smoothness parameter |
variogram_logrange |
initial value for variogram_logrange |
variogram_logitdf |
initial value for variogram_logitdf |
transeta_mean_init |
list of initial values for the initial weights (or the initial variational means of these weights). The list contains five values, one for the AWU, one for the RBF, one for the LFT (Mobius), and two for the affine transformation |
transeta_mean_prior |
same as |
transeta_sd_init |
same as |
transeta_sd_prior |
same as |
initvars returns a list with the initial values. Call str(initvars()) to see the structure of this list.
Sets up a Möbius transformation unit
LFT(a = NULL, dtype = "float32")LFT(a = NULL, dtype = "float32")
a |
vector of four complex numbers describing the Möbius transformation |
dtype |
data type |
LFT returns a list containing a list with the following components:
An encapsulated function that takes an input and evaluates the Möbius transformation using TensorFlow
Same as f but uses R
Same as f but does it in parallel for several inputs index by the first dimension of the tensor
The number of basis functions (fixed to 1 in this case)
The transformation applied to the weights before estimation (in this case the identity)
Flag indicating whether the weights are fixed or not (TRUE for LFTs)
Name of layer
List of parameters describing the Möbius transformation as TensorFlow objects
if (reticulate::py_module_available("tensorflow")) { layer <- LFT() }if (reticulate::py_module_available("tensorflow")) { layer <- LFT() }
Prediction function for the fitted deepspat object
## S3 method for class 'deepspat' predict(object, newdata, nsims = 100L, ...)## S3 method for class 'deepspat' predict(object, newdata, nsims = 100L, ...)
object |
the deepspat object |
newdata |
data frame containing the prediction locations |
nsims |
number of simulations from the Gaussian mixture components (SDSP only) |
... |
currently unused |
predict.deepspat returns a list with the two following items
Data frame containing the predictions/prediction intervals at the prediction locations
Combined simulations from the Gaussian mixtures (SDSP only)
Prediction function for the fitted deepspat_bivar_GP object
## S3 method for class 'deepspat_bivar_GP' predict(object, newdata, ...)## S3 method for class 'deepspat_bivar_GP' predict(object, newdata, ...)
object |
the deepspat_bivar_GP object |
newdata |
data frame containing the prediction locations |
... |
currently unused |
predict.deepspat_bivar_GP returns a list with the following item
Data frame containing the predictions/prediction intervals at the prediction locations
Observation locations on the warped domain (for the first process)
Observation locations on the warped domain (for the second process)
New prediction locations on the warped domain (for the first process)
New prediction locations on the warped domain (for the second process)
Prediction function for the fitted deepspat_GP object
## S3 method for class 'deepspat_GP' predict(object, newdata, ...)## S3 method for class 'deepspat_GP' predict(object, newdata, ...)
object |
the deepspat_GP object |
newdata |
data frame containing the prediction locations |
... |
currently unused |
predict.deepspat_GP returns a list with the following item
Data frame containing the predictions/prediction intervals at the prediction locations
Observation locations on the warped domain
New prediction locations on the warped domain
Prediction function for the fitted deepspat_nn_GP object
## S3 method for class 'deepspat_nn_GP' predict(object, newdata, nn_id, ...)## S3 method for class 'deepspat_nn_GP' predict(object, newdata, nn_id, ...)
object |
the deepspat_nn_GP object |
newdata |
data frame containing the prediction locations |
nn_id |
nearest neighbors index |
... |
currently unused |
predict.deepspat_nn_GP returns a list with the following item
Data frame containing the predictions/prediction intervals at the prediction locations
Observation locations on the warped domain
New prediction locations on the warped domain
Prediction function for the fitted deepspat_nn_ST_GP object
## S3 method for class 'deepspat_nn_ST_GP' predict(object, newdata, nn_id, ...)## S3 method for class 'deepspat_nn_ST_GP' predict(object, newdata, nn_id, ...)
object |
the deepspat_nn_ST_GP object |
newdata |
data frame containing the prediction locations |
nn_id |
nearest neighbors index |
... |
currently unused |
predict.deepspat_nn_ST_GP returns a list with the following item
Data frame containing the predictions/prediction intervals at the prediction locations
Observation locations on the spatial warped domain
Observation locations on the temporal warped domain
New prediction locations on the spatial warped domain
New prediction locations on the temporal warped domain
Prediction function for the fitted deepspat_trivar_GP object
## S3 method for class 'deepspat_trivar_GP' predict(object, newdata, ...)## S3 method for class 'deepspat_trivar_GP' predict(object, newdata, ...)
object |
the deepspat_trivar_GP object |
newdata |
data frame containing the prediction locations |
... |
currently unused |
predict.deepspat_trivar_GP returns a list with the following item
Data frame containing the predictions/prediction intervals at the prediction locations
Sets up a composition of radial basis functions (RBFs) for used in a deep compositional spatial model. The function sets up RBFs on a prescribed domain on a grid at a certain resolution. It returns a list containing all the functions in the single-resolution RBF unit. See Value for more details.
RBF_block(res = 1L, lims = c(-0.5, 0.5), dtype = "float32")RBF_block(res = 1L, lims = c(-0.5, 0.5), dtype = "float32")
res |
the resolution |
lims |
the limits of one side of the square 2D domain on which to set up the RBFs |
dtype |
data type |
RBF_block returns a list containing a list for each RBF in the block with the following components:
An encapsulated function that takes an input and evaluates the RBF over some input using TensorFlow
Same as f but uses R
Same as f but does it in parallel for several inputs index by the first dimension of the tensor
The number of basis functions (one for each layer)
The transformation applied to the weights before estimation
Flag indicating whether the weights are fixed or not (FALSE for RBFs)
Name of layer
if (reticulate::py_module_available("tensorflow")) { layer <- RBF_block(res = 1L) }if (reticulate::py_module_available("tensorflow")) { layer <- RBF_block(res = 1L) }
Set TensorFlow seed in deepspat package
set_deepspat_seed(seed = 1L)set_deepspat_seed(seed = 1L)
seed |
the seed |
No return value, called for side effects.
if (reticulate::py_module_available("tensorflow")) { set_deepspat_seed(seed = 1L) }if (reticulate::py_module_available("tensorflow")) { set_deepspat_seed(seed = 1L) }
Generates simulated data for use in experiments
sim_data(type = "step1D", ds = 0.001, n = 300L, sigma2y = NULL)sim_data(type = "step1D", ds = 0.001, n = 300L, sigma2y = NULL)
type |
type of function. Can be 'step1D', 'Monterrubio1D', 'dampedwave1D', 'step2D', 'AWU_RBF_2D', or 'AWU_RBF_LFT_2D' |
ds |
spatial grid length |
n |
number of data points |
sigma2y |
measurement-error variance |
sim_data returns a list containing the following items:
Process locations on a fine grid with spacing ds
Observation locations
The warping function (when this is also simulated)
The true process on the fine grid
The simulated observation data
if (reticulate::py_module_available("tensorflow")) { sim <- sim_data(type = "step1D", ds = 0.001) }if (reticulate::py_module_available("tensorflow")) { sim <- sim_data(type = "step1D", ds = 0.001) }
Prediction function for the fitted deepspat_ext object
## S3 method for class 'deepspat_MSP' summary(object, newdata, uncAss = TRUE, edm_emp = NULL, ...)## S3 method for class 'deepspat_MSP' summary(object, newdata, uncAss = TRUE, edm_emp = NULL, ...)
object |
a deepspat object obtained from fitting a deep compositional spatial model for extremes using max-stable processes. |
newdata |
a data frame containing the prediction locations. |
uncAss |
assess the uncertainty of dependence parameters or not |
edm_emp |
empirical estimates of extremal dependence measure for weighted least square inference method |
... |
currently unused |
A list with the following components:
A matrix of rescaled spatial coordinates produced by scaling the input locations.
A matrix of warped spatial coordinates. For family = "power_stat" this equals srescaled, while for family = "power_nonstat"
the coordinates are further transformed through additional layers.
A numeric value representing the fitted spatial range parameter, computed as exp(logphi_tf).
A numeric value representing the fitted smoothness parameter, computed as 2 * sigmoid(logitkappa_tf).
A numeric matrix giving the estimated covariance matrix of the
dependence parameters , computed via the
pairwise likelihood / WLS sandwich-type estimator. NULL if
uncAss = FALSE.
Prediction function for the fitted deepspat_ext object
## S3 method for class 'deepspat_rPP' summary(object, newdata, uncAss = TRUE, edm_emp = NULL, uprime = NULL, ...)## S3 method for class 'deepspat_rPP' summary(object, newdata, uncAss = TRUE, edm_emp = NULL, uprime = NULL, ...)
object |
a deepspat object obtained from fitting a deep compositional spatial model for extremes using r-Pareto processes. |
newdata |
a data frame containing the prediction locations. |
uncAss |
assess the uncertainty of dependence parameters or not |
edm_emp |
empirical estimates of extremal dependence measure for weighted least square inference method |
uprime |
uprime for weighted least square inference method |
... |
currently unused. |
A list with the following components:
A matrix of rescaled spatial coordinates produced by scaling the input locations.
A matrix of warped spatial coordinates. For family = "power_stat" this equals srescaled, while for family = "power_nonstat"
the coordinates are further transformed through additional layers.
A numeric value representing the fitted spatial range parameter, computed as exp(logphi_tf).
A numeric value representing the fitted smoothness parameter, computed as 2 * sigmoid(logitkappa_tf).
A numeric matrix giving the estimated covariance matrix of the
dependence parameters , computed via the
pairwise likelihood / WLS sandwich-type estimator. NULL if
uncAss = FALSE.