Skip to content

Commit 9b4c605

Browse files
committed
Update lgp.R
fix bugs to retain reproducibility
1 parent b6c041f commit 9b4c605

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

R/lgp.R

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ lgp <- function(struc, B = 10, id = NULL) {
9797
layer <- list()
9898
K <- length(struc[[l]])
9999
for (k in 1:K) {
100-
cont <- pkg.env$copy$deepcopy(struc[[l]][[k]]$container_obj)
100+
cont <- 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
}
104104
if ( l==1 ){
105105
if (cont$type=='gp'){
106106
if ( !is.null(cont$structure$connect) ){
107+
cont <- pkg.env$copy$deepcopy(cont)
107108
inverse_order <- order(c(cont$structure$input_dim, cont$structure$connect) + 1)
108109
cont$structure$input <- cbind(cont$structure$input, cont$structure$global_input)[,inverse_order,drop=F]
109110
cont$structure$global_input <- NULL
@@ -112,14 +113,24 @@ lgp <- function(struc, B = 10, id = NULL) {
112113
if (length(cont$structure$length)!=1) cont$structure$length <- cont$structure$length[inverse_order]
113114
}
114115
} else {
116+
exist.connect <- FALSE
115117
for (item in cont$structure[[1]]){
116118
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]
119+
exist.connect <- TRUE
120+
break
121+
}
122+
}
123+
if ( exist.connect ){
124+
cont <- pkg.env$copy$deepcopy(cont)
125+
for (item in cont$structure[[1]]){
126+
if ( !is.null(item$connect) ){
127+
inverse_order <- order(c(item$input_dim, item$connect) + 1)
128+
item$input <- cbind(item$input, item$global_input)[,inverse_order,drop=F]
129+
item$global_input <- NULL
130+
item$input_dim <- (1:length(inverse_order))-1
131+
item$connect <- NULL
132+
if (length(item$length)!=1) item$length <- item$length[inverse_order]
133+
}
123134
}
124135
}
125136
}
@@ -132,7 +143,7 @@ lgp <- function(struc, B = 10, id = NULL) {
132143
res[['id']] <- if (is.null(id)) uuid::UUIDgenerate() else id
133144
seed <- sample.int(100000, 1)
134145
set_seed(seed)
135-
obj <- pkg.env$dgpsi$lgp(all_layer = extracted_struc, N = B)
146+
obj <- pkg.env$dgpsi$lgp(all_layer = pkg.env$copy$deepcopy(extracted_struc), N = B)
136147
res[['emulator_obj']] <- obj
137148
res[['specs']][['seed']] <- seed
138149
res[['specs']][['B']] <- B

0 commit comments

Comments
 (0)