# R/4_prediction_S.R In funGp: Gaussian Process Models for Scalar and Functional Inputs

#### Defines functions preMats_SmakePreds_S

```#' @author José Betancourt, François Bachoc, Thierry Klein and Jérémy Rohmer
makePreds_S <- function(sMs.tp, sMs.pp, sig2, thetas_s, kerType, L, LInvY, detail, nugget){
# create empty prediction list
preds <- list()

# compute and store conditional mean and standard deviation
K.tp <- sig2 * setR(thetas_s, sMs.tp, kerType)
LInvK <- backsolve(L, K.tp, upper.tri = FALSE)
preds\$mean <- t(LInvK) %*% LInvY
preds\$sd <- sqrt(pmax(sig2 - apply(LInvK, 2, crossprod), 0))

# if user requires details, provide K.tp and K.pp
if (detail == "full") {
preds\$K.tp <- K.tp
R <- setR(thetas_s, sMs.pp, kerType)
preds\$K.pp <- sig2 * (R + diag(nugget, nrow = nrow(R), ncol = ncol(R)))
}

return(preds)
}

#' @author José Betancourt, François Bachoc, Thierry Klein and Jérémy Rohmer
preMats_S <- function(sMs, sOut, sig2, thetas_s, kerType, nugget){
# precompute L and LInvY matrices
R <- setR(thetas_s, sMs, kerType)
K.tt <- sig2 * (R + diag(nugget, nrow = nrow(R), ncol = ncol(R)))
L <- t(chol(K.tt))
LInvY <- backsolve(L, sOut, upper.tri = FALSE)

return(list(L = L, LInvY = LInvY))
}
```

## Try the funGp package in your browser

Any scripts or data that you put into this service are public.

funGp documentation built on May 29, 2024, 8 a.m.