=
The futurize package allows you to easily turn sequential code
into parallel code by piping the sequential code to the futurize()
function. Easy!
library(futurize)
plan(multisession)
library(DiceKriging)
design <- expand.grid(x1 = seq(0, 1, length = 15), x2 = seq(0, 1, length = 15))
y <- apply(design, 1, function(x) x[1]^2 + x[2]^2)
m <- km(~., design = design, response = data.frame(y = y),
multistart = 20) |> futurize()
This vignette demonstrates how to use futurize to parallelize
DiceKriging functions, specifically km().
When fitting a kriging model via km(), the parameters of the
covariance function are estimated by maximum likelihood or
cross-validation. The optimization can be started from multiple
points (to avoid local optima), which can be done in parallel.
Fitting a kriging model with a single starting point:
library(DiceKriging)
design <- expand.grid(x1 = seq(0, 1, length = 15), x2 = seq(0, 1, length = 15))
y <- apply(design, MARGIN = 1, FUN = function(x) x[1]^2 + x[2]^2)
m <- km(~., design = design, response = data.frame(y = y))
To run multiple optimizer starts in parallel, set multistart > 1
and pipe to futurize():
library(futurize)
library(DiceKriging)
design <- expand.grid(x1 = seq(0, 1, length = 15), x2 = seq(0, 1, length = 15))
y <- apply(design, MARGIN = 1, FUN = function(x) x[1]^2 + x[2]^2)
m <- km(~., design = design, response = data.frame(y = y),
multistart = 20) |> futurize()
This distributes the multi-start runs across the available parallel workers, given that we have set up a parallel plan, e.g.
plan(multisession)
The built-in multisession backend parallelizes on your local
computer and works on all operating systems. There are other
parallel backends to choose from, including alternatives to
parallelize locally as well as distributed across remote machines,
e.g.
plan(future.mirai::mirai_multisession)
and
plan(future.batchtools::batchtools_slurm)
The following DiceKriging function is supported by futurize():
km()Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.