lgp | R Documentation |
This function constructs a linked (D)GP emulator for a model chain or network.
lgp(struc, emulators = NULL, B = 10, activate = TRUE, verb = TRUE, id = NULL)
See further examples and tutorials at https://mingdeyu.github.io/dgpsi-R/.
An S3 class named lgp
that contains three slots:
id
: A number or character string assigned through the id
argument.
constructor_obj
: a list of 'python' objects that stores the information of the constructed linked emulator.
emulator_obj
, a 'python' object that stores the information for predictions from the linked emulator.
specs
: a list that contains
seed
: the random seed generated to produce the imputations. This information is stored for reproducibility
when the linked (D)GP emulator (that was saved by write()
with the light option light = TRUE
) is loaded back
to R by read()
.
B
: the number of imputations used to generate the linked (D)GP emulator.
If
struc
is a data frame, specs
also includes:
metadata
: a data frame providing configuration details for each emulator in the linked system, with following columns:
Emulator
: the ID of an emulator.
Layer
: the layer in the linked system where the emulator is positioned. A lower Layer
number indicates
a position closer to the input, with layer numbering increasing as you move away from the input.
Pos_in_Layer
: the position of the emulator within its layer. A lower Pos_in_Layer
number
indicates a position higher up in that layer.
Total_Input_Dims
: the total number of input dimensions of the emulator.
Total_Output_Dims
: the total number of output dimensions of the emulator.
struc
: The linked system structure, as supplied by struc
.
The returned lgp
object can be used by
predict()
for linked (D)GP predictions.
validate()
for OOS validation.
plot()
for validation plots.
summary()
to summarize the constructed linked (D)GP emulator.
write()
to save the linked (D)GP emulator to a .pkl
file.
## Not run:
# load the package and the Python env
library(dgpsi)
# model 1
f1 <- function(x) {
(sin(7.5*x)+1)/2
}
# model 2
f2 <- function(x) {
2/3*sin(2*(2*x - 1))+4/3*exp(-30*(2*(2*x-1))^2)-1/3
}
# linked model
f12 <- function(x) {
f2(f1(x))
}
# training data for Model 1
X1 <- seq(0, 1, length = 9)
Y1 <- sapply(X1, f1)
# training data for Model 2
X2 <- seq(0, 1, length = 13)
Y2 <- sapply(X2, f2)
# emulation of model 1
m1 <- gp(X1, Y1, name = "matern2.5", id = "emulator1")
# emulation of model 2
m2 <- dgp(X2, Y2, depth = 2, name = "matern2.5", id = "emulator2")
struc <- data.frame(From_Emulator = c("Global", "emulator1"),
To_Emulator = c("emulator1", "emulator2"),
From_Output = c(1, 1),
To_Input = c(1, 1))
emulators <- list(m1, m2)
# construct the linked emulator for visual inspection
m_link <- lgp(struc, emulators, activate = FALSE)
# visual inspection
summary(m_link)
# build the linked emulator for prediction
m_link <- lgp(struc, emulators, activate = TRUE)
test_x <- seq(0, 1, length = 300)
m_link <- predict(m_link, x = test_x)
# OOS validation
validate_x <- sample(test_x, 20)
validate_y <- sapply(validate_x, f12)
plot(m_link, validate_x, validate_y, style = 2)
# write and read the constructed linked emulator
write(m_link, 'linked_emulator')
m_link <- read('linked_emulator')
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.