Benchmarks¶
Regroup typical EC benchmarks functions to import easily and benchmark examples.
Single Objective Continuous  Multi Objective Continuous  Binary  Symbolic Regression 

cigar() 
fonseca() 
chuang_f1() 
kotanchek() 
plane() 
kursawe() 
chuang_f2() 
salustowicz_1d() 
sphere() 
schaffer_mo() 
chuang_f3() 
salustowicz_2d() 
rand() 
dtlz1() 
royal_road1() 
unwrapped_ball() 
ackley() 
dtlz2() 
royal_road2() 
rational_polynomial() 
bohachevsky() 
dtlz3() 
rational_polynomial2() 

griewank() 
dtlz4() 
sin_cos() 

h1() 
zdt1() 
ripple() 

himmelblau() 
zdt2() 

rastrigin() 
zdt3() 

rastrigin_scaled() 
zdt4() 

rastrigin_skew() 
zdt6() 

rosenbrock() 

schaffer() 

schwefel() 

shekel() 
Continuous Optimization¶

deap.benchmarks.
cigar
(individual)¶ Cigar test objective function.
Type minimization Range none Global optima , Function

deap.benchmarks.
plane
(individual)¶ Plane test objective function.
Type minimization Range none Global optima , Function

deap.benchmarks.
sphere
(individual)¶ Sphere test objective function.
Type minimization Range none Global optima , Function

deap.benchmarks.
rand
(individual)¶ Random test objective function.
Type minimization or maximization Range none Global optima none Function

deap.benchmarks.
ackley
(individual)¶ Ackley test objective function.
Type minimization Range Global optima , Function (Source code, png, hires.png, pdf)

deap.benchmarks.
bohachevsky
(individual)¶ Bohachevsky test objective function.
Type minimization Range Global optima , Function (Source code, png, hires.png, pdf)

deap.benchmarks.
griewank
(individual)¶ Griewank test objective function.
Type minimization Range Global optima , Function (Source code, png, hires.png, pdf)

deap.benchmarks.
h1
(individual)¶ Simple twodimensional function containing several local maxima. From: The Merits of a Parallel Genetic Algorithm in Solving Hard Optimization Problems, A. J. Knoek van Soest and L. J. R. Richard Casius, J. Biomech. Eng. 125, 141 (2003)
Type maximization Range Global optima , Function (Source code, png, hires.png, pdf)

deap.benchmarks.
himmelblau
(individual)¶ The Himmelblau’s function is multimodal with 4 defined minimums in .
Type minimization Range Global optima ,
,
,
,
Function (Source code, png, hires.png, pdf)

deap.benchmarks.
rastrigin
(individual)¶ Rastrigin test objective function.
Type minimization Range Global optima , Function (Source code, png, hires.png, pdf)

deap.benchmarks.
rastrigin_scaled
(individual)¶ Scaled Rastrigin test objective function.

deap.benchmarks.
rastrigin_skew
(individual)¶ Skewed Rastrigin test objective function.

deap.benchmarks.
rosenbrock
(individual)¶ Rosenbrock test objective function.
Type minimization Range none Global optima , Function (Source code, png, hires.png, pdf)

deap.benchmarks.
schaffer
(individual)¶ Schaffer test objective function.
Type minimization Range Global optima , Function (Source code, png, hires.png, pdf)

deap.benchmarks.
schwefel
(individual)¶ Schwefel test objective function.
Type minimization Range Global optima , Function (Source code, png, hires.png, pdf)

deap.benchmarks.
shekel
(individual, a, c)¶ The Shekel multimodal function can have any number of maxima. The number of maxima is given by the length of any of the arguments a or c, a is a matrix of size , where M is the number of maxima and N the number of dimensions and c is a vector.
The following figure uses
and , thus defining 5 maximums in .
(Source code, png, hires.png, pdf)
Multiobjective¶

deap.benchmarks.
fonseca
(individual)¶ Fonseca and Fleming’s multiobjective function. From: C. M. Fonseca and P. J. Fleming, “Multiobjective optimization and multiple constraint handling with evolutionary algorithms – Part II: Application example”, IEEE Transactions on Systems, Man and Cybernetics, 1998.

deap.benchmarks.
kursawe
(individual)¶ Kursawe multiobjective function.
(Source code, png, hires.png, pdf)

