The Controlled Random Search (CRS) algorithm (and in particular, the CRS2 variant) with the `local mutation' modification.
Usage
crs2lm(
x0,
fn,
lower,
upper,
maxeval = 10000,
pop.size = 10 * (length(x0) + 1),
ranseed = NULL,
xtol_rel = 1e-06,
nl.info = FALSE,
...
)
Arguments
- x0
initial point for searching the optimum.
- fn
objective function that is to be minimized.
- lower, upper
lower and upper bound constraints.
- maxeval
maximum number of function evaluations.
- pop.size
population size.
- ranseed
prescribe seed for random number generator.
- xtol_rel
stopping criterion for relative change reached.
- nl.info
logical; shall the original NLopt info be shown.
- ...
additional arguments passed to the function.
Value
List with components:
- par
the optimal solution found so far.
- value
the function value corresponding to
par
.- iter
number of (outer) iterations, see
maxeval
.- convergence
integer code indicating successful completion (> 0) or a possible error number (< 0).
- message
character string produced by NLopt and giving additional information.
Details
The CRS algorithms are sometimes compared to genetic algorithms, in that they start with a random population of points, and randomly evolve these points by heuristic rules. In this case, the evolution somewhat resembles a randomized Nelder-Mead algorithm.
The published results for CRS seem to be largely empirical.
Note
The initial population size for CRS defaults to \(10x(n+1)\) in \(n\) dimensions, but this can be changed. The initial population must be at least \(n+1\).
References
W. L. Price, ``Global optimization by controlled random search,'' J. Optim. Theory Appl. 40 (3), p. 333-348 (1983).
P. Kaelo and M. M. Ali, ``Some variants of the controlled random search algorithm for global optimization,'' J. Optim. Theory Appl. 130 (2), 253-264 (2006).
Examples
## Minimize the Hartmann 6-Dimensional function
## See https://www.sfu.ca/~ssurjano/hart6.html
a <- c(1.0, 1.2, 3.0, 3.2)
A <- matrix(c(10, 0.05, 3, 17,
3, 10, 3.5, 8,
17, 17, 1.7, 0.05,
3.5, 0.1, 10, 10,
1.7, 8, 17, 0.1,
8, 14, 8, 14), nrow = 4)
B <- matrix(c(.1312, .2329, .2348, .4047,
.1696, .4135, .1451, .8828,
.5569, .8307, .3522, .8732,
.0124, .3736, .2883, .5743,
.8283, .1004, .3047, .1091,
.5886, .9991, .6650, .0381), nrow = 4)
hartmann6 <- function(x, a, A, B) {
fun <- 0
for (i in 1:4) {
fun <- fun - a[i] * exp(-sum(A[i, ] * (x - B[i, ]) ^ 2))
}
fun
}
## The function has a global minimum of -3.32237 at
## (0.20169, 0.150011, 0.476874, 0.275332, 0.311652, 0.6573)
S <- crs2lm(x0 = rep(0, 6), hartmann6, lower = rep(0, 6), upper = rep(1, 6),
ranseed = 10L, nl.info = TRUE, xtol_rel=1e-8, maxeval = 10000,
a = a, A = A, B = B)
#>
#> Call:
#> nloptr(x0 = x0, eval_f = fn, lb = lower, ub = upper, opts = opts)
#>
#>
#> Minimization using NLopt version 2.7.1
#>
#> NLopt solver status: 4 ( NLOPT_XTOL_REACHED: Optimization stopped because
#> xtol_rel or xtol_abs (above) was reached. )
#>
#> Number of Iterations....: 5690
#> Termination conditions: maxeval: 10000 xtol_rel: 1e-08
#> Number of inequality constraints: 0
#> Number of equality constraints: 0
#> Optimal value of objective function: -3.32236801141551
#> Optimal value of controls: 0.2016895 0.1500107 0.476874 0.2753324 0.3116516 0.6573005
#>
#>
S
#> $par
#> [1] 0.2016895 0.1500107 0.4768740 0.2753324 0.3116516 0.6573005
#>
#> $value
#> [1] -3.322368
#>
#> $iter
#> [1] 5690
#>
#> $convergence
#> [1] 4
#>
#> $message
#> [1] "NLOPT_XTOL_REACHED: Optimization stopped because xtol_rel or xtol_abs (above) was reached."
#>