Skip to content

Commit b6c041f

Browse files
committed
Update of lgp()
The lgp() function now can connect the same emulator in a chain with different linking information specified by set_linked_idx().
1 parent 48504dd commit b6c041f

6 files changed

Lines changed: 46 additions & 14 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- The `check_point` argument is removed from `design()` and replaced by `autosave`.
1818
- Automatic saving of emulators during the sequential design is added to `design()` through the new argument `autosave`.
1919
- When a customized evaluation function is provided to `design()` via `eval`, the design information in previous waves will be retained as long as the previous waves of the sequential design also use customized evaluation functions. If different customized evaluation functions are supplied to `design()` in different waves, the trace plot of RMSEs produced by `draw()` will show RMSEs from different evaluation functions in different waves.
20+
- One can now link the same emulator multiple times in a chain via `lgp()` by setting different linking information for the emulator via `set_linked_idx()`.
2021
- Updates of documentations and vignettes.
2122

2223
# dgpsi 2.3.0

R/dgp.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@
110110
#' generated by the linked emulators in the preceding layers. Defaults to `NULL`. This argument is only used when `struc = NULL`.
111111
#' @param linked_idx either a vector or a list of vectors:
112112
#' * If `linked_idx` is a vector, it gives indices of columns in the pooled output matrix (formed by column-combined outputs of all
113-
#' emulators in the feeding layer) that feed into the DGP emulator. If the DGP emulator is in the first layer of a linked emulator system,
114-
#' the vector gives the column indices of the global input (formed by column-combining all input matrices of emulators in the first layer)
115-
#' that the DGP emulator will use. The length of the vector shall equal to the length of `internal_input_idx` when `internal_input_idx` is not `NULL`.
113+
#' emulators in the feeding layer) that feed into the DGP emulator. The length of the vector shall equal to the length of `internal_input_idx`
114+
#' when `internal_input_idx` is not `NULL`. If the DGP emulator is in the first layer of a linked emulator system, the vector gives the column indices of the global
115+
#' input (formed by column-combining all input matrices of emulators in the first layer) that the DGP emulator will use. If the DGP emulator is to be used in both the first
116+
#' and subsequent layers, one should initially set `linked_idx` to the appropriate values for the situation where the emulator is not in the first layer. Then, use the
117+
#' function [set_linked_idx()] to reset the linking information when the emulator is in the first layer.
116118
#' * When the DGP emulator is not in the first layer of a linked emulator system, `linked_idx` can be a list that gives the information on connections
117119
#' between the DGP emulator and emulators in all preceding layers. The length of the list should equal to the number of layers before
118120
#' the DGP emulator. Each element of the list is a vector that gives indices of columns in the pooled output matrix (formed by column-combined outputs

R/gp.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@
4747
#' generated by the linked emulators in the preceding layers. Defaults to `NULL`. This argument is only used when `struc = NULL`.
4848
#' @param linked_idx either a vector or a list of vectors:
4949
#' * If `linked_idx` is a vector, it gives indices of columns in the pooled output matrix (formed by column-combined outputs of all
50-
#' emulators in the feeding layer) that feed into the GP emulator. If the GP emulator is in the first layer of a linked emulator system,
51-
#' the vector gives the column indices of the global input (formed by column-combining all input matrices of emulators in the first layer)
52-
#' that the GP emulator will use. The length of the vector shall equal to the length of `internal_input_idx` when `internal_input_idx` is not `NULL`.
50+
#' emulators in the feeding layer) that feed into the GP emulator. The length of the vector shall equal to the length of `internal_input_idx` when `internal_input_idx`
51+
#' is not `NULL`. If the GP emulator is in the first layer of a linked emulator system, the vector gives the column indices of the global
52+
#' input (formed by column-combining all input matrices of emulators in the first layer) that the GP emulator will use. If the GP emulator is to be used in both the first
53+
#' and subsequent layers, one should initially set `linked_idx` to the appropriate values for the situation where the emulator is not in the first layer. Then, use the
54+
#' function [set_linked_idx()] to reset the linking information when the emulator is in the first layer.
5355
#' * When the GP emulator is not in the first layer of a linked emulator system, `linked_idx` can be a list that gives the information on connections
5456
#' between the GP emulator and emulators in all preceding layers. The length of the list should equal to the number of layers before
5557
#' the GP emulator. Each element of the list is a vector that gives indices of columns in the pooled output matrix (formed by column-combined outputs

R/lgp.R

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,33 @@ lgp <- function(struc, B = 10, id = NULL) {
9797
layer <- list()
9898
K <- length(struc[[l]])
9999
for (k in 1:K) {
100-
cont <- struc[[l]][[k]]$container_obj
100+
cont <- pkg.env$copy$deepcopy(struc[[l]][[k]]$container_obj)
101101
if ( is.null(cont$local_input_idx) ){
102102
stop(sprintf("Emulator %i in Layer %i has no 'linked_idx' specified. Use set_linked_idx() to specify this attribute.", k, l), call. = FALSE)
103103
}
104+
if ( l==1 ){
105+
if (cont$type=='gp'){
106+
if ( !is.null(cont$structure$connect) ){
107+
inverse_order <- order(c(cont$structure$input_dim, cont$structure$connect) + 1)
108+
cont$structure$input <- cbind(cont$structure$input, cont$structure$global_input)[,inverse_order,drop=F]
109+
cont$structure$global_input <- NULL
110+
cont$structure$input_dim <- (1:length(inverse_order))-1
111+
cont$structure$connect <- NULL
112+
if (length(cont$structure$length)!=1) cont$structure$length <- cont$structure$length[inverse_order]
113+
}
114+
} else {
115+
for (item in cont$structure[[1]]){
116+
if ( !is.null(item$connect) ){
117+
inverse_order <- order(c(item$input_dim, item$connect) + 1)
118+
item$input <- cbind(item$input, item$global_input)[,inverse_order,drop=F]
119+
item$global_input <- NULL
120+
item$input_dim <- (1:length(inverse_order))-1
121+
item$connect <- NULL
122+
if (length(item$length)!=1) item$length <- item$length[inverse_order]
123+
}
124+
}
125+
}
126+
}
104127
layer[[k]] <- cont
105128
}
106129
extracted_struc[[l]] <- layer
@@ -109,7 +132,7 @@ lgp <- function(struc, B = 10, id = NULL) {
109132
res[['id']] <- if (is.null(id)) uuid::UUIDgenerate() else id
110133
seed <- sample.int(100000, 1)
111134
set_seed(seed)
112-
obj <- pkg.env$dgpsi$lgp(all_layer = pkg.env$copy$deepcopy(extracted_struc), N = B)
135+
obj <- pkg.env$dgpsi$lgp(all_layer = extracted_struc, N = B)
113136
res[['emulator_obj']] <- obj
114137
res[['specs']][['seed']] <- seed
115138
res[['specs']][['B']] <- B

man/dgp.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/gp.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)