deap.benchmarks.
schaffer_mo
(individual)¶ Schaffer’s multiobjective function on a one attribute individual. From: J. D. Schaffer, “Multiple objective optimization with vector evaluated genetic algorithms”, in Proceedings of the First International Conference on Genetic Algorithms, 1987.

deap.benchmarks.
dtlz1
(individual, obj)¶ DTLZ1 multiobjective function. It returns a tuple of obj values. The individual must have at least obj elements. From: K. Deb, L. Thiele, M. Laumanns and E. Zitzler. Scalable MultiObjective Optimization Test Problems. CEC 2002, p. 825  830, IEEE Press, 2002.
Where is the number of objectives and is a vector of the remaining attributes of the individual in dimensions.

deap.benchmarks.
dtlz2
(individual, obj)¶ DTLZ2 multiobjective function. It returns a tuple of obj values. The individual must have at least obj elements. From: K. Deb, L. Thiele, M. Laumanns and E. Zitzler. Scalable MultiObjective Optimization Test Problems. CEC 2002, p. 825  830, IEEE Press, 2002.
Where is the number of objectives and is a vector of the remaining attributes of the individual in dimensions.

deap.benchmarks.
dtlz3
(individual, obj)¶ DTLZ3 multiobjective function. It returns a tuple of obj values. The individual must have at least obj elements. From: K. Deb, L. Thiele, M. Laumanns and E. Zitzler. Scalable MultiObjective Optimization Test Problems. CEC 2002, p. 825  830, IEEE Press, 2002.
Where is the number of objectives and is a vector of the remaining attributes of the individual in dimensions.

deap.benchmarks.
dtlz4
(individual, obj, alpha)¶ DTLZ4 multiobjective function. It returns a tuple of obj values. The individual must have at least obj elements. The alpha parameter allows for a metavariable mapping in
dtlz2()
, the authors suggest . From: K. Deb, L. Thiele, M. Laumanns and E. Zitzler. Scalable MultiObjective Optimization Test Problems. CEC 2002, p. 825  830, IEEE Press, 2002.Where is the number of objectives and is a vector of the remaining attributes of the individual in dimensions.

deap.benchmarks.
zdt1
(individual)¶ ZDT1 multiobjective function.

deap.benchmarks.
zdt2
(individual)¶ ZDT2 multiobjective function.

deap.benchmarks.
zdt3
(individual)¶ ZDT3 multiobjective function.

deap.benchmarks.
zdt4
(individual)¶ ZDT4 multiobjective function.

deap.benchmarks.
zdt6
(individual)¶ ZDT6 multiobjective function.
Binary Optimization¶

deap.benchmarks.binary.
chuang_f1
(individual)¶ Binary deceptive function from : Multivariate MultiModel Approach for Globally Multimodal Problems by ChungYao Chuang and WenLian Hsu.
The function takes individual of 40+1 dimensions and has two global optima in [1,1,…,1] and [0,0,…,0].

deap.benchmarks.binary.
chuang_f2
(individual)¶ Binary deceptive function from : Multivariate MultiModel Approach for Globally Multimodal Problems by ChungYao Chuang and WenLian Hsu.
The function takes individual of 40+1 dimensions and has four global optima in [1,1,…,0,0], [0,0,…,1,1], [1,1,…,1] and [0,0,…,0].

deap.benchmarks.binary.
chuang_f3
(individual)¶ Binary deceptive function from : Multivariate MultiModel Approach for Globally Multimodal Problems by ChungYao Chuang and WenLian Hsu.
The function takes individual of 40+1 dimensions and has two global optima in [1,1,…,1] and [0,0,…,0].

deap.benchmarks.binary.
royal_road1
(individual, order)¶ Royal Road Function R1 as presented by Melanie Mitchell in : “An introduction to Genetic Algorithms”.

deap.benchmarks.binary.
royal_road2
(individual, order)¶ Royal Road Function R2 as presented by Melanie Mitchell in : “An introduction to Genetic Algorithms”.

deap.benchmarks.binary.
bin2float
(min_, max_, nbits)¶ Convert a binary array into an array of float where each float is composed of nbits and is between min_ and max_ and return the result of the decorated function.
Symbolic Regression¶

deap.benchmarks.gp.
kotanchek
(data)¶ Kotanchek benchmark function.
Range Function

