de: Differential Evolution via Genetic Algorithms

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Maximization of a fitness function using Differential Evolution (DE). DE is a population-based evolutionary algorithm for optimisation of fitness functions defined over a continuous parameter space.

Usage

1
2
3
4
5
6
de(fitness,
   lower, upper,
   popSize = 10*d,
   stepsize = 0.8,
   pcrossover = 0.5,
   ...)

Arguments

fitness

the fitness function, any allowable R function which takes as input a vector of values representing a potential solution, and returns a numerical value describing its “fitness”.

lower

a vector of length equal to the decision variables providing the lower bounds of the search space.

upper

a vector of length equal to the decision variables providing the upper bounds of the search space.

popSize

the population size. By default is set at 10 times the number of decision variables.

pcrossover

the probability of crossover, by default set to 0.5.

stepsize

the stepsize or weighting factor. A value in the interval [0,2], by default set to 0.8. If set at NA a random value is selected in the interval [0.5, 1.0] (so called dithering).

...

additional arguments to be passed to the fitness function. This allows to write fitness functions that keep some variables fixed during the search.

Details

Differential Evolution (DE) is a stochastic evolutionary algorithm that optimises multidimensional real-valued fitness functions without requiring the optimisation problem to be differentiable.

This implimentation follows the description in Simon (2013; Sec. 12.4, and Fig. 12.12) and uses the functionalities available in the ga function for Genetic Algorithms.

The DE selection operator is defined by gareal_de with parameters p = pcrossover and F = stepsize.

Value

Returns an object of class de-class. See de-class for a description of available slots information.

Author(s)

Luca Scrucca luca.scrucca@unipg.it

References

Scrucca L. (2013). GA: A Package for Genetic Algorithms in R. Journal of Statistical Software, 53(4), 1-37, http://www.jstatsoft.org/v53/i04/.

Simon D. (2013) Evolutionary Optimization Algorithms. John Wiley & Sons.

Price K., Storn R.M., Lampinen J.A. (2005) Differential Evolution: A Practical Approach to Global Optimization. Springer.

See Also

summary,de-method, plot,de-method, de-class

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 1) one-dimensional function
f <- function(x)  abs(x)+cos(x)
curve(f, -20, 20)

DE <- de(fitness = function(x) -f(x), lower = -20, upper = 20)
plot(DE)
summary(DE)

curve(f, -20, 20, n = 1000)
abline(v = DE@solution, lty = 3)

# 2) "Wild" function, global minimum at about -15.81515

wild <- function(x) 10*sin(0.3*x)*sin(1.3*x^2) + 0.00001*x^4 + 0.2*x + 80
plot(wild, -50, 50, n = 1000)

# from help("optim")
SANN <- optim(50, fn = wild, method = "SANN",
              control = list(maxit = 20000, temp = 20, parscale = 20))
unlist(SANN[1:2])

DE <- de(fitness = function(...) -wild(...), lower = -50, upper = 50)
plot(DE)
summary(DE)

# 3) two-dimensional Rastrigin function

Rastrigin <- function(x1, x2)
{
  20 + x1^2 + x2^2 - 10*(cos(2*pi*x1) + cos(2*pi*x2))
}

x1 <- x2 <- seq(-5.12, 5.12, by = 0.1)
f <- outer(x1, x2, Rastrigin)
persp3D(x1, x2, f, theta = 50, phi = 20, col.palette = bl2gr.colors)

DE <- de(fitness = function(x) -Rastrigin(x[1], x[2]),
         lower = c(-5.12, -5.12), upper = c(5.12, 5.12),
         popSize = 50)
plot(DE)
summary(DE)

filled.contour(x1, x2, f, color.palette = bl2gr.colors,
               plot.axes = { axis(1); axis(2); 
                             points(DE@solution, 
                                    col = "yellow", pch = 3, lwd = 2) })

# 4) two-dimensional Ackley function

Ackley <- function(x1, x2)
{
  -20*exp(-0.2*sqrt(0.5*(x1^2 + x2^2))) - 
  exp(0.5*(cos(2*pi*x1) + cos(2*pi*x2))) + exp(1) + 20
}

x1 <- x2 <- seq(-3, 3, by = 0.1)
f <- outer(x1, x2, Ackley)
persp3D(x1, x2, f, theta = 50, phi = 20, col.palette = bl2gr.colors)

DE <- de(fitness = function(x) -Ackley(x[1], x[2]),
         lower = c(-3, -3), upper = c(3, 3),
         stepsize = NA)
plot(DE)
summary(DE)

filled.contour(x1, x2, f, color.palette = bl2gr.colors,
               plot.axes = { axis(1); axis(2); 
                             points(DE@solution, 
                                    col = "yellow", pch = 3, lwd = 2) })

Example output

Loading required package: foreach
Loading required package: iterators
Package 'GA' version 3.2
Type 'citation("GA")' for citing this R package in publications.

Attaching package: 'GA'

The following object is masked from 'package:utils':

    de

-- Differential Evolution -------------- 

DE settings: 
Type                  =  real-valued 
Population size       =  10 
Number of generations =  100 
Elitism               =  0 
Stepsize              =  0.8 
Crossover probability =  0.5 
Mutation probability  =  0 
Search domain = 
       x1
lower -20
upper  20

DE results: 
Iterations             = 100 
Fitness function value = -1 
Solution = 
                x1
[1,] -5.356551e-16
      par     value 
-15.81514  67.46774 
-- Differential Evolution -------------- 

DE settings: 
Type                  =  real-valued 
Population size       =  10 
Number of generations =  100 
Elitism               =  0 
Stepsize              =  0.8 
Crossover probability =  0.5 
Mutation probability  =  0 
Search domain = 
       x1
lower -50
upper  50

DE results: 
Iterations             = 100 
Fitness function value = -67.67126 
Solution = 
            x1
[1,] -16.41428
-- Differential Evolution -------------- 

DE settings: 
Type                  =  real-valued 
Population size       =  50 
Number of generations =  100 
Elitism               =  0 
Stepsize              =  0.8 
Crossover probability =  0.5 
Mutation probability  =  0 
Search domain = 
         x1    x2
lower -5.12 -5.12
upper  5.12  5.12

DE results: 
Iterations             = 100 
Fitness function value = -1.539036e-11 
Solution = 
               x1            x2
[1,] 4.419249e-08 -2.749941e-07
-- Differential Evolution -------------- 

DE settings: 
Type                  =  real-valued 
Population size       =  20 
Number of generations =  100 
Elitism               =  0 
Stepsize              =  runif(0.5,1.0) 
Crossover probability =  0.5 
Mutation probability  =  0 
Search domain = 
      x1 x2
lower -3 -3
upper  3  3

DE results: 
Iterations             = 100 
Fitness function value = -9.076238e-09 
Solution = 
               x1            x2
[1,] 3.024442e-09 -1.072389e-09

GA documentation built on May 2, 2019, 9:57 a.m.