SPJDEoptim: Simple Parallel Version of 'JDEoptim()'

View source: R/SPJDEoptim.R

SPJDEoptimR Documentation

Simple Parallel Version of JDEoptim()

Description

Parallel evaluation of the objective function and/or constraints for each candidate solution in the population.

Usage

SPJDEoptim(lower, upper, fn,
           constr = NULL, meq = 0, eps = 1e-5,
           sequential_eval = c("none", "constraints",
                               "objective", "both"),
           ..., further_args = list(),
           NP = 10*length(lower),
           Fl = 0.1, Fu = 1, CRl = 0, CRu = 1.1,
           tau_F = 0.1, tau_CR = 0.1, tau_pF = 0.1,
           jitter_factor = 0.001,
           tol = 1e-15, maxiter = 2000*length(lower),
           fnscale = 1, compare_to = c("median", "max"),
           add_to_init_pop = NULL,
           trace = FALSE, triter = 1,
           details = FALSE)

Arguments

lower, upper

numeric vectors, the lower and upper bounds of the search space (box constraints); must be finite (is.finite).

fn

a function to be minimized that takes a numeric vector X_i as first argument and returns the value of the objective.

constr

a vector function specifying the left-hand side of equality constraints defined to equal zero (h_j(X_i) = 0,\; j = 1,\ldots,\mathrm{meq}), followed by inequality constraints defined as lesser than or equal to zero (g_j(X_i) \le 0,\; j = \mathrm{meq}+1,\ldots). This function takes X_i as its first argument and returns a numeric vector with the same length of the total number of constraints. It defaults to NULL, which means that bound-constrained minimization is used.

meq

an integer, the first meq constraints are equality constraints whereas the remaining ones are inequality constraints. Defaults to 0 (inequality constraints only).

eps

the maximal admissible constraint violation for equality constraints. A numeric vector of small positive tolerance values with length meq used in the transformation of equalities into inequalities of the form |h_j(X_i)| - \epsilon \le 0. A scalar value is expanded to apply to all equality constraints. Default is 1e-5.

sequential_eval

a character string that indicates when either the objective function (if "objective") or the constraints (if "constraints") should be evaluated in a serial instead of parallel manner whenever their computational cost is low. If "both" the computation is purely sequential, being intended for debugging and testing. Defaults to "none".

...

[to be used only when run in parallel mode] named arguments specifying locally-defined functions and other objects required but not defined in fn and/or constr.

further_args

a list of any further arguments passed to fn and constr. Defaults to an empty list.

NP

an integer, the population size. Defaults to 100.

Fl

a numeric, the minimum value that the scaling factor F could take. It defaults to 0.1.

Fu

a numeric, the maximum value that the scaling factor F could take. It defaults to 1.

CRl

a numeric, the minimum value to be used for the crossover constant CR. It defaults to 0.

CRu

a numeric, the maximum value to be used for the crossover constant CR. It defaults to 1.1.

tau_F

a numeric, the probability that the scaling factor F is updated. Defaults to 0.1.

tau_CR

a numeric, the probability that the crossover constant CR is updated. Defaults to 0.1.

tau_pF

a numeric, the probability that the mutation probability p_F in the mutation strategy DE/rand/1/either-or is updated. Defaults to 0.1.

jitter_factor

a numeric, the tuning constant for jitter. If NULL only dither is used. Default is 0.001.

tol

a numeric, the tolerance for the stopping criterion. Default is 1e-15.

maxiter

an integer, the maximum number of iterations allowed. Default is 2000*length(lower).

fnscale

a numeric, the typical magnitude of fn used in the stopping criterion. Defaults to 1. See ‘Details’ in JDEoptim().

compare_to

a character string controlling which function should be applied when evaluating the stopping criterion. It defaults to "median". See ‘Details’ in JDEoptim().

add_to_init_pop

numeric vector of length length(lower) or column-wise matrix with length(lower) rows specifying initial candidate solutions which are appended to the randomly generated initial population. Default is NULL.

trace

logical indicating whether or not to monitor the iteration process. Default is FALSE.

triter

an integer, trace output is printed at every triter iterations. Default is 1.

details

logical indicating if the output will contain the solutions in the final population and their respective fn values. Defaults to FALSE.

Details

The optimizer is intended for dealing with computationally expensive objective functions and/or constraints (see, e.g., Storn and Price, 2025). The algorithm has been parallelized simply by distributing the evaluation of the candidate solutions in the population over the available processors/cores with mirai_map() from package mirai.

