Skip to content

Commit ad55535

Browse files
committed
Update prediction.R
1 parent 77ec69b commit ad55535

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

R/prediction.R

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,21 @@ predict.tsissm.selection <- function(object, h = 12, newxreg = NULL, nsim = 1000
341341
# sample correlated quantiles from a copula
342342
cop <- normalCopula(P2p(C), dim = NCOL(C), dispstr = "un")
343343
U <- rCopula(h * nsim, cop)
344-
out <- future_lapply(1:length(object$models), function(i){
345-
r <- matrix(U[,i], nrow = nsim, ncol = h)
346-
predict(object$models[[i]], h = h, newxreg = newxreg, nsim = nsim, forc_dates = forc_dates, innov = r, innov_type = "q",
347-
init_states = init_states, ...)
348-
}, future.seed = TRUE, future.packages = c("tsissm","xts"))
349-
out <- eval(out)
344+
n_cores <- nbrOfWorkers()
345+
if (n_cores <= 1) {
346+
out <- lapply(1:length(object$models), function(i){
347+
r <- matrix(U[,i], nrow = nsim, ncol = h)
348+
predict(object$models[[i]], h = h, newxreg = newxreg, nsim = nsim, forc_dates = forc_dates, innov = r, innov_type = "q",
349+
init_states = init_states, ...)
350+
})
351+
} else {
352+
out <- future_lapply(1:length(object$models), function(i){
353+
r <- matrix(U[,i], nrow = nsim, ncol = h)
354+
predict(object$models[[i]], h = h, newxreg = newxreg, nsim = nsim, forc_dates = forc_dates, innov = r, innov_type = "q",
355+
init_states = init_states, ...)
356+
}, future.seed = TRUE, future.packages = c("tsissm","xts"))
357+
out <- eval(out)
358+
}
350359
L <- list(models = out, table = object$table, correlation = object$correlation)
351360
class(L) <- c("tsissm.selection_predict")
352361
return(L)

0 commit comments

Comments
 (0)