19"""Collection of test functions and benchmarks for QD algorithms based on artificial landscapes. Cf https://arxiv.org/pdf/1308.4008v1.pdf and https://arxiv.org/pdf/1207.4318.pdf and https://en.wikipedia.org/wiki/Test_functions_for_optimization and https://www.sfu.ca/~ssurjano/optimization.html"""
22 "sphere",
"illumination_sphere",
"SphereBenchmark",
23 "weighted_sphere",
"illumination_weighted_sphere",
"WeightedSphereBenchmark",
24 "rotated_hyper_ellipsoid",
"illumination_rotated_hyper_ellipsoid",
"RotatedHyperEllipsoidBenchmark",
25 "rosenbrock",
"illumination_rosenbrock",
"RosenbrockBenchmark",
26 "rastrigin_normalised",
"illumination_rastrigin_normalised",
"NormalisedRastriginBenchmark",
27 "rastrigin",
"illumination_rastrigin",
"RastriginBenchmark",
28 "schwefel",
"illumination_schwefel",
"SchwefelBenchmark",
29 "small_schwefel",
"illumination_small_schwefel",
"SmallSchwefelBenchmark",
30 "griewangk",
"illumination_griewangk",
"GriewangkBenchmark",
31 "sum_of_powers",
"illumination_sum_of_powers",
"SumOfPowersBenchmark",
32 "ackley",
"illumination_ackley",
"AckleyBenchmark",
33 "styblinski_tang",
"illumination_styblinski_tang",
"StyblinskiTangBenchmark",
34 "levy",
"illumination_levy",
"LevyBenchmark",
35 "perm0db",
"illumination_perm0db",
"Perm0dbBenchmark",
36 "permdb",
"illumination_permdb",
"PermdbBenchmark",
37 "trid",
"illumination_trid",
"TridBenchmark",
38 "zakharov",
"illumination_zakharov",
"ZakharovBenchmark",
39 "dixon_price",
"illumination_dixon_price",
"DixonPriceBenchmark",
40 "powell",
"illumination_powell",
"PowellBenchmark",
41 "michalewicz",
"illumination_michalewicz",
"MichalewiczBenchmark",
42 "wavy",
"illumination_wavy",
"WavyBenchmark",
43 "trigonometric02",
"illumination_trigonometric02",
"Trigonometric02Benchmark",
44 "qing",
"illumination_qing",
"QingBenchmark",
45 "small_qing",
"illumination_small_qing",
"SmallQingBenchmark",
46 "deb01",
"illumination_deb01",
"Deb01Benchmark",
47 "shubert04",
"illumination_shubert04",
"Shubert04Benchmark",
50from math
import cos, pi
51from typing
import Optional, Tuple, List, Iterable, Iterator, Any, TypeVar, Generic, Union, Sequence, MutableSet, MutableSequence, Type, Callable, Generator, Mapping, MutableMapping, overload
54from qdpy
import algorithms
64def _illuminate_artificial_landscape(ind, func, nb_features = 2):
65 """Attach descriptors and named scores to a raw objective function.
67 An illumination evaluator returns fitness, a prefix of the genome
68 as descriptors, and a score mapping containing string coordinate
69 keys plus ``perf`` for the first objective.
72 features = list(ind[:nb_features])
73 scores = {f
"{i}": v
for i, v
in enumerate(features)}
74 scores[
'perf'] = fitness[0]
75 return fitness, features, scores
79 r"""Sphere function defined as:
80 $$ f(x) = \sum_{i=1}^{n} x_i^{2} $$
81 with a search domain of $-5.12 < x_i < 5.12, 1 \leq i \leq n$.
82 The global minimum is at $f(x_1, ..., x_n) = f(0, ..., 0) = 0.
83 It is continuous, convex and unimodal.
85 return sum((x ** 2.
for x
in ind)),
86illumination_sphere = algorithms.partial(_illuminate_artificial_landscape, func=sphere)
88 """Minimise the sum of squared genome coordinates."""
89 def __init__(self, nb_features: int = 2):
91 ind_domain = (-5.12, 5.12)
92 super().__init__(fn=algorithms.partial(illumination_sphere, nb_features=nb_features),
93 ind_domain = ind_domain,
94 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
95 default_task =
"minimisation")
97def weighted_sphere(ind):
98 r"""Weighted sphere function defined as:
99 $$ f(x) = \sum_{i=1}^{n} i \times x_i^{2} $$
100 with a search domain of $-5.12 < x_i < 5.12, 1 \leq i \leq n$.
101 The global minimum is at $f(x_1, ..., x_n) = f(0, ..., 0) = 0.
102 It is continuous, convex and unimodal.
104 return sum(i * x**2.0
for i, x
in enumerate(ind, start=1)),
105illumination_weighted_sphere = algorithms.partial(_illuminate_artificial_landscape, func=weighted_sphere)
107 """Minimise squared coordinates weighted by their one-based coordinate indexes."""
108 def __init__(self, nb_features: int = 2):
110 ind_domain = (-5.12, 5.12)
111 super().__init__(fn=algorithms.partial(illumination_weighted_sphere, nb_features=nb_features),
112 ind_domain = ind_domain,
113 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
114 default_task =
"minimisation")
117def rotated_hyper_ellipsoid(ind):
118 r"""Rotated hyper-ellipsoid function defined as:
119 $$ f(x) = \sum_{i=1}^{n} \sum_{j=1}^{i} x_j^{2} $$
120 with a search domain of $-65.536 < x_i < 65.536, 1 \leq i \leq n$.
121 The global minimum is at $f(x_1, ..., x_n) = f(0, ..., 0) = 0.
122 It is continuous, convex and unimodal.
124 return sum((len(ind) - i) * x**2.0
for i, x
in enumerate(ind)),
125illumination_rotated_hyper_ellipsoid = algorithms.partial(_illuminate_artificial_landscape, func=rotated_hyper_ellipsoid)
127 """Minimise the sum of squared prefix norms."""
128 def __init__(self, nb_features: int = 2):
130 ind_domain = (-65.536, 65.536)
131 super().__init__(fn=algorithms.partial(illumination_rotated_hyper_ellipsoid, nb_features=nb_features),
132 ind_domain = ind_domain,
133 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
134 default_task =
"minimisation")
138 r"""Rosenbrock function defined as:
139 $$ f(x) = \sum_{i=1}^{n-1} 100 \times (x_{i+1} - x_i^{2})^{2} + (1 - x_{i})^{2} $$
140 with a search domain of $-2.048 < x_i < 2.048, 1 \leq i \leq n$.
141 The global minimum is at $f(x_1, ..., x_n) = f(1, ..., 1) = 0.
143 return sum((100. * (ind[i+1]-ind[i]**2.)**2. + (1-ind[i])**2.
for i
in range(len(ind)-1))),
144illumination_rosenbrock = algorithms.partial(_illuminate_artificial_landscape, func=rosenbrock)
146 """Minimise Rosenbrock's function with its curved valley toward the all-ones genome."""
147 def __init__(self, nb_features: int = 2):
149 ind_domain = (-2.048, 2.048)
150 super().__init__(fn=algorithms.partial(illumination_rosenbrock, nb_features=nb_features),
151 ind_domain = ind_domain,
152 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
153 default_task =
"minimisation")
157def rastrigin_normalised(ind, a=10.):
158 """Rastrigin test function, with inputs and outputs scaled to be between 0. and 1."""
160 ind_n = [-5.12 + x * (5.12 * 2.)
for x
in ind]
161 return (a * n + sum(x * x - a * cos(2. * pi * x)
for x
in ind_n)) / (a * n + n * (5.12 * 5.12 + a)),
162illumination_rastrigin_normalised = algorithms.partial(_illuminate_artificial_landscape, func=rastrigin_normalised)
164 """Minimise Rastrigin with genome coordinates and output scaled to the unit interval."""
165 def __init__(self, nb_features: int = 2):
167 ind_domain = (0., 1.)
168 super().__init__(fn=algorithms.partial(illumination_rastrigin_normalised, nb_features=nb_features),
169 ind_domain = ind_domain,
170 fitness_domain = ((0., 1.),), features_domain = (ind_domain,) * nb_features,
171 default_task =
"minimisation")
174def rastrigin(ind, a=10.):
175 """Rastrigin test function."""
177 return a * n + sum(x * x - a * cos(2. * pi * x)
for x
in ind),
178illumination_rastrigin = algorithms.partial(_illuminate_artificial_landscape, func=rastrigin)
180 """Minimise the multimodal Rastrigin objective on its native coordinate domain."""
181 def __init__(self, nb_features: int = 2):
183 ind_domain = (-5.12, 5.12)
184 super().__init__(fn=algorithms.partial(illumination_rastrigin, nb_features=nb_features),
185 ind_domain = ind_domain,
186 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
187 default_task =
"minimisation")
192 r"""Schwefel function defined as:
193 $$ f(x) = 418.9829n - \sum_{i=1}^{n} x_i \sin(\sqrt(\norm(x_i))) $
194 with a search domain of $-500 < x_i < 500, 1 \leq i \leq n$.
195 The global minimum is at $f(x_1, ..., x_n) = f(420.9687, ..., 420.9687) = 0.
197 return 418.9829 * float(len(ind)) - sum((x * math.sin(math.sqrt(abs(x)))
for x
in ind)),
198illumination_schwefel = algorithms.partial(_illuminate_artificial_landscape, func=schwefel)
200 """Minimise Schwefel on the full coordinate range from -500 to 500."""
201 def __init__(self, nb_features: int = 2):
203 ind_domain = (-500., 500.)
204 super().__init__(fn=algorithms.partial(illumination_schwefel, nb_features=nb_features),
205 ind_domain = ind_domain,
206 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
207 default_task =
"minimisation")
211def small_schwefel(ind):
212 r"""Schwefel function defined as:
213 $$ f(x) = 418.9829n - \sum_{i=1}^{n} x_i \sin(\sqrt(\norm(x_i))) $
214 with a search domain of $-100 < x_i < 100, 1 \leq i \leq n$.
216 return 418.9829 * float(len(ind)) - sum((x * math.sin(math.sqrt(abs(x)))
for x
in ind)),
217illumination_small_schwefel = algorithms.partial(_illuminate_artificial_landscape, func=small_schwefel)
219 """Minimise Schwefel on the narrowed coordinate range from -100 to 100."""
220 def __init__(self, nb_features: int = 2):
222 ind_domain = (-100., 100.)
223 super().__init__(fn=algorithms.partial(illumination_small_schwefel, nb_features=nb_features),
224 ind_domain = ind_domain,
225 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
226 default_task =
"minimisation")
230 r"""Griewangk function defined as:
231 $$ f(x) = 1 + \sum_{i=1}^{n} \frac{x_i^2}{4000} - \prod_{i=1}^n \cos \frac{x_i}{\sqrt{i}} $$
232 with a search domain of $-600 < x_i < 600, 1 \leq i \leq n$.
233 The global minimum is at $f(x_1, ..., x_n) = f(0, ..., 0) = 0.
235 return 1. + sum(( (x ** 2.) / 4000.
for x
in ind)) - np.prod(list((math.cos(ind[i] / math.sqrt(i+1.))
for i
in range(len(ind))))),
236illumination_griewangk = algorithms.partial(_illuminate_artificial_landscape, func=griewangk)
238 """Minimise the Griewangk sum-and-product objective."""
239 def __init__(self, nb_features: int = 2):
241 ind_domain = (-600., 600.)
242 super().__init__(fn=algorithms.partial(illumination_griewangk, nb_features=nb_features),
243 ind_domain = ind_domain,
244 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
245 default_task =
"minimisation")
249def sum_of_powers(ind):
250 r"""Sum Of Powers function defined as:
251 $$ f(x) = \sum_{i=1}^{n} \norm{x_i}^{(i+1)} $$
252 with a search domain of $-1 < x_i < 1, 1 \leq i \leq n$.
253 The global minimum is at $f(x_1, ..., x_n) = f(0, ..., 0) = 0.
255 return sum(abs(float(x))**power
for power, x
in enumerate(ind, start=2)),
256illumination_sum_of_powers = algorithms.partial(_illuminate_artificial_landscape, func=sum_of_powers)
258 """Minimise absolute coordinate powers with exponents increasing from two."""
259 def __init__(self, nb_features: int = 2):
261 ind_domain = (-1., 1.)
262 super().__init__(fn=algorithms.partial(illumination_sum_of_powers, nb_features=nb_features),
263 ind_domain = ind_domain,
264 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
265 default_task =
"minimisation")
269def ackley(ind, a=20., b=0.2, c=2.*math.pi):
270 r"""Ackley function defined as:
271 $$ f(x) = -a \exp^{-b \sqrt{1/n \sum_{i=1}^n x_i^2} - \exp^{1/n \sum_{i=1}^n \cos{c x_i}} + a + \exp^{1} $$
272 with $a=20, b=0.2, c=2\pi$ and with a search domain of $-32.768 < x_i < 32.768, 1 \leq i \leq n$.
273 The global minimum is at $f(x_1, ..., x_n) = f(0, ..., 0) = 0.
275 return - a * math.exp(-b * math.sqrt(1./len(ind) * sum((x**2.
for x
in ind)) )) - math.exp(1./len(ind) * sum((math.cos(c*ind[i])
for i
in range(len(ind)) )) ) + a + math.exp(1.),
276illumination_ackley = algorithms.partial(_illuminate_artificial_landscape, func=ackley)
278 """Minimise the Ackley objective using its default coefficients."""
279 def __init__(self, nb_features: int = 2):
281 ind_domain = (-32.768, 32.768)
282 super().__init__(fn=algorithms.partial(illumination_ackley, nb_features=nb_features),
283 ind_domain = ind_domain,
284 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
285 default_task =
"minimisation")
289def styblinski_tang(ind):
290 r"""Styblinski-Tang function defined as:
291 $$ f(x) = 1/2 \sum_{i=1}^{n} x_i^4 - 16 x_i^2 + 5 x_i $$
292 with a search domain of $-5 < x_i < 5, 1 \leq i \leq n$.
294 return sum(((x ** 4.) - 16. * (x ** 2.) + 5. * x
for x
in ind)) / 2.,
295illumination_styblinski_tang = algorithms.partial(_illuminate_artificial_landscape, func=styblinski_tang)
297 """Minimise the separable Styblinski–Tang polynomial."""
298 def __init__(self, nb_features: int = 2):
301 super().__init__(fn=algorithms.partial(illumination_styblinski_tang, nb_features=nb_features),
302 ind_domain = ind_domain,
303 fitness_domain = ((-math.inf, math.inf),), features_domain = (ind_domain,) * nb_features,
304 default_task =
"minimisation")
309 r"""Levy function defined as:
310 $$ f(x) = \sin(\pi w_1)^2 + \sum_{i=1}^{n-1}(w_i-1)^2 (1+10 \sin(\pi w_i+1)^2) + (w_n-1)^2 (1+\sin(2\pi w_d)^2)$$
311 where $w_i = 1+ \frac{x_i-1}{4}$
312 with a search domain of $-10 < x_i < 10, 1 \leq i \leq n$.
313 The global minimum is at $f(x_1, ..., x_n) = f(1, ..., 1) = 0.
315 w = list((1. + (x-1.)/4.
for x
in ind))
316 return (math.sin(math.pi * w[0]))**2. + \
317 sum((x-1.)**2. * (1.+10.*math.sin(math.pi*x+1.)**2.)
for x
in w[:-1]) + \
318 (w[-1]-1.)**2. * (1.+(math.sin(2.*math.pi*w[-1]))**2.),
319illumination_levy = algorithms.partial(_illuminate_artificial_landscape, func=levy)
321 """Minimise the Lévy objective including its distinct final-coordinate term."""
322 def __init__(self, nb_features: int = 2):
324 ind_domain = (-10., 10.)
325 super().__init__(fn=algorithms.partial(illumination_levy, nb_features=nb_features),
326 ind_domain = ind_domain,
327 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
328 default_task =
"minimisation")
331def perm0db(ind, beta=10.):
332 r"""Perm function 0, D, BETA defined as:
333 $$ f(x) = \sum_{i=1}^n (\sum_{j=1}^n (j+\beta) (x_j^i - \frac{1}{j^i}) )^2$$
334 with a search domain of $-n < x_i < n, 1 \leq i \leq n$.
335 The global minimum is at $f(1, 1/2, ..., 1/n) = 0$.
338 ( sum(( (j+1.+beta) * ((ind[j])**float(i+1) - 1./(float(j+1)**float(i+1)))
for j
in range(len(ind)) )) )**2. \
339 for i
in range(len(ind)) )),
340illumination_perm0db = algorithms.partial(_illuminate_artificial_landscape, func=perm0db)
342 """Minimise the Perm 0, d, beta objective with reciprocal-index optima."""
343 def __init__(self, nb_features: int = 2):
345 ind_domain = (float(-nb_features), float(nb_features))
346 super().__init__(fn=algorithms.partial(illumination_perm0db, nb_features=nb_features),
347 ind_domain = ind_domain,
348 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
349 default_task =
"minimisation")
352def permdb(ind, beta=0.5):
353 r"""Perm function D, BETA defined as:
354 $$ f(x) = \sum_{i=1}^d (\sum_{j=1}^n (j^i+\beta) ((\frac{x_j}{j})^i - 1) )^2$$
355 with a search domain of $-n < x_i < n, 1 \leq i \leq n$.
356 The global minimum is at $f(1, 2, ..., n) = 0$.
359 ( sum(( ((j+1.)**(i+1.)+beta) * ((ind[j]/(j+1.))**(i+1.) - 1.)
for j
in range(len(ind)) )) )**2. \
360 for i
in range(len(ind)) )),
361illumination_permdb = algorithms.partial(_illuminate_artificial_landscape, func=permdb)
363 """Minimise the Perm d, beta objective with one-based index optima."""
364 def __init__(self, nb_features: int = 2):
366 ind_domain = (float(-nb_features), float(nb_features))
367 super().__init__(fn=algorithms.partial(illumination_permdb, nb_features=nb_features),
368 ind_domain = ind_domain,
369 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
370 default_task =
"minimisation")
375 r"""Trid function defined as:
376 $$ f(x) = \sum_{i=1}^n (x_i - 1)^2 - \sum_{i=2}^n x_i x_{i-1}$$
377 with a search domain of $-n^2 < x_i < n^2, 1 \leq i \leq n$.
378 The global minimum is $f(x^{*}) = -n(n+4)(n-1)/6$ at $x_i = i(n+1-i)$ for all $i=1,2,...,n$.
380 return sum(( (x-1)**2.
for x
in ind)) - sum(( ind[i] * ind[i-1]
for i
in range(1, len(ind)) )),
381illumination_trid = algorithms.partial(_illuminate_artificial_landscape, func=trid)
383 """Minimise the Trid objective with a fitness domain that admits negative values."""
384 def __init__(self, nb_features: int = 2):
386 ind_domain = (-float(nb_features)**2., float(nb_features)**2.)
387 super().__init__(fn=algorithms.partial(illumination_trid, nb_features=nb_features),
388 ind_domain = ind_domain,
389 fitness_domain = ((-math.inf, math.inf),), features_domain = (ind_domain,) * nb_features,
390 default_task =
"minimisation")
394 r"""Zakharov function defined as:
395 $$ f(x) = \sum_{i=1}^n x_i^2 + (\sum_{i=1}^n 0.5 i x_i)^2 + (\sum_{i=1}^n 0.5 i x_i)^4$$
396 with a search domain of $-5 < x_i < 10, 1 \leq i \leq n$.
397 The global minimum is at $f(x_1, ..., x_n) = f(0, ..., 0) = 0.
399 weighted_sum = sum(0.5 * i * x
for i, x
in enumerate(ind, start=1))
400 return sum(x**2.0
for x
in ind) + weighted_sum**2 + weighted_sum**4,
401illumination_zakharov = algorithms.partial(_illuminate_artificial_landscape, func=zakharov)
403 """Minimise the Zakharov objective with one-based weights in its mixed terms."""
404 def __init__(self, nb_features: int = 2):
406 ind_domain = (-5., 10.)
407 super().__init__(fn=algorithms.partial(illumination_zakharov, nb_features=nb_features),
408 ind_domain = ind_domain,
409 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
410 default_task =
"minimisation")
414 r"""Dixon Price function defined as:
415 $$ f(x) = (x_1 - 1)^2 + \sum_{i=2}^n i (2 x_i^2 - x_{i-1})^2$$
416 with a search domain of $-10 < x_i < 10, 1 \leq i \leq n$.
417 The global minimum is $f(x^{*}) = 0$ at $x_i = 2^{-(2^i-2)/(2^i)}$ for all $i=1,2,...,n$.
419 return (ind[0] - 1.0)**2 + sum(
420 i * (2 * x**2.0 - previous)**2
421 for i, (previous, x)
in enumerate(zip(ind, ind[1:]), start=2)
423illumination_dixon_price = algorithms.partial(_illuminate_artificial_landscape, func=dixon_price)
425 """Minimise the Dixon–Price objective over adjacent coordinate pairs."""
426 def __init__(self, nb_features: int = 2):
428 ind_domain = (-10., 10.)
429 super().__init__(fn=algorithms.partial(illumination_dixon_price, nb_features=nb_features),
430 ind_domain = ind_domain,
431 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
432 default_task =
"minimisation")
436 r"""Powell function defined as:
437 $$ f(x) = \sum_{i=1}^{n/4} ((x_{4i-3}+10x_{4i-2})^2 + 5(x_{4i-1}-x_{4i})^2 + (x_{4i-2}-2x_{4i-1})^4 + 10(x_{4i-3}-x_{4i})^4)$$
438 with a search domain of $-4 < x_i < 5, 1 \leq i \leq n$.
439 The dimension must be a positive multiple of four.
440 The global minimum is at $f(x_1, ..., x_n) = f(0, ..., 0) = 0.
442 if len(ind) == 0
or len(ind) % 4:
443 raise ValueError(
"Powell requires a positive multiple of four coordinates.")
445 (a + 10.0*b)**2 + 5*(c - float(d))**2 + (b - 2.0*c)**4 + 10*(a - float(d))**4
446 for a, b, c, d
in zip(ind[::4], ind[1::4], ind[2::4], ind[3::4])
448illumination_powell = algorithms.partial(_illuminate_artificial_landscape, func=powell)
450 """Minimise Powell over complete groups of four genome coordinates."""
451 def __init__(self, nb_features: int = 2):
453 ind_domain = (-4., 5.)
454 super().__init__(fn=algorithms.partial(illumination_powell, nb_features=nb_features),
455 ind_domain = ind_domain,
456 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
457 default_task =
"minimisation")
460def michalewicz(ind, m=10.):
461 r"""Michalewicz function defined as:
462 $$ f(x) = - \sum_{i=1}^{n} \sin(x_i) \sin( \frac{i x_i^2}{\pi} )^(2*m)$$
463 with a search domain of $0 < x_i < \pi, 1 \leq i \leq n$.
465 return - sum(( math.sin(ind[i]) * (math.sin(((i+1.)*(ind[i] **2.))/math.pi))**(2.*m)
for i
in range(len(ind)) )),
466illumination_michalewicz = algorithms.partial(_illuminate_artificial_landscape, func=michalewicz)
468 """Minimise the Michalewicz objective with its default steepness parameter."""
469 def __init__(self, nb_features: int = 2):
471 ind_domain = (0., math.pi)
472 super().__init__(fn=algorithms.partial(illumination_michalewicz, nb_features=nb_features),
473 ind_domain = ind_domain,
474 fitness_domain = ((-math.inf, 0.),), features_domain = (ind_domain,) * nb_features,
475 default_task =
"minimisation")
479 r"""Wavy function defined as:
480 $$ f(x) = 1 - \frac{1}{n} \sum_{i=1}^{n} \cos(kx_i)e^{-\frac{x_i^2}{2}}$$
481 with a search domain of $-\pi < x_i < \pi, 1 \leq i \leq n$.
483 return 1. - sum(( math.cos(k * ind[i]) * math.exp(-(ind[i]*ind[i])/2.)
for i
in range(len(ind)))) / float(len(ind)),
484illumination_wavy = algorithms.partial(_illuminate_artificial_landscape, func=wavy)
486 """Minimise the Wavy objective, combining cosine and a Gaussian envelope."""
487 def __init__(self, nb_features: int = 2):
489 ind_domain = (-math.pi, math.pi)
490 super().__init__(fn=algorithms.partial(illumination_wavy, nb_features=nb_features),
491 ind_domain = ind_domain,
492 fitness_domain = ((0., math.inf),), features_domain = (ind_domain,) * nb_features,
493 default_task =
"minimisation")
497def trigonometric02(ind, k=10.):
498 r"""Trigonometric02 function defined as:
499 $$ f(x) = 1 + \sum_{i=1}^n [8\sin^2(7t_i) + 6\sin^2(14t_i) + t_i], \quad t_i = (x_i-0.9)^2.$$
500 The search domain is $[-500, 500]^n$ and the minimum is 1 at $(0.9, ..., 0.9)$.
502 return 1. + sum((8.*math.sin(7. * (ind[i] - 0.9)**2.)**2. + 6.*math.sin(14.*(ind[i]-0.9)**2.)**2. + (ind[i] - 0.9)**2.
for i
in range(len(ind)))),
503illumination_trigonometric02 = algorithms.partial(_illuminate_artificial_landscape, func=trigonometric02)
505 """Minimise the second trigonometric test function with its optimum at 0.9 per coordinate."""
506 def __init__(self, nb_features: int = 2):
508 ind_domain = (-500., 500.)
509 super().__init__(fn=algorithms.partial(illumination_trigonometric02, nb_features=nb_features),
510 ind_domain = ind_domain,
511 fitness_domain = ((1., np.inf),), features_domain = (ind_domain,) * nb_features,
512 default_task =
"minimisation")
517 r"""Qing function defined as:
518 $$ f(x) = \sum_{i=1}^{n} (x_i^2 - i)^2$$
519 with a search domain of $-500 < x_i < 500, 1 \leq i \leq n$.
521 return sum((x**2.0 - i)**2
for i, x
in enumerate(ind, start=1)),
522illumination_qing = algorithms.partial(_illuminate_artificial_landscape, func=qing)
524 """Minimise Qing with coordinate magnitudes given by square roots of one-based indexes."""
525 def __init__(self, nb_features: int = 2):
527 ind_domain = (-500., 500.)
528 super().__init__(fn=algorithms.partial(illumination_qing, nb_features=nb_features),
529 ind_domain = ind_domain,
530 fitness_domain = ((0., np.inf),), features_domain = (ind_domain,) * nb_features,
531 default_task =
"minimisation")
534def small_qing(ind, k=10.):
535 r"""Qing function defined as:
536 $$ f(x) = \sum_{i=1}^{n} (x_i^2 - i)^2$$
537 with a search domain of $-4 < x_i < 4, 1 \leq i \leq n$.
540illumination_small_qing = algorithms.partial(_illuminate_artificial_landscape, func=small_qing)
542 """Minimise Qing on the narrowed coordinate range from -4 to 4."""
543 def __init__(self, nb_features: int = 2):
545 ind_domain = (-4., 4.)
546 super().__init__(fn=algorithms.partial(illumination_small_qing, nb_features=nb_features),
547 ind_domain = ind_domain,
548 fitness_domain = ((0., np.inf),), features_domain = (ind_domain,) * nb_features,
549 default_task =
"minimisation")
555 r"""Deb01 function defined as:
556 $$ f(x) = - \frac{1}{n} \sum_{i=1}^{n} \sin(5 \pi x_i)^6 $$
557 with a search domain of $-1 < x_i < 1, 1 \leq i \leq n$.
559 return -sum(( math.sin(5. * math.pi * ind[i])**6.
for i
in range(len(ind)))) / float(len(ind)),
560illumination_deb01 = algorithms.partial(_illuminate_artificial_landscape, func=deb01)
562 """Minimise the first Deb objective, a negative mean of powered sine terms."""
563 def __init__(self, nb_features: int = 2):
565 ind_domain = (-1., 1.)
566 super().__init__(fn=algorithms.partial(illumination_deb01, nb_features=nb_features),
567 ind_domain = ind_domain,
568 fitness_domain = ((-1., 1.),), features_domain = (ind_domain,) * nb_features,
569 default_task =
"minimisation")
574 r"""Shubert04 function defined as:
575 $$ f(x) = -\sum_{i=1}^n \sum_{j=1}^5 j \cos((j+1)x_i + j) $$
576 with a search domain of $-10 < x_i < 10, 1 \leq i \leq n$.
578 return sum(( sum((-j * math.cos((j+1) * ind[i] + j)
for j
in range(1, 6)))
for i
in range(len(ind)))),
579illumination_shubert04 = algorithms.partial(_illuminate_artificial_landscape, func=shubert04)
581 """Minimise the fourth Shubert variant with a dimension-independent admissible fitness domain."""
582 def __init__(self, nb_features: int = 2):
584 ind_domain = (-10., 10.)
585 super().__init__(fn=algorithms.partial(illumination_shubert04, nb_features=nb_features),
586 ind_domain = ind_domain,
587 fitness_domain = ((-math.inf, math.inf),), features_domain = (ind_domain,) * nb_features,
588 default_task =
"minimisation")