It is important to note this approach and its implementation is not equivalent to the purely sequential version JDEoptim(), the major reason being the fact that an asynchronous update of the current population is not possible anymore. This in turn almost always has a deleterious effect on the efficiency of DE. For this reason although it can run without mirai installed, for example using sequential_eval = "both", the use of JDEoptim() is preferred over SPJDEoptim() in this case.

Note that all support for the parallel computation is provided by package mirai and controlled directly by end-users; in particular, resources are declared with mirai::daemons() before invoking SPJDEoptim().

Value

A list with the following components:

par

the best solution X_i found.

value

the value of \mathrm{fn}(X_i) corresponding to par.

iter

the number of iterations used.

convergence

an integer code; 0 indicates successful completion, whereas 1 indicates that the iteration limit maxiter has been reached.

and if details = TRUE:

poppar

a matrix whose columns are the solutions remaining in the final population.

popcost

the values of \mathrm{fn}(X_i) for the corresponding columns of poppar.

Note

Additional arguments are passed to fn and constr through further_args instead of ... such as in JDEoptim().

Author(s)

Eduardo L. T. Conceicao mail@eduardoconceicao.org

References

https://mirai.r-lib.org

Storn, Rainer and Price, Kenneth V. (2025) Multi-child DE — a massively parallel differential evolution algorithm; in 2025 IEEE Symposium on Computational Intelligence on Engineering/Cyber Physical Systems (CIES), Trondheim, Norway. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1109/CIES64955.2025.11007629")}.

Examples


if (requireNamespace("mirai", quietly = TRUE)) {
# NOTE: Examples were excluded from testing
#       to reduce package check time.

# stays within 2-core limit
mirai::daemons(1, dispatcher = FALSE)
set.seed(42)

# Warning: the examples are run using a very small number of
# iterations to decrease execution time. Because they are very
# cheap to compute, parallel evaluation is actually detrimental.

#   Shekel 5 problem
#
#   0 <= xj <= 10, j = {1, 2, 3, 4}
#   There are five local minima and the global minimizer is
#   located at x* = (4.00, 4.00, 4.00, 4.00) with
#   f(x*) ~~ -10.1499.
#
#   Source:
#     Ali, M. Montaz, Khompatraporn, Charoenchai, and
#     Zabinsky, Zelda B. (2005).
#     A numerical evaluation of several stochastic algorithms
#     on selected continuous global optimization test problems.
#     Journal of Global Optimization 31, 635-672.
#     https://doi.org/10.1007/s10898-004-9972-2
a_ij <- matrix(c(4, 4, 4, 4,
                 1, 1, 1, 1,
                 8, 8, 8, 8,
                 6, 6, 6, 6,
                 3, 7, 3, 7), ncol = 4, byrow = TRUE)
c_i <- c(0.1, 0.2, 0.2, 0.4, 0.4)
a_ji <- t(a_ij)
shekel5 <- function(x) {
    -sum(1/( colSums((x - a_ji)^2) + c_i ))
}

SPJDEoptim(rep(0, 4), rep(10, 4), shekel5,
           a_ji = a_ji, c_i = c_i,
           maxiter = 10, trace = TRUE)

#   Sinusoidal problem
#
#   0 <= xi <= 180, i = {1, 2, ..., n}
#   The variable x is in degrees. Parameter A affects the
#   amplitude of the global optimum; B affects the peridiocity
#   and hence the number of local minima; z shifts the location
#   of the global minimum. The location of the global solution
#   is at x* = (90+z, 90+z, ..., 90+z) with the global optimum
#   value of f(x*) = -(A+1).
#
#   Source:
#     Ali, M. Montaz, Khompatraporn, Charoenchai, and
#     Zabinsky, Zelda B. (2005).
#     A numerical evaluation of several stochastic algorithms
#     on selected continuous global optimization test problems.
#     Journal of Global Optimization 31, 635-672.
#     https://doi.org/10.1007/s10898-004-9972-2
sinusoidal <- function(x, A, B, z) {
    var_in_rad <- (x - z)*pi/180
    -( A*prod(sin(var_in_rad)) + prod(sin(B*var_in_rad)) )
}

SPJDEoptim(rep(0, 10), rep(180, 10), sinusoidal,
           further_args = list(A = 2.5, B = 5, z = 30),
           maxiter = 10, trace = TRUE)

mirai::daemons(0) # reset
Sys.sleep(1)
}


DEoptimR documentation built on Feb. 19, 2026, 3:01 a.m.