Title: | Draw Samples of Truncated Multivariate Normal Distributions |
---|---|
Description: | Draw samples from truncated multivariate normal distribution using the sequential nearest neighbor (SNN) method introduced in "Scalable Sampling of Truncated Multivariate Normals Using Sequential Nearest-Neighbor Approximation" <doi:10.48550/arXiv.2406.17307>. |
Authors: | Jian Cao [aut, cre], Matthias Katzfuss [aut] |
Maintainer: | Jian Cao <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.0 |
Built: | 2024-10-26 04:25:30 UTC |
Source: | https://github.com/jcatwood/nntmvn |
Simulate the underlying GP responses for censored responses using nearest neighbors
rtmvn_snn( y, cens_lb, cens_ub, mask_cens, NN, locs, cov_name, cov_parm, covmat = NULL, seed = NULL )
rtmvn_snn( y, cens_lb, cens_ub, mask_cens, NN, locs, cov_name, cov_parm, covmat = NULL, seed = NULL )
y |
uncensored responses of length n, where n is the number of all responses |
cens_lb |
lower bound vector for TMVN of length n |
cens_ub |
upper bound vector for TMVN of length n |
mask_cens |
mask for censored responses (also locations) of length n |
NN |
n X m matrix for nearest neighbors. i-th row is the nearest neighbor indices of y_i. |
locs |
location matrix n X d |
cov_name |
covariance function name from the |
cov_parm |
parameters for the covariance function from the |
covmat |
(optional) n-by-n dense covariance matrix, not needed if |
seed |
set seed for reproducibility |
a vector of length n representing the underlying GP responses
library(GpGp) library(RANN) library(nntmvn) set.seed(123) x <- matrix(seq(from = 0, to = 1, length.out = 51), ncol = 1) cov_name <- "matern15_isotropic" cov_parm <- c(1.0, 0.1, 0.001) # variance, range, nugget cov_func <- getFromNamespace(cov_name, "GpGp") covmat <- cov_func(cov_parm, x) y <- t(chol(covmat)) %*% rnorm(length(x)) mask <- y < 0.3 y_cens <- y y_cens[mask] <- NA lb <- rep(-Inf, 100) ub <- rep(0.3, 100) m <- 10 NN <- RANN::nn2(x, k = m + 1)[[1]] y_samp <- rtmvn_snn(y_cens, lb, ub, mask, NN, x, cov_name, cov_parm) plot(x, y_cens, ylim = range(y)) points(x[mask, ], y[mask], col = "blue") plot(x, y_cens, ylim = range(y)) points(x[mask, ], y_samp[mask], col = "red")
library(GpGp) library(RANN) library(nntmvn) set.seed(123) x <- matrix(seq(from = 0, to = 1, length.out = 51), ncol = 1) cov_name <- "matern15_isotropic" cov_parm <- c(1.0, 0.1, 0.001) # variance, range, nugget cov_func <- getFromNamespace(cov_name, "GpGp") covmat <- cov_func(cov_parm, x) y <- t(chol(covmat)) %*% rnorm(length(x)) mask <- y < 0.3 y_cens <- y y_cens[mask] <- NA lb <- rep(-Inf, 100) ub <- rep(0.3, 100) m <- 10 NN <- RANN::nn2(x, k = m + 1)[[1]] y_samp <- rtmvn_snn(y_cens, lb, ub, mask, NN, x, cov_name, cov_parm) plot(x, y_cens, ylim = range(y)) points(x[mask, ], y[mask], col = "blue") plot(x, y_cens, ylim = range(y)) points(x[mask, ], y_samp[mask], col = "red")