deap.benchmarks.gp.
salustowicz_1d
(data)¶ Salustowicz benchmark function.
Range Function

deap.benchmarks.gp.
salustowicz_2d
(data)¶ Salustowicz benchmark function.
Range Function

deap.benchmarks.gp.
unwrapped_ball
(data)¶ Unwrapped ball benchmark function.
Range Function

deap.benchmarks.gp.
rational_polynomial
(data)¶ Rational polynomial ball benchmark function.
Range Function

deap.benchmarks.gp.
rational_polynomial2
(data)¶ Rational polynomial benchmark function.
Range Function

deap.benchmarks.gp.
sin_cos
(data)¶ Sine cosine benchmark function.
Range Function

deap.benchmarks.gp.
ripple
(data)¶ Ripple benchmark function.
Range Function
Moving Peaks Benchmark¶
Reimplementation of the Moving Peaks Benchmark by Jurgen Branke. With the addition of the fluctuating number of peaks presented in du Plessis and Engelbrecht, 2013, SelfAdaptive Environment with Fluctuating Number of Optima.

class
deap.benchmarks.movingpeaks.
MovingPeaks
(self, dim[, pfunc][, npeaks][, bfunc][, random][, ...])¶ The Moving Peaks Benchmark is a fitness function changing over time. It consists of a number of peaks, changing in height, width and location. The peaks function is given by pfunc, wich is either a function object or a list of function objects (the default is
function1()
). The number of peaks is determined by npeaks (which defaults to 5). This parameter can be either a integer or a sequence. If it is set to an integer the number of peaks won’t change, while if set to a sequence of 3 elements, the number of peaks will fluctuate between the first and third element of that sequence, the second element is the inital number of peaks. When fluctuating the number of peaks, the parameter number_severity must be included, it represents the number of peak fraction that is allowed to change. The dimensionality of the search domain is dim. A basis function bfunc can also be given to act as static landscape (the default is no basis function). The argument random serves to grant an independent random number generator to the moving peaks so that the evolution is not influenced by number drawn by this object (the default uses random functions from the Python modulerandom
). Various other keyword parameters listed in the table below are required to setup the benchmark, default parameters are based on scenario 1 of this benchmark.Parameter SCENARIO_1
(Default)SCENARIO_2
SCENARIO_3
Details pfunc
function1()
cone()
cone()
The peak function or a list of peak function. npeaks
5 10 50 Number of peaks. If an integer, the number of peaks won’t change, if a sequence it will fluctuate [min, current, max]. bfunc
None
None
lambda x: 10
Basis static function. min_coord
0.0 0.0 0.0 Minimum coordinate for the centre of the peaks. max_coord
100.0 100.0 100.0 Maximum coordinate for the centre of the peaks. min_height
30.0 30.0 30.0 Minimum height of the peaks. max_height
70.0 70.0 70.0 Maximum height of the peaks. uniform_height
50.0 50.0 0 Starting height for all peaks, if uniform_height <= 0
the initial height is set randomly for each peak.min_width
0.0001 1.0 1.0 Minimum width of the peaks. max_width
0.2 12.0 12.0 Maximum width of the peaks uniform_width
0.1 0 0 Starting width for all peaks, if uniform_width <= 0
the initial width is set randomly for each peak.lambda_
0.0 0.5 0.5 Correlation between changes. move_severity
1.0 1.5 1.0 The distance a single peak moves when peaks change. height_severity
7.0 7.0 1.0 The standard deviation of the change made to the height of a peak when peaks change. width_severity
0.01 1.0 0.5 The standard deviation of the change made to the width of a peak when peaks change. period
5000 5000 1000 Period between two changes. Dictionnaries
SCENARIO_1
,SCENARIO_2
andSCENARIO_3
of this module define the defaults for these parameters. The scenario 3 requires a constant basis function which can be given as a lambda functionlambda x: constant
.The following shows an example of scenario 1 with non uniform heights and widths.
(Source code, png, hires.png, pdf)

__call__
(self, individual[, count])¶ Evaluate a given individual with the current benchmark configuration.
Parameters:  indidivudal – The individual to evaluate.
 count – Wether or not to count this evaluation in
the total evaluation count. (Defaults to
True
)

changePeaks
()¶ Order the peaks to change position, height, width and number.

globalMaximum
()¶ Returns the global maximum value and position.

maximums
()¶ Returns all visible maximums value and position sorted with the global maximum first.


deap.benchmarks.movingpeaks.
cone
(individual, position, height, width)¶ The cone peak function to be used with scenario 2 and 3.

deap.benchmarks.movingpeaks.
function1
(individual, position, height, width)¶ The function1 peak function to be used with scenario 1.
Benchmarks tools¶
Module containing tools that are useful when benchmarking algorithms

deap.benchmarks.tools.
convergence
(first_front, optimal_front)¶ Given a Pareto front first_front and the optimal Pareto front, this function returns a metric of convergence of the front as explained in the original NSGAII article by K. Deb. The smaller the value is, the closer the front is to the optimal one.

deap.benchmarks.tools.
diversity
(first_front, first, last)¶ Given a Pareto front first_front and the two extreme points of the optimal Pareto front, this function returns a metric of the diversity of the front as explained in the original NSGAII article by K. Deb. The smaller the value is, the better the front is.

deap.benchmarks.tools.
noise
(noise)¶ Decorator for evaluation functions, it evaluates the objective function and adds noise by calling the function(s) provided in the noise argument. The noise functions are called without any argument, consider using the
Toolbox
or Python’sfunctools.partial()
to provide any required argument. If a single function is provided it is applied to all objectives of the evaluation function. If a list of noise functions is provided, it must be of length equal to the number of objectives. The noise argument also acceptNone
, which will leave the objective without noise.This decorator adds a
noise()
method to the decorated function.
noise.
noise
(noise)¶ Set the current noise to noise. After decorating the evaluation function, this function will be available directly from the function object.
prand = functools.partial(random.gauss, mu=0.0, sigma=1.0) @noise(prand) def evaluate(individual): return sum(individual), # This will remove noise from the evaluation function evaluate.noise(None)


deap.benchmarks.tools.
rotate
(matrix)¶ Decorator for evaluation functions, it rotates the objective function by matrix which should be a valid orthogonal NxN rotation matrix, with N the length of an individual. When called the decorated function should take as first argument the individual to be evaluated. The inverse rotation matrix is actually applied to the individual and the resulting list is given to the evaluation function. Thus, the evaluation function shall not be expecting an individual as it will receive a plain list (numpy.array). The multiplication is done using numpy.
This decorator adds a
rotate()
method to the decorated function.Note
A random orthogonal matrix Q can be created via QR decomposition.
A = numpy.random.random((n,n)) Q, _ = numpy.linalg.qr(A)

rotate.
rotate
(matrix)¶ Set the current rotation to matrix. After decorating the evaluation function, this function will be available directly from the function object.
# Create a random orthogonal matrix A = numpy.random.random((n,n)) Q, _ = numpy.linalg.qr(A) @rotate(Q) def evaluate(individual): return sum(individual), # This will reset rotation to identity evaluate.rotate(numpy.identity(n))


deap.benchmarks.tools.
scale
(factor)¶ Decorator for evaluation functions, it scales the objective function by factor which should be the same length as the individual size. When called the decorated function should take as first argument the individual to be evaluated. The inverse factor vector is actually applied to the individual and the resulting list is given to the evaluation function. Thus, the evaluation function shall not be expecting an individual as it will receive a plain list.
This decorator adds a
scale()
method to the decorated function.
scale.
scale
(factor)¶ Set the current scale to factor. After decorating the evaluation function, this function will be available directly from the function object.
@scale([0.25, 2.0, ..., 0.1]) def evaluate(individual): return sum(individual), # This will cancel the scaling evaluate.scale([1.0, 1.0, ..., 1.0])


deap.benchmarks.tools.
translate
(vector)¶ Decorator for evaluation functions, it translates the objective function by vector which should be the same length as the individual size. When called the decorated function should take as first argument the individual to be evaluated. The inverse translation vector is actually applied to the individual and the resulting list is given to the evaluation function. Thus, the evaluation function shall not be expecting an individual as it will receive a plain list.
This decorator adds a
translate()
method to the decorated function.
translate.
translate
(vector)¶ Set the current translation to vector. After decorating the evaluation function, this function will be available directly from the function object.
@translate([0.25, 0.5, ..., 0.1]) def evaluate(individual): return sum(individual), # This will cancel the translation evaluate.translate([0.0, 0.0, ..., 0.0])
