diff --git a/go_benchmark_functions/__init__.py b/go_benchmark_functions/__init__.py new file mode 100644 index 0000000..d4ae32e --- /dev/null +++ b/go_benchmark_functions/__init__.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +""" +============================================================================== +`go_benchmark_functions` -- Problems for testing global optimization routines +============================================================================== + +This module provides a comprehensive set of problems for benchmarking global +optimization routines, such as scipy.optimize.basinhopping, or +scipy.optimize.differential_evolution. The purpose is to see whether a given +optimization routine can find the global minimum, and how many function +evaluations it requires to do so. +The range of problems is extensive, with a range of difficulty. The problems are +multivariate, with N=2 to N=17 provided. + +References +---------- +.. [1] Momin Jamil and Xin-She Yang, A literature survey of benchmark + functions for global optimization problems, Int. Journal of Mathematical + Modelling and Numerical Optimisation, Vol. 4, No. 2, pp. 150--194 (2013). + https://arxiv.org/abs/1308.4008v1 + (and references contained within) +.. [2] http://infinity77.net/global_optimization/ +.. [3] S. K. Mishra, Global Optimization By Differential Evolution and + Particle Swarm Methods: Evaluation On Some Benchmark Functions, Munich + Research Papers in Economics +.. [4] E. P. Adorio, U. P. Dilman, MVF - Multivariate Test Function Library + in C for Unconstrained Global Optimization Methods, [Available Online]: + https://www.geocities.ws/eadorio/mvf.pdf +.. [5] S. K. Mishra, Some New Test Functions For Global Optimization And + Performance of Repulsive Particle Swarm Method, [Available Online]: + https://mpra.ub.uni-muenchen.de/2718/ +.. [6] NIST StRD Nonlinear Regression Problems, retrieved on 1 Oct, 2014 + https://www.itl.nist.gov/div898/strd/nls/nls_main.shtml + +""" + +""" +Copyright 2013 Andrea Gavana +Author: + +Modifications 2014 Andrew Nelson + +""" + +from .go_funcs_A import * +from .go_funcs_B import * +from .go_funcs_C import * +from .go_funcs_D import * +from .go_funcs_E import * +from .go_funcs_F import * +from .go_funcs_G import * +from .go_funcs_H import * +from .go_funcs_I import * +from .go_funcs_J import * +from .go_funcs_K import * +from .go_funcs_L import * +from .go_funcs_M import * +from .go_funcs_N import * +from .go_funcs_O import * +from .go_funcs_P import * +from .go_funcs_Q import * +from .go_funcs_R import * +from .go_funcs_S import * +from .go_funcs_T import * +from .go_funcs_U import * +from .go_funcs_V import * +from .go_funcs_W import * +from .go_funcs_X import * +from .go_funcs_Y import * +from .go_funcs_Z import * + +__all__ = [s for s in dir() if not s.startswith('_')] diff --git a/go_benchmark_functions/go_benchmark.py b/go_benchmark_functions/go_benchmark.py new file mode 100644 index 0000000..0ee1d3c --- /dev/null +++ b/go_benchmark_functions/go_benchmark.py @@ -0,0 +1,207 @@ +# -*- coding: utf-8 -*- +import numpy as np +from numpy import abs, asarray + +from ..common import safe_import + +with safe_import(): + from scipy.special import factorial + + +class Benchmark: + + """ + Defines a global optimization benchmark problem. + + This abstract class defines the basic structure of a global + optimization problem. Subclasses should implement the ``fun`` method + for a particular optimization problem. + + Attributes + ---------- + N : int + The dimensionality of the problem. + bounds : sequence + The lower/upper bounds to be used for minimizing the problem. + This a list of (lower, upper) tuples that contain the lower and upper + bounds for the problem. The problem should not be asked for evaluation + outside these bounds. ``len(bounds) == N``. + xmin : sequence + The lower bounds for the problem + xmax : sequence + The upper bounds for the problem + fglob : float + The global minimum of the evaluated function. + global_optimum : sequence + A list of vectors that provide the locations of the global minimum. + Note that some problems have multiple global minima, not all of which + may be listed. + nfev : int + the number of function evaluations that the object has been asked to + calculate. + change_dimensionality : bool + Whether we can change the benchmark function `x` variable length (i.e., + the dimensionality of the problem) + custom_bounds : sequence + a list of tuples that contain lower/upper bounds for use in plotting. + """ + + def __init__(self, dimensions): + """ + Initialises the problem + + Parameters + ---------- + + dimensions : int + The dimensionality of the problem + """ + + self._dimensions = dimensions + self.nfev = 0 + self.fglob = np.nan + self.global_optimum = None + self.change_dimensionality = False + self.custom_bounds = None + + def __str__(self): + return '{0} ({1} dimensions)'.format(self.__class__.__name__, self.N) + + def __repr__(self): + return self.__class__.__name__ + + def initial_vector(self): + """ + Random initialisation for the benchmark problem. + + Returns + ------- + x : sequence + a vector of length ``N`` that contains random floating point + numbers that lie between the lower and upper bounds for a given + parameter. + """ + + return asarray([np.random.uniform(l, u) for l, u in self.bounds]) + + def success(self, x, tol=1.e-5): + """ + Tests if a candidate solution at the global minimum. + The default test is + + Parameters + ---------- + x : sequence + The candidate vector for testing if the global minimum has been + reached. Must have ``len(x) == self.N`` + tol : float + The evaluated function and known global minimum must differ by less + than this amount to be at a global minimum. + + Returns + ------- + bool : is the candidate vector at the global minimum? + """ + val = self.fun(asarray(x)) + if abs(val - self.fglob) < tol: + return True + + # the solution should still be in bounds, otherwise immediate fail. + if np.any(x > np.asfarray(self.bounds)[:, 1]): + return False + if np.any(x < np.asfarray(self.bounds)[:, 0]): + return False + + # you found a lower global minimum. This shouldn't happen. + if val < self.fglob: + raise ValueError("Found a lower global minimum", + x, + val, + self.fglob) + + return False + + def fun(self, x): + """ + Evaluation of the benchmark function. + + Parameters + ---------- + x : sequence + The candidate vector for evaluating the benchmark problem. Must + have ``len(x) == self.N``. + + Returns + ------- + val : float + the evaluated benchmark function + """ + + raise NotImplementedError + + def change_dimensions(self, ndim): + """ + Changes the dimensionality of the benchmark problem + + The dimensionality will only be changed if the problem is suitable + + Parameters + ---------- + ndim : int + The new dimensionality for the problem. + """ + + if self.change_dimensionality: + self._dimensions = ndim + else: + raise ValueError('dimensionality cannot be changed for this' + 'problem') + + @property + def bounds(self): + """ + The lower/upper bounds to be used for minimizing the problem. + This a list of (lower, upper) tuples that contain the lower and upper + bounds for the problem. The problem should not be asked for evaluation + outside these bounds. ``len(bounds) == N``. + """ + if self.change_dimensionality: + return [self._bounds[0]] * self.N + else: + return self._bounds + + @property + def N(self): + """ + The dimensionality of the problem. + + Returns + ------- + N : int + The dimensionality of the problem + """ + return self._dimensions + + @property + def xmin(self): + """ + The lower bounds for the problem + + Returns + ------- + xmin : sequence + The lower bounds for the problem + """ + return asarray([b[0] for b in self.bounds]) + + @property + def xmax(self): + """ + The upper bounds for the problem + + Returns + ------- + xmax : sequence + The upper bounds for the problem + """ + return asarray([b[1] for b in self.bounds]) diff --git a/go_benchmark_functions/go_funcs_A.py b/go_benchmark_functions/go_funcs_A.py new file mode 100644 index 0000000..43fb070 --- /dev/null +++ b/go_benchmark_functions/go_funcs_A.py @@ -0,0 +1,279 @@ +# -*- coding: utf-8 -*- +from numpy import abs, cos, exp, pi, prod, sin, sqrt, sum +from .go_benchmark import Benchmark + + +class Ackley01(Benchmark): + + r""" + Ackley01 objective function. + + The Ackley01 [1]_ global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Ackley01}}(x) = -20 e^{-0.2 \sqrt{\frac{1}{n} \sum_{i=1}^n + x_i^2}} - e^{\frac{1}{n} \sum_{i=1}^n \cos(2 \pi x_i)} + 20 + e + + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in + [-35, 35]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Adorio, E. MVF - "Multivariate Test Functions Library in C for + Unconstrained Global Optimization", 2005 + + TODO: the -0.2 factor in the exponent of the first term is given as + -0.02 in Jamil et al. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-35.0] * self.N, [35.0] * self.N)) + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + u = sum(x ** 2) + v = sum(cos(2 * pi * x)) + return (-20. * exp(-0.2 * sqrt(u / self.N)) + - exp(v / self.N) + 20. + exp(1.)) + + +class Ackley02(Benchmark): + + r""" + Ackley02 objective function. + + The Ackley02 [1]_ global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Ackley02}(x) = -200 e^{-0.02 \sqrt{x_1^2 + x_2^2}} + + + with :math:`x_i \in [-32, 32]` for :math:`i=1, 2`. + + *Global optimum*: :math:`f(x) = -200` for :math:`x = [0, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + """ + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-32.0] * self.N, [32.0] * self.N)) + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = -200. + + def fun(self, x, *args): + self.nfev += 1 + return -200 * exp(-0.02 * sqrt(x[0] ** 2 + x[1] ** 2)) + + +class Ackley03(Benchmark): + + r""" + Ackley03 [1]_ objective function. + + The Ackley03 global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Ackley03}}(x) = -200 e^{-0.02 \sqrt{x_1^2 + x_2^2}} + + 5e^{\cos(3x_1) + \sin(3x_2)} + + + with :math:`x_i \in [-32, 32]` for :math:`i=1, 2`. + + *Global optimum*: :math:`f(x) = -195.62902825923879` for :math:`x + = [-0.68255758, -0.36070859]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: I think the minus sign is missing in front of the first term in eqn3 + in [1]_. This changes the global minimum + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-32.0] * self.N, [32.0] * self.N)) + self.global_optimum = [[-0.68255758, -0.36070859]] + self.fglob = -195.62902825923879 + + def fun(self, x, *args): + self.nfev += 1 + a = -200 * exp(-0.02 * sqrt(x[0] ** 2 + x[1] ** 2)) + a += 5 * exp(cos(3 * x[0]) + sin(3 * x[1])) + return a + + +class Adjiman(Benchmark): + + r""" + Adjiman objective function. + + The Adjiman [1]_ global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Adjiman}}(x) = \cos(x_1)\sin(x_2) - \frac{x_1}{(x_2^2 + 1)} + + + with, :math:`x_1 \in [-1, 2]` and :math:`x_2 \in [-1, 1]`. + + *Global optimum*: :math:`f(x) = -2.02181` for :math:`x = [2.0, 0.10578]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = ([-1.0, 2.0], [-1.0, 1.0]) + self.global_optimum = [[2.0, 0.10578]] + self.fglob = -2.02180678 + + def fun(self, x, *args): + self.nfev += 1 + return cos(x[0]) * sin(x[1]) - x[0] / (x[1] ** 2 + 1) + + +class Alpine01(Benchmark): + + r""" + Alpine01 objective function. + + The Alpine01 [1]_ global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Alpine01}}(x) = \sum_{i=1}^{n} \lvert {x_i \sin \left( x_i + \right) + 0.1 x_i} \rvert + + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in + [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(abs(x * sin(x) + 0.1 * x)) + + +class Alpine02(Benchmark): + + r""" + Alpine02 objective function. + + The Alpine02 [1]_ global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Alpine02}(x) = \prod_{i=1}^{n} \sqrt{x_i} \sin(x_i) + + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in [0, + 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = -6.1295` for :math:`x = + [7.91705268, 4.81584232]` for :math:`i = 1, 2` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: eqn 7 in [1]_ has the wrong global minimum value. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [10.0] * self.N)) + self.global_optimum = [[7.91705268, 4.81584232]] + self.fglob = -6.12950 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return prod(sqrt(x) * sin(x)) + + +class AMGM(Benchmark): + + r""" + AMGM objective function. + + The AMGM (Arithmetic Mean - Geometric Mean Equality) global optimization + problem is a multimodal minimization problem defined as follows + + .. math:: + + f_{\text{AMGM}}(x) = \left ( \frac{1}{n} \sum_{i=1}^{n} x_i - + \sqrt[n]{ \prod_{i=1}^{n} x_i} \right )^2 + + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in + [0, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_1 = x_2 = ... = x_n` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO, retrieved 2015 + + TODO: eqn 7 in [1]_ has the wrong global minimum value. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [10.0] * self.N)) + self.global_optimum = [[1, 1]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + f1 = sum(x) + f2 = prod(x) + f1 = f1 / self.N + f2 = f2 ** (1.0 / self.N) + f = (f1 - f2) ** 2 + + return f diff --git a/go_benchmark_functions/go_funcs_B.py b/go_benchmark_functions/go_funcs_B.py new file mode 100644 index 0000000..a58e509 --- /dev/null +++ b/go_benchmark_functions/go_funcs_B.py @@ -0,0 +1,759 @@ +# -*- coding: utf-8 -*- +from numpy import abs, cos, exp, log, arange, pi, sin, sqrt, sum +from .go_benchmark import Benchmark + + +class BartelsConn(Benchmark): + + r""" + Bartels-Conn objective function. + + The BartelsConn [1]_ global optimization problem is a multimodal + minimization problem defined as follows: + + .. math:: + + f_{\text{BartelsConn}}(x) = \lvert {x_1^2 + x_2^2 + x_1x_2} \rvert + + \lvert {\sin(x_1)} \rvert + \lvert {\cos(x_2)} \rvert + + + with :math:`x_i \in [-500, 500]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 1` for :math:`x = [0, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-500.] * self.N, [500.] * self.N)) + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 1.0 + + def fun(self, x, *args): + self.nfev += 1 + + return (abs(x[0] ** 2.0 + x[1] ** 2.0 + x[0] * x[1]) + abs(sin(x[0])) + + abs(cos(x[1]))) + + +class Beale(Benchmark): + + r""" + Beale objective function. + + The Beale [1]_ global optimization problem is a multimodal + minimization problem defined as follows: + + .. math:: + + f_{\text{Beale}}(x) = \left(x_1 x_2 - x_1 + 1.5\right)^{2} + + \left(x_1 x_2^{2} - x_1 + 2.25\right)^{2} + \left(x_1 x_2^{3} - x_1 + + 2.625\right)^{2} + + + with :math:`x_i \in [-4.5, 4.5]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x=[3, 0.5]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-4.5] * self.N, [4.5] * self.N)) + self.global_optimum = [[3.0, 0.5]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return ((1.5 - x[0] + x[0] * x[1]) ** 2 + + (2.25 - x[0] + x[0] * x[1] ** 2) ** 2 + + (2.625 - x[0] + x[0] * x[1] ** 3) ** 2) + + +class BiggsExp02(Benchmark): + + r""" + BiggsExp02 objective function. + + The BiggsExp02 [1]_ global optimization problem is a multimodal minimization + problem defined as follows + + .. math:: + + \begin{matrix} + f_{\text{BiggsExp02}}(x) = \sum_{i=1}^{10} (e^{-t_i x_1} + - 5 e^{-t_i x_2} - y_i)^2 \\ + t_i = 0.1 i\\ + y_i = e^{-t_i} - 5 e^{-10t_i}\\ + \end{matrix} + + + with :math:`x_i \in [0, 20]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 10]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0] * 2, + [20] * 2)) + self.global_optimum = [[1., 10.]] + self.fglob = 0 + + def fun(self, x, *args): + self.nfev += 1 + + t = arange(1, 11.) * 0.1 + y = exp(-t) - 5 * exp(-10 * t) + vec = (exp(-t * x[0]) - 5 * exp(-t * x[1]) - y) ** 2 + + return sum(vec) + + +class BiggsExp03(Benchmark): + + r""" + BiggsExp03 objective function. + + The BiggsExp03 [1]_ global optimization problem is a multimodal minimization + problem defined as follows + + .. math:: + + \begin{matrix}\ f_{\text{BiggsExp03}}(x) = \sum_{i=1}^{10} + (e^{-t_i x_1} - x_3e^{-t_i x_2} - y_i)^2\\ + t_i = 0.1i\\ + y_i = e^{-t_i} - 5e^{-10 t_i}\\ + \end{matrix} + + + with :math:`x_i \in [0, 20]` for :math:`i = 1, 2, 3`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 10, 5]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + """ + + def __init__(self, dimensions=3): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0] * 3, + [20] * 3)) + self.global_optimum = [[1., 10., 5.]] + self.fglob = 0 + + def fun(self, x, *args): + self.nfev += 1 + + t = arange(1., 11.) * 0.1 + y = exp(-t) - 5 * exp(-10 * t) + vec = (exp(-t * x[0]) - x[2] * exp(-t * x[1]) - y) ** 2 + + return sum(vec) + + +class BiggsExp04(Benchmark): + + r""" + BiggsExp04 objective function. + + The BiggsExp04 [1]_ global optimization problem is a multimodal + minimization problem defined as follows + + .. math:: + + \begin{matrix}\ f_{\text{BiggsExp04}}(x) = \sum_{i=1}^{10} + (x_3 e^{-t_i x_1} - x_4 e^{-t_i x_2} - y_i)^2\\ + t_i = 0.1i\\ + y_i = e^{-t_i} - 5 e^{-10 t_i}\\ + \end{matrix} + + + with :math:`x_i \in [0, 20]` for :math:`i = 1, ..., 4`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 10, 1, 5]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + """ + + def __init__(self, dimensions=4): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.] * 4, + [20.] * 4)) + self.global_optimum = [[1., 10., 1., 5.]] + self.fglob = 0 + + def fun(self, x, *args): + self.nfev += 1 + + t = arange(1, 11.) * 0.1 + y = exp(-t) - 5 * exp(-10 * t) + vec = (x[2] * exp(-t * x[0]) - x[3] * exp(-t * x[1]) - y) ** 2 + + return sum(vec) + + +class BiggsExp05(Benchmark): + + r""" + BiggsExp05 objective function. + + The BiggsExp05 [1]_ global optimization problem is a multimodal minimization + problem defined as follows + + .. math:: + + \begin{matrix}\ f_{\text{BiggsExp05}}(x) = \sum_{i=1}^{11} + (x_3 e^{-t_i x_1} - x_4 e^{-t_i x_2} + 3 e^{-t_i x_5} - y_i)^2\\ + t_i = 0.1i\\ + y_i = e^{-t_i} - 5e^{-10 t_i} + 3e^{-4 t_i}\\ + \end{matrix} + + + with :math:`x_i \in [0, 20]` for :math:`i=1, ..., 5`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 10, 1, 5, 4]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + """ + + def __init__(self, dimensions=5): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.] * 5, + [20.] * 5)) + self.global_optimum = [[1., 10., 1., 5., 4.]] + self.fglob = 0 + + def fun(self, x, *args): + self.nfev += 1 + t = arange(1, 12.) * 0.1 + y = exp(-t) - 5 * exp(-10 * t) + 3 * exp(-4 * t) + vec = (x[2] * exp(-t * x[0]) - x[3] * exp(-t * x[1]) + + 3 * exp(-t * x[4]) - y) ** 2 + + return sum(vec) + + +class Bird(Benchmark): + + r""" + Bird objective function. + + The Bird global optimization problem is a multimodal minimization + problem defined as follows + + .. math:: + + f_{\text{Bird}}(x) = \left(x_1 - x_2\right)^{2} + e^{\left[1 - + \sin\left(x_1\right) \right]^{2}} \cos\left(x_2\right) + e^{\left[1 - + \cos\left(x_2\right)\right]^{2}} \sin\left(x_1\right) + + + with :math:`x_i \in [-2\pi, 2\pi]` + + *Global optimum*: :math:`f(x) = -106.7645367198034` for :math:`x + = [4.701055751981055, 3.152946019601391]` or :math:`x = + [-1.582142172055011, -3.130246799635430]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-2.0 * pi] * self.N, + [2.0 * pi] * self.N)) + self.global_optimum = [[4.701055751981055, 3.152946019601391], + [-1.582142172055011, -3.130246799635430]] + self.fglob = -106.7645367198034 + + def fun(self, x, *args): + self.nfev += 1 + + return (sin(x[0]) * exp((1 - cos(x[1])) ** 2) + + cos(x[1]) * exp((1 - sin(x[0])) ** 2) + (x[0] - x[1]) ** 2) + + +class Bohachevsky1(Benchmark): + + r""" + Bohachevsky 1 objective function. + + The Bohachevsky 1 [1]_ global optimization problem is a multimodal + minimization problem defined as follows + + .. math:: + + f_{\text{Bohachevsky}}(x) = \sum_{i=1}^{n-1}\left[x_i^2 + 2 x_{i+1}^2 - + 0.3 \cos(3 \pi x_i) - 0.4 \cos(4 \pi x_{i + 1}) + 0.7 \right] + + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in + [-15, 15]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for :math:`i = 1, + ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: equation needs to be fixed up in the docstring. see Jamil#17 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, [100.0] * self.N)) + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return (x[0] ** 2 + 2 * x[1] ** 2 - 0.3 * cos(3 * pi * x[0]) + - 0.4 * cos(4 * pi * x[1]) + 0.7) + + +class Bohachevsky2(Benchmark): + + r""" + Bohachevsky 2 objective function. + + The Bohachevsky 2 [1]_ global optimization problem is a multimodal + minimization problem defined as follows + + .. math:: + + f_{\text{Bohachevsky}}(x) = \sum_{i=1}^{n-1}\left[x_i^2 + 2 x_{i+1}^2 - + 0.3 \cos(3 \pi x_i) - 0.4 \cos(4 \pi x_{i + 1}) + 0.7 \right] + + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in + [-15, 15]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for :math:`i = 1, + ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: equation needs to be fixed up in the docstring. Jamil is also wrong. + There should be no 0.4 factor in front of the cos term + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, [100.0] * self.N)) + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return (x[0] ** 2 + 2 * x[1] ** 2 - 0.3 * cos(3 * pi * x[0]) + * cos(4 * pi * x[1]) + 0.3) + + +class Bohachevsky3(Benchmark): + + r""" + Bohachevsky 3 objective function. + + The Bohachevsky 3 [1]_ global optimization problem is a multimodal + minimization problem defined as follows + + .. math:: + + f_{\text{Bohachevsky}}(x) = \sum_{i=1}^{n-1}\left[x_i^2 + 2 x_{i+1}^2 - + 0.3 \cos(3 \pi x_i) - 0.4 \cos(4 \pi x_{i + 1}) + 0.7 \right] + + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in + [-15, 15]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for :math:`i = 1, + ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: equation needs to be fixed up in the docstring. Jamil#19 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, [100.0] * self.N)) + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return (x[0] ** 2 + 2 * x[1] ** 2 + - 0.3 * cos(3 * pi * x[0] + 4 * pi * x[1]) + 0.3) + + +class BoxBetts(Benchmark): + + r""" + BoxBetts objective function. + + The BoxBetts global optimization problem is a multimodal + minimization problem defined as follows + + .. math:: + + f_{\text{BoxBetts}}(x) = \sum_{i=1}^k g(x_i)^2 + + + Where, in this exercise: + + .. math:: + + g(x) = e^{-0.1i x_1} - e^{-0.1i x_2} - x_3\left[e^{-0.1i} + - e^{-i}\right] + + + And :math:`k = 10`. + + Here, :math:`x_1 \in [0.9, 1.2], x_2 \in [9, 11.2], x_3 \in [0.9, 1.2]`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 10, 1]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=3): + Benchmark.__init__(self, dimensions) + + self._bounds = ([0.9, 1.2], [9.0, 11.2], [0.9, 1.2]) + self.global_optimum = [[1.0, 10.0, 1.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + i = arange(1, 11) + g = (exp(-0.1 * i * x[0]) - exp(-0.1 * i * x[1]) + - (exp(-0.1 * i) - exp(-i)) * x[2]) + return sum(g**2) + + +class Branin01(Benchmark): + + r""" + Branin01 objective function. + + The Branin01 global optimization problem is a multimodal minimization + problem defined as follows + + .. math:: + + f_{\text{Branin01}}(x) = \left(- 1.275 \frac{x_1^{2}}{\pi^{2}} + 5 + \frac{x_1}{\pi} + x_2 -6\right)^{2} + \left(10 -\frac{5}{4 \pi} \right) + \cos\left(x_1\right) + 10 + + + with :math:`x_1 \in [-5, 10], x_2 \in [0, 15]` + + *Global optimum*: :math:`f(x) = 0.39788735772973816` for :math:`x = + [-\pi, 12.275]` or :math:`x = [\pi, 2.275]` or :math:`x = [3\pi, 2.475]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: Jamil#22, one of the solutions is different + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-5., 10.), (0., 15.)] + + self.global_optimum = [[-pi, 12.275], [pi, 2.275], [3 * pi, 2.475]] + self.fglob = 0.39788735772973816 + + def fun(self, x, *args): + self.nfev += 1 + + return ((x[1] - (5.1 / (4 * pi ** 2)) * x[0] ** 2 + + 5 * x[0] / pi - 6) ** 2 + + 10 * (1 - 1 / (8 * pi)) * cos(x[0]) + 10) + + +class Branin02(Benchmark): + + r""" + Branin02 objective function. + + The Branin02 global optimization problem is a multimodal minimization + problem defined as follows + + .. math:: + + f_{\text{Branin02}}(x) = \left(- 1.275 \frac{x_1^{2}}{\pi^{2}} + + 5 \frac{x_1}{\pi} + x_2 - 6 \right)^{2} + \left(10 - \frac{5}{4 \pi} + \right) \cos\left(x_1\right) \cos\left(x_2\right) + + \log(x_1^2+x_2^2 + 1) + 10 + + + with :math:`x_i \in [-5, 15]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 5.559037` for :math:`x = [-3.2, 12.53]` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-5.0, 15.0), (-5.0, 15.0)] + + self.global_optimum = [[-3.1969884, 12.52625787]] + self.fglob = 5.5589144038938247 + + def fun(self, x, *args): + self.nfev += 1 + + return ((x[1] - (5.1 / (4 * pi ** 2)) * x[0] ** 2 + + 5 * x[0] / pi - 6) ** 2 + + 10 * (1 - 1 / (8 * pi)) * cos(x[0]) * cos(x[1]) + + log(x[0] ** 2.0 + x[1] ** 2.0 + 1.0) + 10) + + +class Brent(Benchmark): + + r""" + Brent objective function. + + The Brent [1]_ global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Brent}}(x) = (x_1 + 10)^2 + (x_2 + 10)^2 + e^{(-x_1^2 -x_2^2)} + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [-10, -10]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO solution is different to Jamil#24 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = ([-10, 2], [-10, 2]) + + self.global_optimum = [[-10.0, -10.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + return ((x[0] + 10.0) ** 2.0 + (x[1] + 10.0) ** 2.0 + + exp(-x[0] ** 2.0 - x[1] ** 2.0)) + + +class Brown(Benchmark): + + r""" + Brown objective function. + + The Brown [1]_ global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Brown}}(x) = \sum_{i=1}^{n-1}\left[ + \left(x_i^2\right)^{x_{i + 1}^2 + 1} + + \left(x_{i + 1}^2\right)^{x_i^2 + 1}\right] + + + with :math:`x_i \in [-1, 4]` for :math:`i=1,...,n`. + + *Global optimum*: :math:`f(x_i) = 0` for :math:`x_i = 0` for + :math:`i=1,...,n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-1.0] * self.N, [4.0] * self.N)) + self.custom_bounds = ([-1.0, 1.0], [-1.0, 1.0]) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + x0 = x[:-1] + x1 = x[1:] + return sum((x0 ** 2.0) ** (x1 ** 2.0 + 1.0) + + (x1 ** 2.0) ** (x0 ** 2.0 + 1.0)) + + +class Bukin02(Benchmark): + + r""" + Bukin02 objective function. + + The Bukin02 [1]_ global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Bukin02}}(x) = 100 (x_2^2 - 0.01x_1^2 + 1) + + 0.01(x_1 + 10)^2 + + + with :math:`x_1 \in [-15, -5], x_2 \in [-3, 3]` + + *Global optimum*: :math:`f(x) = -124.75` for :math:`x = [-15, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: I think that Gavana and Jamil are wrong on this function. In both + sources the x[1] term is not squared. As such there will be a minimum at + the smallest value of x[1]. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-15.0, -5.0), (-3.0, 3.0)] + + self.global_optimum = [[-15.0, 0.0]] + self.fglob = -124.75 + + def fun(self, x, *args): + + self.nfev += 1 + return (100 * (x[1] ** 2 - 0.01 * x[0] ** 2 + 1.0) + + 0.01 * (x[0] + 10.0) ** 2.0) + + +class Bukin04(Benchmark): + + r""" + Bukin04 objective function. + + The Bukin04 [1]_ global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Bukin04}}(x) = 100 x_2^{2} + 0.01 \lvert{x_1 + 10} + \rvert + + + with :math:`x_1 \in [-15, -5], x_2 \in [-3, 3]` + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [-10, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-15.0, -5.0), (-3.0, 3.0)] + + self.global_optimum = [[-10.0, 0.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + + self.nfev += 1 + return 100 * x[1] ** 2 + 0.01 * abs(x[0] + 10) + + +class Bukin06(Benchmark): + + r""" + Bukin06 objective function. + + The Bukin06 [1]_ global optimization problem is a multimodal minimization + problem defined as follows: + + .. math:: + + f_{\text{Bukin06}}(x) = 100 \sqrt{ \lvert{x_2 - 0.01 x_1^{2}} + \rvert} + 0.01 \lvert{x_1 + 10} \rvert + + + with :math:`x_1 \in [-15, -5], x_2 \in [-3, 3]` + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [-10, 1]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-15.0, -5.0), (-3.0, 3.0)] + self.global_optimum = [[-10.0, 1.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + + self.nfev += 1 + return 100 * sqrt(abs(x[1] - 0.01 * x[0] ** 2)) + 0.01 * abs(x[0] + 10) diff --git a/go_benchmark_functions/go_funcs_C.py b/go_benchmark_functions/go_funcs_C.py new file mode 100644 index 0000000..2ba4d8c --- /dev/null +++ b/go_benchmark_functions/go_funcs_C.py @@ -0,0 +1,578 @@ +# -*- coding: utf-8 -*- +import numpy as np +from numpy import (abs, asarray, cos, exp, floor, pi, sign, sin, sqrt, sum, + size, tril, isnan, atleast_2d, repeat) +from numpy.testing import assert_almost_equal + +from .go_benchmark import Benchmark + + +class CarromTable(Benchmark): + r""" + CarromTable objective function. + + The CarromTable [1]_ global optimization problem is a multimodal + minimization problem defined as follows: + + .. math:: + + f_{\text{CarromTable}}(x) = - \frac{1}{30}\left(\cos(x_1) + cos(x_2) e^{\left|1 - \frac{\sqrt{x_1^2 + x_2^2}}{\pi}\right|}\right)^2 + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -24.15681551650653` for :math:`x_i = \pm + 9.646157266348881` for :math:`i = 1, 2` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.global_optimum = [(9.646157266348881, 9.646134286497169), + (-9.646157266348881, 9.646134286497169), + (9.646157266348881, -9.646134286497169), + (-9.646157266348881, -9.646134286497169)] + self.fglob = -24.15681551650653 + + def fun(self, x, *args): + self.nfev += 1 + + u = cos(x[0]) * cos(x[1]) + v = sqrt(x[0] ** 2 + x[1] ** 2) + return -((u * exp(abs(1 - v / pi))) ** 2) / 30. + + +class Chichinadze(Benchmark): + r""" + Chichinadze objective function. + + This class defines the Chichinadze [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Chichinadze}}(x) = x_{1}^{2} - 12 x_{1} + + 8 \sin\left(\frac{5}{2} \pi x_{1}\right) + + 10 \cos\left(\frac{1}{2} \pi x_{1}\right) + 11 + - 0.2 \frac{\sqrt{5}}{e^{\frac{1}{2} \left(x_{2} -0.5 \right)^{2}}} + + + with :math:`x_i \in [-30, 30]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -42.94438701899098` for :math:`x = + [6.189866586965680, 0.5]` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO: Jamil#33 has a dividing factor of 2 in the sin term. However, f(x) + for the given solution does not give the global minimum. i.e. the equation + is at odds with the solution. + Only by removing the dividing factor of 2, i.e. `8 * sin(5 * pi * x[0])` + does the given solution result in the given global minimum. + Do we keep the result or equation? + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-30.0] * self.N, [30.0] * self.N)) + self.custom_bounds = [(-10, 10), (-10, 10)] + + self.global_optimum = [[6.189866586965680, 0.5]] + self.fglob = -42.94438701899098 + + def fun(self, x, *args): + self.nfev += 1 + + return (x[0] ** 2 - 12 * x[0] + 11 + 10 * cos(pi * x[0] / 2) + + 8 * sin(5 * pi * x[0] / 2) + - 1.0 / sqrt(5) * exp(-((x[1] - 0.5) ** 2) / 2)) + + +class Cigar(Benchmark): + r""" + Cigar objective function. + + This class defines the Cigar [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Cigar}}(x) = x_1^2 + 10^6\sum_{i=2}^{n} x_i^2 + + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in + [-100, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = [(-5, 5), (-5, 5)] + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return x[0] ** 2 + 1e6 * sum(x[1:] ** 2) + + +class Cola(Benchmark): + r""" + Cola objective function. + + This class defines the Cola global optimization problem. The 17-dimensional + function computes indirectly the formula :math:`f(n, u)` by setting + :math:`x_0 = y_0, x_1 = u_0, x_i = u_{2(i2)}, y_i = u_{2(i2)+1}` : + + .. math:: + + f_{\text{Cola}}(x) = \sum_{i 0 \\ + \pi + \arctan(y/x) & \textrm{for } x < 0 \end{cases} + + with :math:`x_i \in [-100, 100]` for :math:`i = 1, 2, 3`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 0, 0]` + + .. [1] Fletcher, R. & Powell, M. A Rapidly Convergent Descent Method for + Minimzation, Computer Journal, 1963, 62, 163-168 + + TODO: Jamil equation is different to original reference. The above paper + can be obtained from + http://galton.uchicago.edu/~lekheng/courses/302/classics/ + fletcher-powell.pdf + """ + + def __init__(self, dimensions=3): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.] * self.N, [10.] * self.N)) + + self.global_optimum = [[1.0, 0.0, 0.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + r = sqrt(x[0] ** 2 + x[1] ** 2) + theta = 1 / (2. * pi) * arctan2(x[1], x[0]) + + return x[2] ** 2 + 100 * ((x[2] - 10 * theta) ** 2 + (r - 1) ** 2) + + +class HimmelBlau(Benchmark): + + r""" + HimmelBlau objective function. + + This class defines the HimmelBlau [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{HimmelBlau}}({x}) = (x_1^2 + x_2 - 11)^2 + (x_1 + x_2^2 - 7)^2 + + + with :math:`x_i \in [-6, 6]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [3, 2]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.] * self.N, [5.] * self.N)) + + self.global_optimum = [[3.0, 2.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return (x[0] ** 2 + x[1] - 11) ** 2 + (x[0] + x[1] ** 2 - 7) ** 2 + + +class HolderTable(Benchmark): + + r""" + HolderTable objective function. + + This class defines the HolderTable [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{HolderTable}}({x}) = - \left|{e^{\left|{1 + - \frac{\sqrt{x_{1}^{2} + x_{2}^{2}}}{\pi} }\right|} + \sin\left(x_{1}\right) \cos\left(x_{2}\right)}\right| + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -19.20850256788675` for + :math:`x_i = \pm 9.664590028909654` for :math:`i = 1, 2` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO: Jamil #146 equation is wrong - should be squaring the x1 and x2 + terms, but isn't. Gavana does. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [(8.055023472141116, 9.664590028909654), + (-8.055023472141116, 9.664590028909654), + (8.055023472141116, -9.664590028909654), + (-8.055023472141116, -9.664590028909654)] + self.fglob = -19.20850256788675 + + def fun(self, x, *args): + self.nfev += 1 + + return -abs(sin(x[0]) * cos(x[1]) + * exp(abs(1 - sqrt(x[0] ** 2 + x[1] ** 2) / pi))) + + +class Hosaki(Benchmark): + + r""" + Hosaki objective function. + + This class defines the Hosaki [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Hosaki}}(x) = \left ( 1 - 8 x_1 + 7 x_1^2 - \frac{7}{3} x_1^3 + + \frac{1}{4} x_1^4 \right ) x_2^2 e^{-x_1} + + + with :math:`x_i \in [0, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -2.3458115` for :math:`x = [4, 2]`. + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = ([0., 5.], [0., 6.]) + self.custom_bounds = [(0, 5), (0, 5)] + + self.global_optimum = [[4, 2]] + self.fglob = -2.3458115 + + def fun(self, x, *args): + self.nfev += 1 + + val = (1 - 8 * x[0] + 7 * x[0] ** 2 - 7 / 3. * x[0] ** 3 + + 0.25 * x[0] ** 4) + return val * x[1] ** 2 * exp(-x[1]) diff --git a/go_benchmark_functions/go_funcs_I.py b/go_benchmark_functions/go_funcs_I.py new file mode 100644 index 0000000..81d2ae7 --- /dev/null +++ b/go_benchmark_functions/go_funcs_I.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +from numpy import sin, sum +from .go_benchmark import Benchmark + + +class Infinity(Benchmark): + + r""" + Infinity objective function. + + This class defines the Infinity [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Infinity}}(x) = \sum_{i=1}^{n} x_i^{6} + \left [ \sin\left ( \frac{1}{x_i} \right ) + 2 \right ] + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-1, 1]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-1.0] * self.N, [1.0] * self.N)) + + self.global_optimum = [[1e-16 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(x ** 6.0 * (sin(1.0 / x) + 2.0)) diff --git a/go_benchmark_functions/go_funcs_J.py b/go_benchmark_functions/go_funcs_J.py new file mode 100644 index 0000000..a83d4e2 --- /dev/null +++ b/go_benchmark_functions/go_funcs_J.py @@ -0,0 +1,107 @@ +# -*- coding: utf-8 -*- +from numpy import sum, asarray, arange, exp +from .go_benchmark import Benchmark + + +class JennrichSampson(Benchmark): + r""" + Jennrich-Sampson objective function. + + This class defines the Jennrich-Sampson [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{JennrichSampson}}(x) = \sum_{i=1}^{10} \left [2 + 2i + - (e^{ix_1} + e^{ix_2}) \right ]^2 + + + with :math:`x_i \in [-1, 1]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 124.3621824` for + :math:`x = [0.257825, 0.257825]`. + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-1.0] * self.N, [1.0] * self.N)) + + self.global_optimum = [[0.257825, 0.257825]] + self.custom_bounds = [(-1, 0.34), (-1, 0.34)] + self.fglob = 124.3621824 + + def fun(self, x, *args): + self.nfev += 1 + + i = arange(1, 11) + return sum((2 + 2 * i - (exp(i * x[0]) + exp(i * x[1]))) ** 2) + + +class Judge(Benchmark): + r""" + Judge objective function. + + This class defines the Judge [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Judge}}(x) = \sum_{i=1}^{20} + \left [ \left (x_1 + A_i x_2 + B x_2^2 \right ) - C_i \right ]^2 + + + Where, in this exercise: + + .. math:: + + \begin{cases} + C = [4.284, 4.149, 3.877, 0.533, 2.211, 2.389, 2.145, + 3.231, 1.998, 1.379, 2.106, 1.428, 1.011, 2.179, 2.858, 1.388, 1.651, + 1.593, 1.046, 2.152] \\ + A = [0.286, 0.973, 0.384, 0.276, 0.973, 0.543, 0.957, 0.948, 0.543, + 0.797, 0.936, 0.889, 0.006, 0.828, 0.399, 0.617, 0.939, 0.784, + 0.072, 0.889] \\ + B = [0.645, 0.585, 0.310, 0.058, 0.455, 0.779, 0.259, 0.202, 0.028, + 0.099, 0.142, 0.296, 0.175, 0.180, 0.842, 0.039, 0.103, 0.620, + 0.158, 0.704] + \end{cases} + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x_i) = 16.0817307` for + :math:`\mathbf{x} = [0.86479, 1.2357]`. + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[0.86479, 1.2357]] + self.custom_bounds = [(-2.0, 2.0), (-2.0, 2.0)] + self.fglob = 16.0817307 + self.c = asarray([4.284, 4.149, 3.877, 0.533, 2.211, 2.389, 2.145, + 3.231, 1.998, 1.379, 2.106, 1.428, 1.011, 2.179, + 2.858, 1.388, 1.651, 1.593, 1.046, 2.152]) + + self.a = asarray([0.286, 0.973, 0.384, 0.276, 0.973, 0.543, 0.957, + 0.948, 0.543, 0.797, 0.936, 0.889, 0.006, 0.828, + 0.399, 0.617, 0.939, 0.784, 0.072, 0.889]) + + self.b = asarray([0.645, 0.585, 0.310, 0.058, 0.455, 0.779, 0.259, + 0.202, 0.028, 0.099, 0.142, 0.296, 0.175, 0.180, + 0.842, 0.039, 0.103, 0.620, 0.158, 0.704]) + + def fun(self, x, *args): + self.nfev += 1 + + return sum(((x[0] + x[1] * self.a + (x[1] ** 2.0) * self.b) - self.c) + ** 2.0) diff --git a/go_benchmark_functions/go_funcs_K.py b/go_benchmark_functions/go_funcs_K.py new file mode 100644 index 0000000..f3425e3 --- /dev/null +++ b/go_benchmark_functions/go_funcs_K.py @@ -0,0 +1,149 @@ +# -*- coding: utf-8 -*- +from numpy import asarray, atleast_2d, arange, sin, sqrt, prod, sum, round +from .go_benchmark import Benchmark + + +class Katsuura(Benchmark): + + r""" + Katsuura objective function. + + This class defines the Katsuura [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Katsuura}}(x) = \prod_{i=0}^{n-1} \left [ 1 + + (i+1) \sum_{k=1}^{d} \lfloor (2^k x_i) \rfloor 2^{-k} \right ] + + + Where, in this exercise, :math:`d = 32`. + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [0, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 1` for :math:`x_i = 0` for + :math:`i = 1, ..., n`. + + .. [1] Adorio, E. MVF - "Multivariate Test Functions Library in C for + Unconstrained Global Optimization", 2005 + .. [2] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO: Adorio has wrong global minimum. Adorio uses round, Gavana docstring + uses floor, but Gavana code uses round. We'll use round... + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [100.0] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.custom_bounds = [(0, 1), (0, 1)] + self.fglob = 1.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + d = 32 + k = atleast_2d(arange(1, d + 1)).T + i = arange(0., self.N * 1.) + inner = round(2 ** k * x) * (2. ** (-k)) + return prod(sum(inner, axis=0) * (i + 1) + 1) + + +class Keane(Benchmark): + + r""" + Keane objective function. + + This class defines the Keane [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Keane}}(x) = \frac{\sin^2(x_1 - x_2)\sin^2(x_1 + x_2)} + {\sqrt{x_1^2 + x_2^2}} + + + with :math:`x_i \in [0, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0.0` for + :math:`x = [7.85396153, 7.85396135]`. + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: Jamil #69, there is no way that the function can have a negative + value. Everything is squared. I think that they have the wrong solution. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[7.85396153, 7.85396135]] + self.custom_bounds = [(-1, 0.34), (-1, 0.34)] + self.fglob = 0. + + def fun(self, x, *args): + self.nfev += 1 + + val = sin(x[0] - x[1]) ** 2 * sin(x[0] + x[1]) ** 2 + return val / sqrt(x[0] ** 2 + x[1] ** 2) + + +class Kowalik(Benchmark): + + r""" + Kowalik objective function. + + This class defines the Kowalik [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Kowalik}}(x) = \sum_{i=0}^{10} \left [ a_i + - \frac{x_1 (b_i^2 + b_i x_2)} {b_i^2 + b_i x_3 + x_4} \right ]^2 + + Where: + + .. math:: + + \begin{matrix} + a = [4, 2, 1, 1/2, 1/4 1/8, 1/10, 1/12, 1/14, 1/16] \\ + b = [0.1957, 0.1947, 0.1735, 0.1600, 0.0844, 0.0627, + 0.0456, 0.0342, 0.0323, 0.0235, 0.0246]\\ + \end{matrix} + + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in + [-5, 5]` for :math:`i = 1, ..., 4`. + + *Global optimum*: :math:`f(x) = 0.00030748610` for :math:`x = + [0.192833, 0.190836, 0.123117, 0.135766]`. + + ..[1] https://www.itl.nist.gov/div898/strd/nls/data/mgh09.shtml + """ + + def __init__(self, dimensions=4): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + self.global_optimum = [[0.192833, 0.190836, 0.123117, 0.135766]] + self.fglob = 0.00030748610 + + self.a = asarray([4.0, 2.0, 1.0, 1 / 2.0, 1 / 4.0, 1 / 6.0, 1 / 8.0, + 1 / 10.0, 1 / 12.0, 1 / 14.0, 1 / 16.0]) + self.b = asarray([0.1957, 0.1947, 0.1735, 0.1600, 0.0844, 0.0627, + 0.0456, 0.0342, 0.0323, 0.0235, 0.0246]) + + def fun(self, x, *args): + self.nfev += 1 + + vec = self.b - (x[0] * (self.a ** 2 + self.a * x[1]) + / (self.a ** 2 + self.a * x[2] + x[3])) + return sum(vec ** 2) diff --git a/go_benchmark_functions/go_funcs_L.py b/go_benchmark_functions/go_funcs_L.py new file mode 100644 index 0000000..3167b63 --- /dev/null +++ b/go_benchmark_functions/go_funcs_L.py @@ -0,0 +1,328 @@ +# -*- coding: utf-8 -*- +from numpy import sum, cos, exp, pi, arange, sin +from .go_benchmark import Benchmark + + +class Langermann(Benchmark): + + r""" + Langermann objective function. + + This class defines the Langermann [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Langermann}}(x) = - \sum_{i=1}^{5} + \frac{c_i \cos\left\{\pi \left[\left(x_{1}- a_i\right)^{2} + + \left(x_{2} - b_i \right)^{2}\right]\right\}}{e^{\frac{\left( x_{1} + - a_i\right)^{2} + \left( x_{2} - b_i\right)^{2}}{\pi}}} + + + Where: + + .. math:: + + \begin{matrix} + a = [3, 5, 2, 1, 7]\\ + b = [5, 2, 1, 4, 9]\\ + c = [1, 2, 5, 2, 3] \\ + \end{matrix} + + + Here :math:`x_i \in [0, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -5.1621259` + for :math:`x = [2.00299219, 1.006096]` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO: Langermann from Gavana is _not the same_ as Jamil #68. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[2.00299219, 1.006096]] + self.fglob = -5.1621259 + + def fun(self, x, *args): + self.nfev += 1 + + a = [3, 5, 2, 1, 7] + b = [5, 2, 1, 4, 9] + c = [1, 2, 5, 2, 3] + + return (-sum(c * exp(-(1 / pi) * ((x[0] - a) ** 2 + + (x[1] - b) ** 2)) * cos(pi * ((x[0] - a) ** 2 + + (x[1] - b) ** 2)))) + + +class LennardJones(Benchmark): + + r""" + LennardJones objective function. + + This class defines the Lennard-Jones global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{LennardJones}}(\mathbf{x}) = \sum_{i=0}^{n-2}\sum_{j>1}^{n-1} + \frac{1}{r_{ij}^{12}} - \frac{1}{r_{ij}^{6}} + + + Where, in this exercise: + + .. math:: + + r_{ij} = \sqrt{(x_{3i}-x_{3j})^2 + (x_{3i+1}-x_{3j+1})^2) + + (x_{3i+2}-x_{3j+2})^2} + + + Valid for any dimension, :math:`n = 3*k, k=2 , 3, 4, ..., 20`. :math:`k` + is the number of atoms in 3-D space constraints: unconstrained type: + multi-modal with one global minimum; non-separable + + Value-to-reach: :math:`minima[k-2] + 0.0001`. See array of minima below; + additional minima available at the Cambridge cluster database: + + http://www-wales.ch.cam.ac.uk/~jon/structures/LJ/tables.150.html + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-4, 4]` for :math:`i = 1 ,..., n`. + + *Global optimum*: + + .. math:: + + \text{minima} = [-1.,-3.,-6.,-9.103852,-12.712062,-16.505384,\\ + -19.821489, -24.113360, -28.422532,-32.765970,\\ + -37.967600,-44.326801, -47.845157,-52.322627,\\ + -56.815742,-61.317995, -66.530949, -72.659782,\\ + -77.1777043]\\ + + + """ + + def __init__(self, dimensions=6): + # dimensions is in [6:60] + # max dimensions is going to be 60. + if dimensions not in range(6, 61): + raise ValueError("LJ dimensions must be in (6, 60)") + + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-4.0] * self.N, [4.0] * self.N)) + + self.global_optimum = [[]] + + self.minima = [-1.0, -3.0, -6.0, -9.103852, -12.712062, + -16.505384, -19.821489, -24.113360, -28.422532, + -32.765970, -37.967600, -44.326801, -47.845157, + -52.322627, -56.815742, -61.317995, -66.530949, + -72.659782, -77.1777043] + + k = int(dimensions / 3) + self.fglob = self.minima[k - 2] + self.change_dimensionality = True + + def change_dimensions(self, ndim): + if ndim not in range(6, 61): + raise ValueError("LJ dimensions must be in (6, 60)") + + Benchmark.change_dimensions(self, ndim) + self.fglob = self.minima[int(self.N / 3) - 2] + + def fun(self, x, *args): + self.nfev += 1 + + k = int(self.N / 3) + s = 0.0 + + for i in range(k - 1): + for j in range(i + 1, k): + a = 3 * i + b = 3 * j + xd = x[a] - x[b] + yd = x[a + 1] - x[b + 1] + zd = x[a + 2] - x[b + 2] + ed = xd * xd + yd * yd + zd * zd + ud = ed * ed * ed + if ed > 0.0: + s += (1.0 / ud - 2.0) / ud + + return s + + +class Leon(Benchmark): + + r""" + Leon objective function. + + This class defines the Leon [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Leon}}(\mathbf{x}) = \left(1 - x_{1}\right)^{2} + + 100 \left(x_{2} - x_{1}^{2} \right)^{2} + + + with :math:`x_i \in [-1.2, 1.2]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 1]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-1.2] * self.N, [1.2] * self.N)) + + self.global_optimum = [[1 for _ in range(self.N)]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return 100. * (x[1] - x[0] ** 2.0) ** 2.0 + (1 - x[0]) ** 2.0 + + +class Levy03(Benchmark): + + r""" + Levy 3 objective function. + + This class defines the Levy 3 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Levy03}}(\mathbf{x}) = \sin^2(\pi y_1)+\sum_{i=1}^{n-1}(y_i-1)^2[1+10\sin^2(\pi y_{i+1})]+(y_n-1)^2 + + Where, in this exercise: + + .. math:: + + y_i=1+\frac{x_i-1}{4} + + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in [-10, 10]` for :math:`i=1,...,n`. + + *Global optimum*: :math:`f(x_i) = 0` for :math:`x_i = 1` for :math:`i=1,...,n` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO: not clear what the Levy function definition is. Gavana, Mishra, + Adorio have different forms. Indeed Levy 3 docstring from Gavana + disagrees with the Gavana code! The following code is from the Mishra + listing of Levy08. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = [(-5, 5), (-5, 5)] + + self.global_optimum = [[1 for _ in range(self.N)]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + y = 1 + (x - 1) / 4 + v = sum((y[:-1] - 1) ** 2 * (1 + 10 * sin(pi * y[1:]) ** 2)) + z = (y[-1] - 1) ** 2 + return sin(pi * y[0]) ** 2 + v + z + + +class Levy05(Benchmark): + + r""" + Levy 5 objective function. + + This class defines the Levy 5 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Levy05}}(\mathbf{x}) = \sum_{i=1}^{5} i \cos \left[(i-1)x_1 + i \right] \times \sum_{j=1}^{5} j \cos \left[(j+1)x_2 + j \right] + (x_1 + 1.42513)^2 + (x_2 + 0.80032)^2 + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in [-10, 10]` for :math:`i=1,...,n`. + + *Global optimum*: :math:`f(x_i) = -176.1375779` for :math:`\mathbf{x} = [-1.30685, -1.42485]`. + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = ([-2.0, 2.0], [-2.0, 2.0]) + + self.global_optimum = [[-1.30685, -1.42485]] + self.fglob = -176.1375779 + + def fun(self, x, *args): + self.nfev += 1 + + i = arange(1, 6) + a = i * cos((i - 1) * x[0] + i) + b = i * cos((i + 1) * x[1] + i) + + return sum(a) * sum(b) + (x[0] + 1.42513) ** 2 + (x[1] + 0.80032) ** 2 + + +class Levy13(Benchmark): + + r""" + Levy13 objective function. + + This class defines the Levy13 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Levy13}}(x) = \left(x_{1} -1\right)^{2} \left[\sin^{2} + \left(3 \pi x_{2}\right) + 1\right] + \left(x_{2} + - 1\right)^{2} \left[\sin^{2}\left(2 \pi x_{2}\right) + + 1\right] + \sin^{2}\left(3 \pi x_{1}\right) + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 1]` + + .. [1] Mishra, S. Some new test functions for global optimization and + performance of repulsive particle swarm method. + Munich Personal RePEc Archive, 2006, 2718 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = [(-5, 5), (-5, 5)] + + self.global_optimum = [[1 for _ in range(self.N)]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + u = sin(3 * pi * x[0]) ** 2 + v = (x[0] - 1) ** 2 * (1 + (sin(3 * pi * x[1])) ** 2) + w = (x[1] - 1) ** 2 * (1 + (sin(2 * pi * x[1])) ** 2) + return u + v + w diff --git a/go_benchmark_functions/go_funcs_M.py b/go_benchmark_functions/go_funcs_M.py new file mode 100644 index 0000000..5450d6c --- /dev/null +++ b/go_benchmark_functions/go_funcs_M.py @@ -0,0 +1,719 @@ +# -*- coding: utf-8 -*- +from numpy import (abs, asarray, cos, exp, log, arange, pi, prod, sin, sqrt, + sum, tan) +from .go_benchmark import Benchmark, safe_import + +with safe_import(): + from scipy.special import factorial + + +class Matyas(Benchmark): + + r""" + Matyas objective function. + + This class defines the Matyas [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Matyas}}(x) = 0.26(x_1^2 + x_2^2) - 0.48 x_1 x_2 + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return 0.26 * (x[0] ** 2 + x[1] ** 2) - 0.48 * x[0] * x[1] + + +class McCormick(Benchmark): + + r""" + McCormick objective function. + + This class defines the McCormick [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{McCormick}}(x) = - x_{1} + 2 x_{2} + \left(x_{1} + - x_{2}\right)^{2} + \sin\left(x_{1} + x_{2}\right) + 1 + + with :math:`x_1 \in [-1.5, 4]`, :math:`x_2 \in [-3, 4]`. + + *Global optimum*: :math:`f(x) = -1.913222954981037` for + :math:`x = [-0.5471975602214493, -1.547197559268372]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-1.5, 4.0), (-3.0, 3.0)] + + self.global_optimum = [[-0.5471975602214493, -1.547197559268372]] + self.fglob = -1.913222954981037 + + def fun(self, x, *args): + self.nfev += 1 + + return (sin(x[0] + x[1]) + (x[0] - x[1]) ** 2 - 1.5 * x[0] + + 2.5 * x[1] + 1) + + +class Meyer(Benchmark): + + r""" + Meyer [1]_ objective function. + + ..[1] https://www.itl.nist.gov/div898/strd/nls/data/mgh10.shtml + + TODO NIST regression standard + """ + + def __init__(self, dimensions=3): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0., 100., 100.], + [1, 1000., 500.])) + self.global_optimum = [[5.6096364710e-3, 6.1813463463e3, + 3.4522363462e2]] + self.fglob = 8.7945855171e1 + self.a = asarray([3.478E+04, 2.861E+04, 2.365E+04, 1.963E+04, 1.637E+04, + 1.372E+04, 1.154E+04, 9.744E+03, 8.261E+03, 7.030E+03, + 6.005E+03, 5.147E+03, 4.427E+03, 3.820E+03, 3.307E+03, + 2.872E+03]) + self.b = asarray([5.000E+01, 5.500E+01, 6.000E+01, 6.500E+01, 7.000E+01, + 7.500E+01, 8.000E+01, 8.500E+01, 9.000E+01, 9.500E+01, + 1.000E+02, 1.050E+02, 1.100E+02, 1.150E+02, 1.200E+02, + 1.250E+02]) + + def fun(self, x, *args): + self.nfev += 1 + + vec = x[0] * exp(x[1] / (self.b + x[2])) + return sum((self.a - vec) ** 2) + + +class Michalewicz(Benchmark): + + r""" + Michalewicz objective function. + + This class defines the Michalewicz [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Michalewicz}}(x) = - \sum_{i=1}^{2} \sin\left(x_i\right) + \sin^{2 m}\left(\frac{i x_i^{2}}{\pi}\right) + + + Where, in this exercise, :math:`m = 10`. + + with :math:`x_i \in [0, \pi]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x_i) = -1.8013` for :math:`x = [0, 0]` + + .. [1] Adorio, E. MVF - "Multivariate Test Functions Library in C for + Unconstrained Global Optimization", 2005 + + TODO: could change dimensionality, but global minimum might change. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [pi] * self.N)) + + self.global_optimum = [[2.20290555, 1.570796]] + self.fglob = -1.8013 + + def fun(self, x, *args): + self.nfev += 1 + + m = 10.0 + i = arange(1, self.N + 1) + return -sum(sin(x) * sin(i * x ** 2 / pi) ** (2 * m)) + + +class MieleCantrell(Benchmark): + + r""" + Miele-Cantrell [1]_ objective function. + + This class defines the Miele-Cantrell global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{MieleCantrell}}({x}) = (e^{-x_1} - x_2)^4 + 100(x_2 - x_3)^6 + + \tan^4(x_3 - x_4) + x_1^8 + + + with :math:`x_i \in [-1, 1]` for :math:`i = 1, ..., 4`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, 1, 1, 1]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=4): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-1.0] * self.N, [1.0] * self.N)) + + self.global_optimum = [[0.0, 1.0, 1.0, 1.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return ((exp(-x[0]) - x[1]) ** 4 + 100 * (x[1] - x[2]) ** 6 + + tan(x[2] - x[3]) ** 4 + x[0] ** 8) + + +class Mishra01(Benchmark): + + r""" + Mishra 1 objective function. + + This class defines the Mishra 1 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Mishra01}}(x) = (1 + x_n)^{x_n} + + + where + + .. math:: + + x_n = n - \sum_{i=1}^{n-1} x_i + + + with :math:`x_i \in [0, 1]` for :math:`i =1, ..., n`. + + *Global optimum*: :math:`f(x) = 2` for :math:`x_i = 1` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, + [1.0 + 1e-9] * self.N)) + + self.global_optimum = [[1.0 for _ in range(self.N)]] + self.fglob = 2.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + xn = self.N - sum(x[0:-1]) + return (1 + xn) ** xn + + +class Mishra02(Benchmark): + + r""" + Mishra 2 objective function. + + This class defines the Mishra 2 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Mishra02}}({x}) = (1 + x_n)^{x_n} + + + with + + .. math:: + + x_n = n - \sum_{i=1}^{n-1} \frac{(x_i + x_{i+1})}{2} + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [0, 1]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 2` for :math:`x_i = 1` + for :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, + [1.0 + 1e-9] * self.N)) + + self.global_optimum = [[1.0 for _ in range(self.N)]] + self.fglob = 2.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + xn = self.N - sum((x[:-1] + x[1:]) / 2.0) + return (1 + xn) ** xn + + +class Mishra03(Benchmark): + + r""" + Mishra 3 objective function. + + This class defines the Mishra 3 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Mishra03}}(x) = \sqrt{\lvert \cos{\sqrt{\lvert x_1^2 + + x_2^2 \rvert}} \rvert} + 0.01(x_1 + x_2) + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -0.1999` for + :math:`x = [-9.99378322, -9.99918927]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: I think that Jamil#76 has the wrong global minimum, a smaller one + is possible + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[-9.99378322, -9.99918927]] + self.fglob = -0.19990562 + + def fun(self, x, *args): + self.nfev += 1 + + return ((0.01 * (x[0] + x[1]) + + sqrt(abs(cos(sqrt(abs(x[0] ** 2 + x[1] ** 2))))))) + + +class Mishra04(Benchmark): + + r""" + Mishra 4 objective function. + + This class defines the Mishra 4 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Mishra04}}({x}) = \sqrt{\lvert \sin{\sqrt{\lvert + x_1^2 + x_2^2 \rvert}} \rvert} + 0.01(x_1 + x_2) + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -0.17767` for + :math:`x = [-8.71499636, -9.0533148]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: I think that Jamil#77 has the wrong minimum, not possible + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[-8.88055269734, -8.89097599857]] + self.fglob = -0.177715264826 + + def fun(self, x, *args): + self.nfev += 1 + + return ((0.01 * (x[0] + x[1]) + + sqrt(abs(sin(sqrt(abs(x[0] ** 2 + x[1] ** 2))))))) + + +class Mishra05(Benchmark): + + r""" + Mishra 5 objective function. + + This class defines the Mishra 5 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Mishra05}}(x) = \left [ \sin^2 ((\cos(x_1) + \cos(x_2))^2) + + \cos^2 ((\sin(x_1) + \sin(x_2))^2) + x_1 \right ]^2 + 0.01(x_1 + x_2) + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -0.119829` for :math:`x = [-1.98682, -10]` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO Line 381 in paper + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[-1.98682, -10.0]] + self.fglob = -1.019829519930646 + + def fun(self, x, *args): + self.nfev += 1 + + return (0.01 * x[0] + 0.1 * x[1] + + (sin((cos(x[0]) + cos(x[1])) ** 2) ** 2 + + cos((sin(x[0]) + sin(x[1])) ** 2) ** 2 + x[0]) ** 2) + + +class Mishra06(Benchmark): + + r""" + Mishra 6 objective function. + + This class defines the Mishra 6 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Mishra06}}(x) = -\log{\left [ \sin^2 ((\cos(x_1) + + \cos(x_2))^2) - \cos^2 ((\sin(x_1) + \sin(x_2))^2) + x_1 \right ]^2} + + 0.01 \left[(x_1 -1)^2 + (x_2 - 1)^2 \right] + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x_i) = -2.28395` for :math:`x = [2.88631, 1.82326]` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO line 397 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[2.88631, 1.82326]] + self.fglob = -2.28395 + + def fun(self, x, *args): + self.nfev += 1 + + a = 0.1 * ((x[0] - 1) ** 2 + (x[1] - 1) ** 2) + u = (cos(x[0]) + cos(x[1])) ** 2 + v = (sin(x[0]) + sin(x[1])) ** 2 + return a - log((sin(u) ** 2 - cos(v) ** 2 + x[0]) ** 2) + + +class Mishra07(Benchmark): + + r""" + Mishra 7 objective function. + + This class defines the Mishra 7 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Mishra07}}(x) = \left [\prod_{i=1}^{n} x_i - n! \right]^2 + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = \sqrt{n}` + for :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = [(-2, 2), (-2, 2)] + self.global_optimum = [[sqrt(self.N) + for i in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return (prod(x) - factorial(self.N)) ** 2.0 + + +class Mishra08(Benchmark): + + r""" + Mishra 8 objective function. + + This class defines the Mishra 8 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Mishra08}}(x) = 0.001 \left[\lvert x_1^{10} - 20x_1^9 + + 180x_1^8 - 960 x_1^7 + 3360x_1^6 - 8064x_1^5 + 13340x_1^4 - 15360x_1^3 + + 11520x_1^2 - 5120x_1 + 2624 \rvert \lvert x_2^4 + 12x_2^3 + 54x_2^2 + + 108x_2 + 81 \rvert \right]^2 + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [2, -3]` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO Line 1065 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = [(1.0, 2.0), (-4.0, 1.0)] + self.global_optimum = [[2.0, -3.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + val = abs(x[0] ** 10 - 20 * x[0] ** 9 + 180 * x[0] ** 8 + - 960 * x[0] ** 7 + 3360 * x[0] ** 6 - 8064 * x[0] ** 5 + + 13340 * x[0] ** 4 - 15360 * x[0] ** 3 + 11520 * x[0] ** 2 + - 5120 * x[0] + 2624) + val += abs(x[1] ** 4 + 12 * x[1] ** 3 + + 54 * x[1] ** 2 + 108 * x[1] + 81) + return 0.001 * val ** 2 + + +class Mishra09(Benchmark): + + r""" + Mishra 9 objective function. + + This class defines the Mishra 9 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Mishra09}}({x}) = \left[ ab^2c + abc^2 + b^2 + + (x_1 + x_2 - x_3)^2 \right]^2 + + + Where, in this exercise: + + .. math:: + + \begin{cases} a = 2x_1^3 + 5x_1x_2 + 4x_3 - 2x_1^2x_3 - 18 \\ + b = x_1 + x_2^3 + x_1x_2^2 + x_1x_3^2 - 22 \\ + c = 8x_1^2 + 2x_2x_3 + 2x_2^2 + 3x_2^3 - 52 \end{cases} + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2, 3`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 2, 3]` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO Line 1103 + """ + + def __init__(self, dimensions=3): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.global_optimum = [[1.0, 2.0, 3.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + a = (2 * x[0] ** 3 + 5 * x[0] * x[1] + + 4 * x[2] - 2 * x[0] ** 2 * x[2] - 18) + b = x[0] + x[1] ** 3 + x[0] * x[1] ** 2 + x[0] * x[2] ** 2 - 22.0 + c = (8 * x[0] ** 2 + 2 * x[1] * x[2] + + 2 * x[1] ** 2 + 3 * x[1] ** 3 - 52) + + return (a * c * b ** 2 + a * b * c ** 2 + b ** 2 + + (x[0] + x[1] - x[2]) ** 2) ** 2 + + +class Mishra10(Benchmark): + + r""" + Mishra 10 objective function. + + This class defines the Mishra 10 global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + TODO - int(x) should be used instead of floor(x)!!!!! + f_{\text{Mishra10}}({x}) = \left[ \lfloor x_1 \perp x_2 \rfloor - + \lfloor x_1 \rfloor - \lfloor x_2 \rfloor \right]^2 + + with :math:`x_i \in [-10, 10]` for :math:`i =1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [2, 2]` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO line 1115 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.global_optimum = [[2.0, 2.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + x1, x2 = int(x[0]), int(x[1]) + f1 = x1 + x2 + f2 = x1 * x2 + return (f1 - f2) ** 2.0 + + +class Mishra11(Benchmark): + + r""" + Mishra 11 objective function. + + This class defines the Mishra 11 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Mishra11}}(x) = \left [ \frac{1}{n} \sum_{i=1}^{n} \lvert x_i + \rvert - \left(\prod_{i=1}^{n} \lvert x_i \rvert \right )^{\frac{1}{n}} + \right]^2 + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = [(-3, 3), (-3, 3)] + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + N = self.N + return ((1.0 / N) * sum(abs(x)) - (prod(abs(x))) ** 1.0 / N) ** 2.0 + + +class MultiModal(Benchmark): + + r""" + MultiModal objective function. + + This class defines the MultiModal global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{MultiModal}}(x) = \left( \sum_{i=1}^n \lvert x_i \rvert + \right) \left( \prod_{i=1}^n \lvert x_i \rvert \right) + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = [(-5, 5), (-5, 5)] + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(abs(x)) * prod(abs(x)) diff --git a/go_benchmark_functions/go_funcs_N.py b/go_benchmark_functions/go_funcs_N.py new file mode 100644 index 0000000..acb3cae --- /dev/null +++ b/go_benchmark_functions/go_funcs_N.py @@ -0,0 +1,149 @@ +# -*- coding: utf-8 -*- +from numpy import cos, sqrt, sin, abs +from .go_benchmark import Benchmark + + +class NeedleEye(Benchmark): + + r""" + NeedleEye objective function. + + This class defines the Needle-Eye [1]_ global optimization problem. This is a + a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{NeedleEye}}(x) = + \begin{cases} + 1 & \textrm{if }\hspace{5pt} \lvert x_i \rvert < eye \hspace{5pt} + \forall i \\ + \sum_{i=1}^n (100 + \lvert x_i \rvert) & \textrm{if } \hspace{5pt} + \lvert x_i \rvert > eye \\ + 0 & \textrm{otherwise}\\ + \end{cases} + + + Where, in this exercise, :math:`eye = 0.0001`. + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 1` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 1.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + f = fp = 0.0 + eye = 0.0001 + + for val in x: + if abs(val) >= eye: + fp = 1.0 + f += 100.0 + abs(val) + else: + f += 1.0 + + if fp < 1e-6: + f = f / self.N + + return f + + +class NewFunction01(Benchmark): + + r""" + NewFunction01 objective function. + + This class defines the NewFunction01 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{NewFunction01}}(x) = \left | {\cos\left(\sqrt{\left|{x_{1}^{2} + + x_{2}}\right|}\right)} \right |^{0.5} + (x_{1} + x_{2})/100 + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -0.18459899925` for + :math:`x = [-8.46669057, -9.99982177]` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO line 355 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[-8.46668984648, -9.99980944557]] + self.fglob = -0.184648852475 + + def fun(self, x, *args): + self.nfev += 1 + + return ((abs(cos(sqrt(abs(x[0] ** 2 + x[1]))))) ** 0.5 + + 0.01 * (x[0] + x[1])) + + +class NewFunction02(Benchmark): + + r""" + NewFunction02 objective function. + + This class defines the NewFunction02 global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{NewFunction02}}(x) = \left | {\sin\left(\sqrt{\lvert{x_{1}^{2} + + x_{2}}\rvert}\right)} \right |^{0.5} + (x_{1} + x_{2})/100 + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -0.19933159253` for + :math:`x = [-9.94103375, -9.99771235]` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO Line 368 + TODO WARNING, minimum value is estimated from running many optimisations and + choosing the best. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[-9.94114736324, -9.99997128772]] + self.fglob = -0.199409030092 + + def fun(self, x, *args): + self.nfev += 1 + + return ((abs(sin(sqrt(abs(x[0] ** 2 + x[1]))))) ** 0.5 + + 0.01 * (x[0] + x[1])) + + +#Newfunction 3 from Gavana is entered as Mishra05. diff --git a/go_benchmark_functions/go_funcs_O.py b/go_benchmark_functions/go_funcs_O.py new file mode 100644 index 0000000..5a7bc43 --- /dev/null +++ b/go_benchmark_functions/go_funcs_O.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +from numpy import sum, cos, exp, pi, asarray +from .go_benchmark import Benchmark + + +class OddSquare(Benchmark): + + r""" + Odd Square objective function. + + This class defines the Odd Square [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{OddSquare}}(x) = -e^{-\frac{d}{2\pi}} \cos(\pi d) + \left( 1 + \frac{0.02h}{d + 0.01} \right ) + + + Where, in this exercise: + + .. math:: + + \begin{cases} + d = n \cdot \smash{\displaystyle\max_{1 \leq i \leq n}} + \left[ (x_i - b_i)^2 \right ] \\ + h = \sum_{i=1}^{n} (x_i - b_i)^2 + \end{cases} + + And :math:`b = [1, 1.3, 0.8, -0.4, -1.3, 1.6, -0.2, -0.6, 0.5, 1.4, 1, 1.3, + 0.8, -0.4, -1.3, 1.6, -0.2, -0.6, 0.5, 1.4]` + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-5 \pi, 5 \pi]` for :math:`i = 1, ..., n` and + :math:`n \leq 20`. + + *Global optimum*: :math:`f(x_i) = -1.0084` for :math:`x \approx b` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO The best solution changes on dimensionality + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0 * pi] * self.N, + [5.0 * pi] * self.N)) + self.custom_bounds = ([-2.0, 4.0], [-2.0, 4.0]) + self.a = asarray([1, 1.3, 0.8, -0.4, -1.3, 1.6, -0.2, -0.6, 0.5, 1.4] + * 2) + self.global_optimum = [[1.0873320463871847, 1.3873320456818079]] + + self.fglob = -1.00846728102 + + def fun(self, x, *args): + self.nfev += 1 + b = self.a[0: self.N] + d = self.N * max((x - b) ** 2.0) + h = sum((x - b) ** 2.0) + return (-exp(-d / (2.0 * pi)) * cos(pi * d) + * (1.0 + 0.02 * h / (d + 0.01))) diff --git a/go_benchmark_functions/go_funcs_P.py b/go_benchmark_functions/go_funcs_P.py new file mode 100644 index 0000000..10ea190 --- /dev/null +++ b/go_benchmark_functions/go_funcs_P.py @@ -0,0 +1,726 @@ +# -*- coding: utf-8 -*- +from numpy import (abs, sum, sin, cos, sqrt, log, prod, where, pi, exp, arange, + floor, log10, atleast_2d, zeros) +from .go_benchmark import Benchmark + + +class Parsopoulos(Benchmark): + + r""" + Parsopoulos objective function. + + This class defines the Parsopoulos [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Parsopoulos}}(x) = \cos(x_1)^2 + \sin(x_2)^2 + + + with :math:`x_i \in [-5, 5]` for :math:`i = 1, 2`. + + *Global optimum*: This function has infinite number of global minima in R2, + at points :math:`\left(k\frac{\pi}{2}, \lambda \pi \right)`, + where :math:`k = \pm1, \pm3, ...` and :math:`\lambda = 0, \pm1, \pm2, ...` + + In the given domain problem, function has 12 global minima all equal to + zero. + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + + self.global_optimum = [[pi / 2.0, pi]] + self.fglob = 0 + + def fun(self, x, *args): + self.nfev += 1 + + return cos(x[0]) ** 2.0 + sin(x[1]) ** 2.0 + + +class Pathological(Benchmark): + + r""" + Pathological objective function. + + This class defines the Pathological [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Pathological}}(x) = \sum_{i=1}^{n -1} \frac{\sin^{2}\left( + \sqrt{100 x_{i+1}^{2} + x_{i}^{2}}\right) -0.5}{0.001 \left(x_{i}^{2} + - 2x_{i}x_{i+1} + x_{i+1}^{2}\right)^{2} + 0.50} + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-100, 100]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0.` for :math:`x = [0, 0]` for + :math:`i = 1, 2` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0. + + def fun(self, x, *args): + self.nfev += 1 + + vec = (0.5 + (sin(sqrt(100 * x[: -1] ** 2 + x[1:] ** 2)) ** 2 - 0.5) / + (1. + 0.001 * (x[: -1] ** 2 - 2 * x[: -1] * x[1:] + + x[1:] ** 2) ** 2)) + return sum(vec) + + +class Paviani(Benchmark): + + r""" + Paviani objective function. + + This class defines the Paviani [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Paviani}}(x) = \sum_{i=1}^{10} \left[\log^{2}\left(10 + - x_i\right) + \log^{2}\left(x_i -2\right)\right] + - \left(\prod_{i=1}^{10} x_i^{10} \right)^{0.2} + + + with :math:`x_i \in [2.001, 9.999]` for :math:`i = 1, ... , 10`. + + *Global optimum*: :math:`f(x_i) = -45.7784684040686` for + :math:`x_i = 9.350266` for :math:`i = 1, ..., 10` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: think Gavana web/code definition is wrong because final product term + shouldn't raise x to power 10. + """ + + def __init__(self, dimensions=10): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([2.001] * self.N, [9.999] * self.N)) + + self.global_optimum = [[9.350266 for _ in range(self.N)]] + self.fglob = -45.7784684040686 + + def fun(self, x, *args): + self.nfev += 1 + + return sum(log(x - 2) ** 2.0 + log(10.0 - x) ** 2.0) - prod(x) ** 0.2 + + +class Penalty01(Benchmark): + + r""" + Penalty 1 objective function. + + This class defines the Penalty 1 [1]_ global optimization problem. This is a + imultimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Penalty01}}(x) = \frac{\pi}{30} \left\{10 \sin^2(\pi y_1) + + \sum_{i=1}^{n-1} (y_i - 1)^2 \left[1 + 10 \sin^2(\pi y_{i+1}) \right] + + (y_n - 1)^2 \right \} + \sum_{i=1}^n u(x_i, 10, 100, 4) + + + Where, in this exercise: + + .. math:: + + y_i = 1 + \frac{1}{4}(x_i + 1) + + + And: + + .. math:: + + u(x_i, a, k, m) = + \begin{cases} + k(x_i - a)^m & \textrm{if} \hspace{5pt} x_i > a \\ + 0 & \textrm{if} \hspace{5pt} -a \leq x_i \leq a \\ + k(-x_i - a)^m & \textrm{if} \hspace{5pt} x_i < -a + \end{cases} + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-50, 50]` for :math:`i= 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = -1` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-50.0] * self.N, [50.0] * self.N)) + self.custom_bounds = ([-5.0, 5.0], [-5.0, 5.0]) + + self.global_optimum = [[-1.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + a, b, c = 10.0, 100.0, 4.0 + + xx = abs(x) + u = where(xx > a, b * (xx - a) ** c, 0.0) + + y = 1.0 + (x + 1.0) / 4.0 + + return (sum(u) + (pi / 30.0) * (10.0 * sin(pi * y[0]) ** 2.0 + + sum((y[: -1] - 1.0) ** 2.0 + * (1.0 + 10.0 * sin(pi * y[1:]) ** 2.0)) + + (y[-1] - 1) ** 2.0)) + + +class Penalty02(Benchmark): + + r""" + Penalty 2 objective function. + + This class defines the Penalty 2 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Penalty02}}(x) = 0.1 \left\{\sin^2(3\pi x_1) + \sum_{i=1}^{n-1} + (x_i - 1)^2 \left[1 + \sin^2(3\pi x_{i+1}) \right ] + + (x_n - 1)^2 \left [1 + \sin^2(2 \pi x_n) \right ]\right \} + + \sum_{i=1}^n u(x_i, 5, 100, 4) + + Where, in this exercise: + + .. math:: + + u(x_i, a, k, m) = + \begin{cases} + k(x_i - a)^m & \textrm{if} \hspace{5pt} x_i > a \\ + 0 & \textrm{if} \hspace{5pt} -a \leq x_i \leq a \\ + k(-x_i - a)^m & \textrm{if} \hspace{5pt} x_i < -a \\ + \end{cases} + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-50, 50]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 1` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-50.0] * self.N, [50.0] * self.N)) + self.custom_bounds = ([-4.0, 4.0], [-4.0, 4.0]) + + self.global_optimum = [[1.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + a, b, c = 5.0, 100.0, 4.0 + + xx = abs(x) + u = where(xx > a, b * (xx - a) ** c, 0.0) + + return (sum(u) + 0.1 * (10 * sin(3.0 * pi * x[0]) ** 2.0 + + sum((x[:-1] - 1.0) ** 2.0 + * (1.0 + sin(3 * pi * x[1:]) ** 2.0)) + + (x[-1] - 1) ** 2.0 * (1 + sin(2 * pi * x[-1]) ** 2.0))) + + +class PenHolder(Benchmark): + + r""" + PenHolder objective function. + + This class defines the PenHolder [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{PenHolder}}(x) = -e^{\left|{e^{-\left|{- \frac{\sqrt{x_{1}^{2} + + x_{2}^{2}}}{\pi} + 1}\right|} \cos\left(x_{1}\right) + \cos\left(x_{2}\right)}\right|^{-1}} + + + with :math:`x_i \in [-11, 11]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x_i) = -0.9635348327265058` for + :math:`x_i = \pm 9.646167671043401` for :math:`i = 1, 2` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-11.0] * self.N, [11.0] * self.N)) + + self.global_optimum = [[-9.646167708023526, 9.646167671043401]] + self.fglob = -0.9635348327265058 + + def fun(self, x, *args): + self.nfev += 1 + + a = abs(1. - (sqrt(x[0] ** 2 + x[1] ** 2) / pi)) + b = cos(x[0]) * cos(x[1]) * exp(a) + return -exp(-abs(b) ** -1) + + +class PermFunction01(Benchmark): + + r""" + PermFunction 1 objective function. + + This class defines the PermFunction1 [1]_ global optimization problem. This is + a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{PermFunction01}}(x) = \sum_{k=1}^n \left\{ \sum_{j=1}^n (j^k + + \beta) \left[ \left(\frac{x_j}{j}\right)^k - 1 \right] \right\}^2 + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-n, n + 1]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = i` for + :math:`i = 1, ..., n` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO: line 560 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-self.N] * self.N, + [self.N + 1] * self.N)) + + self.global_optimum = [list(range(1, self.N + 1))] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + b = 0.5 + k = atleast_2d(arange(self.N) + 1).T + j = atleast_2d(arange(self.N) + 1) + s = (j ** k + b) * ((x / j) ** k - 1) + return sum((sum(s, axis=1) ** 2)) + + +class PermFunction02(Benchmark): + + r""" + PermFunction 2 objective function. + + This class defines the Perm Function 2 [1]_ global optimization problem. This is + a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{PermFunction02}}(x) = \sum_{k=1}^n \left\{ \sum_{j=1}^n (j + + \beta) \left[ \left(x_j^k - {\frac{1}{j}}^{k} \right ) + \right] \right\}^2 + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-n, n+1]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = \frac{1}{i}` + for :math:`i = 1, ..., n` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO: line 582 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-self.N] * self.N, + [self.N + 1] * self.N)) + self.custom_bounds = ([0, 1.5], [0, 1.0]) + + self.global_optimum = [1. / arange(1, self.N + 1)] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + b = 10 + k = atleast_2d(arange(self.N) + 1).T + j = atleast_2d(arange(self.N) + 1) + s = (j + b) * (x ** k - (1. / j) ** k) + return sum((sum(s, axis=1) ** 2)) + + +class Pinter(Benchmark): + + r""" + Pinter objective function. + + This class defines the Pinter [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Pinter}}(x) = \sum_{i=1}^n ix_i^2 + \sum_{i=1}^n 20i + \sin^2 A + \sum_{i=1}^n i \log_{10} (1 + iB^2) + + + Where, in this exercise: + + .. math:: + + \begin{cases} + A = x_{i-1} \sin x_i + \sin x_{i+1} \\ + B = x_{i-1}^2 - 2x_i + 3x_{i + 1} - \cos x_i + 1\\ + \end{cases} + + Where :math:`x_0 = x_n` and :math:`x_{n + 1} = x_1`. + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + i = arange(self.N) + 1 + xx = zeros(self.N + 2) + xx[1: - 1] = x + xx[0] = x[-1] + xx[-1] = x[0] + A = xx[0: -2] * sin(xx[1: - 1]) + sin(xx[2:]) + B = xx[0: -2] ** 2 - 2 * xx[1: - 1] + 3 * xx[2:] - cos(xx[1: - 1]) + 1 + return (sum(i * x ** 2) + + sum(20 * i * sin(A) ** 2) + + sum(i * log10(1 + i * B ** 2))) + + +class Plateau(Benchmark): + + r""" + Plateau objective function. + + This class defines the Plateau [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Plateau}}(x) = 30 + \sum_{i=1}^n \lfloor \lvert x_i + \rvert\rfloor + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-5.12, 5.12]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 30` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.12] * self.N, [5.12] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 30.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return 30.0 + sum(floor(abs(x))) + + +class Powell(Benchmark): + + r""" + Powell objective function. + + This class defines the Powell [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Powell}}(x) = (x_3+10x_1)^2 + 5(x_2-x_4)^2 + (x_1-2x_2)^4 + + 10(x_3-x_4)^4 + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-4, 5]` for :math:`i = 1, ..., 4`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., 4` + + ..[1] Powell, M. An iterative method for finding stationary values of a + function of several variables Computer Journal, 1962, 5, 147-151 + """ + + def __init__(self, dimensions=4): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-4.0] * self.N, [5.0] * self.N)) + self.global_optimum = [[0, 0, 0, 0]] + self.fglob = 0 + + def fun(self, x, *args): + self.nfev += 1 + + return ((x[0] + 10 * x[1]) ** 2 + 5 * (x[2] - x[3]) ** 2 + + (x[1] - 2 * x[2]) ** 4 + 10 * (x[0] - x[3]) ** 4) + + +class PowerSum(Benchmark): + + r""" + Power sum objective function. + + This class defines the Power Sum global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{PowerSum}}(x) = \sum_{k=1}^n\left[\left(\sum_{i=1}^n x_i^k + \right) - b_k \right]^2 + + Where, in this exercise, :math:`b = [8, 18, 44, 114]` + + Here, :math:`x_i \in [0, 4]` for :math:`i = 1, ..., 4`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 2, 2, 3]` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + """ + + def __init__(self, dimensions=4): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, + [4.0] * self.N)) + + self.global_optimum = [[1.0, 2.0, 2.0, 3.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + b = [8.0, 18.0, 44.0, 114.0] + + k = atleast_2d(arange(self.N) + 1).T + return sum((sum(x ** k, axis=1) - b) ** 2) + + +class Price01(Benchmark): + + r""" + Price 1 objective function. + + This class defines the Price 1 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Price01}}(x) = (\lvert x_1 \rvert - 5)^2 + + (\lvert x_2 \rvert - 5)^2 + + + with :math:`x_i \in [-500, 500]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x_i) = 0.0` for :math:`x = [5, 5]` or + :math:`x = [5, -5]` or :math:`x = [-5, 5]` or :math:`x = [-5, -5]`. + + .. [1] Price, W. A controlled random search procedure for global + optimisation Computer Journal, 1977, 20, 367-370 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-500.0] * self.N, + [500.0] * self.N)) + self.custom_bounds = ([-10.0, 10.0], [-10.0, 10.0]) + + self.global_optimum = [[5.0, 5.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return (abs(x[0]) - 5.0) ** 2.0 + (abs(x[1]) - 5.0) ** 2.0 + + +class Price02(Benchmark): + + r""" + Price 2 objective function. + + This class defines the Price 2 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Price02}}(x) = 1 + \sin^2(x_1) + \sin^2(x_2) + - 0.1e^{(-x_1^2 - x_2^2)} + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0.9` for :math:`x_i = [0, 0]` + + .. [1] Price, W. A controlled random search procedure for global + optimisation Computer Journal, 1977, 20, 367-370 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[0.0, 0.0]] + self.fglob = 0.9 + + def fun(self, x, *args): + self.nfev += 1 + + return 1.0 + sum(sin(x) ** 2) - 0.1 * exp(-x[0] ** 2.0 - x[1] ** 2.0) + + +class Price03(Benchmark): + + r""" + Price 3 objective function. + + This class defines the Price 3 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Price03}}(x) = 100(x_2 - x_1^2)^2 + \left[6.4(x_2 - 0.5)^2 + - x_1 - 0.6 \right]^2 + + with :math:`x_i \in [-50, 50]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [-5, -5]`, + :math:`x = [-5, 5]`, :math:`x = [5, -5]`, :math:`x = [5, 5]`. + + .. [1] Price, W. A controlled random search procedure for global + optimisation Computer Journal, 1977, 20, 367-370 + + TODO Jamil #96 has an erroneous factor of 6 in front of the square brackets + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + self.custom_bounds = ([0, 2], [0, 2]) + + self.global_optimum = [[1.0, 1.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return (100 * (x[1] - x[0] ** 2) ** 2 + + (6.4 * (x[1] - 0.5) ** 2 - x[0] - 0.6) ** 2) + + +class Price04(Benchmark): + + r""" + Price 4 objective function. + + This class defines the Price 4 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Price04}}(x) = (2 x_1^3 x_2 - x_2^3)^2 + + (6 x_1 - x_2^2 + x_2)^2 + + with :math:`x_i \in [-50, 50]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, 0]`, + :math:`x = [2, 4]` and :math:`x = [1.464, -2.506]` + + .. [1] Price, W. A controlled random search procedure for global + optimisation Computer Journal, 1977, 20, 367-370 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-50.0] * self.N, [50.0] * self.N)) + self.custom_bounds = ([0, 2], [0, 2]) + + self.global_optimum = [[2.0, 4.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return ((2.0 * x[1] * x[0] ** 3.0 - x[1] ** 3.0) ** 2.0 + + (6.0 * x[0] - x[1] ** 2.0 + x[1]) ** 2.0) diff --git a/go_benchmark_functions/go_funcs_Q.py b/go_benchmark_functions/go_funcs_Q.py new file mode 100644 index 0000000..b27c4ad --- /dev/null +++ b/go_benchmark_functions/go_funcs_Q.py @@ -0,0 +1,125 @@ +# -*- coding: utf-8 -*- +from numpy import abs, sum, arange, sqrt + +from .go_benchmark import Benchmark + + +class Qing(Benchmark): + r""" + Qing objective function. + + This class defines the Qing [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Qing}}(x) = \sum_{i=1}^{n} (x_i^2 - i)^2 + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-500, 500]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = \pm \sqrt(i)` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-500.0] * self.N, + [500.0] * self.N)) + self.custom_bounds = [(-2, 2), (-2, 2)] + self.global_optimum = [[sqrt(_) for _ in range(1, self.N + 1)]] + self.fglob = 0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + i = arange(1, self.N + 1) + return sum((x ** 2.0 - i) ** 2.0) + + +class Quadratic(Benchmark): + r""" + Quadratic objective function. + + This class defines the Quadratic [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Quadratic}}(x) = -3803.84 - 138.08x_1 - 232.92x_2 + 128.08x_1^2 + + 203.64x_2^2 + 182.25x_1x_2 + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -3873.72418` for + :math:`x = [0.19388, 0.48513]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = [(0, 1), (0, 1)] + self.global_optimum = [[0.19388, 0.48513]] + self.fglob = -3873.72418 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return (-3803.84 - 138.08 * x[0] - 232.92 * x[1] + 128.08 * x[0] ** 2.0 + + 203.64 * x[1] ** 2.0 + 182.25 * x[0] * x[1]) + + +class Quintic(Benchmark): + r""" + Quintic objective function. + + This class defines the Quintic [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Quintic}}(x) = \sum_{i=1}^{n} \left|{x_{i}^{5} - 3 x_{i}^{4} + + 4 x_{i}^{3} + 2 x_{i}^{2} - 10 x_{i} -4}\right| + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x_i) = 0` for :math:`x_i = -1` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = [(-2, 2), (-2, 2)] + + self.global_optimum = [[-1.0 for _ in range(self.N)]] + self.fglob = 0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(abs(x ** 5 - 3 * x ** 4 + 4 * x ** 3 + 2 * x ** 2 + - 10 * x - 4)) diff --git a/go_benchmark_functions/go_funcs_R.py b/go_benchmark_functions/go_funcs_R.py new file mode 100644 index 0000000..24ffe58 --- /dev/null +++ b/go_benchmark_functions/go_funcs_R.py @@ -0,0 +1,408 @@ +# -*- coding: utf-8 -*- +from numpy import abs, sum, sin, cos, asarray, arange, pi, exp, log, sqrt +from scipy.optimize import rosen +from .go_benchmark import Benchmark + + +class Rana(Benchmark): + + r""" + Rana objective function. + + This class defines the Rana [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Rana}}(x) = \sum_{i=1}^{n} \left[x_{i} + \sin\left(\sqrt{\lvert{x_{1} - x_{i} + 1}\rvert}\right) + \cos\left(\sqrt{\lvert{x_{1} + x_{i} + 1}\rvert}\right) + + \left(x_{1} + 1\right) \sin\left(\sqrt{\lvert{x_{1} + x_{i} + + 1}\rvert}\right) \cos\left(\sqrt{\lvert{x_{1} - x_{i} + + 1}\rvert}\right)\right] + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in + [-500.0, 500.0]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x_i) = -928.5478` for + :math:`x = [-300.3376, 500]`. + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: homemade global minimum here. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-500.000001] * self.N, + [500.000001] * self.N)) + + self.global_optimum = [[-300.3376, 500.]] + self.fglob = -500.8021602966615 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + t1 = sqrt(abs(x[1:] + x[: -1] + 1)) + t2 = sqrt(abs(x[1:] - x[: -1] + 1)) + v = (x[1:] + 1) * cos(t2) * sin(t1) + x[:-1] * cos(t1) * sin(t2) + return sum(v) + + +class Rastrigin(Benchmark): + + r""" + Rastrigin objective function. + + This class defines the Rastrigin [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Rastrigin}}(x) = 10n \sum_{i=1}^n \left[ x_i^2 + - 10 \cos(2\pi x_i) \right] + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-5.12, 5.12]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-5.12] * self.N, [5.12] * self.N)) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return 10.0 * self.N + sum(x ** 2.0 - 10.0 * cos(2.0 * pi * x)) + + +class Ratkowsky01(Benchmark): + + """ + Ratkowsky objective function. + + .. [1] https://www.itl.nist.gov/div898/strd/nls/data/ratkowsky3.shtml + """ + + # TODO, this is a NIST regression standard dataset + def __init__(self, dimensions=4): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0., 1., 0., 0.1], + [1000, 20., 3., 6.])) + self.global_optimum = [[6.996415127e2, 5.2771253025, 7.5962938329e-1, + 1.2792483859]] + self.fglob = 8.786404908e3 + self.a = asarray([16.08, 33.83, 65.80, 97.20, 191.55, 326.20, 386.87, + 520.53, 590.03, 651.92, 724.93, 699.56, 689.96, + 637.56, 717.41]) + self.b = arange(1, 16.) + + def fun(self, x, *args): + self.nfev += 1 + + vec = x[0] / ((1 + exp(x[1] - x[2] * self.b)) ** (1 / x[3])) + return sum((self.a - vec) ** 2) + + +class Ratkowsky02(Benchmark): + + r""" + Ratkowsky02 objective function. + + This class defines the Ratkowsky 2 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + f_{\text{Ratkowsky02}}(x) = \sum_{m=1}^{9}(a_m - x[0] / (1 + exp(x[1] + - b_m x[2]))^2 + + where + + .. math:: + + \begin{cases} + a=[8.93, 10.8, 18.59, 22.33, 39.35, 56.11, 61.73, 64.62, 67.08]\\ + b=[9., 14., 21., 28., 42., 57., 63., 70., 79.]\\ + \end{cases} + + + Here :math:`x_1 \in [1, 100]`, :math:`x_2 \in [0.1, 5]` and + :math:`x_3 \in [0.01, 0.5]` + + *Global optimum*: :math:`f(x) = 8.0565229338` for + :math:`x = [7.2462237576e1, 2.6180768402, 6.7359200066e-2]` + + .. [1] https://www.itl.nist.gov/div898/strd/nls/data/ratkowsky2.shtml + """ + + def __init__(self, dimensions=3): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([10, 0.5, 0.01], + [200, 5., 0.5])) + self.global_optimum = [[7.2462237576e1, 2.6180768402, 6.7359200066e-2]] + self.fglob = 8.0565229338 + self.a = asarray([8.93, 10.8, 18.59, 22.33, 39.35, 56.11, 61.73, 64.62, + 67.08]) + self.b = asarray([9., 14., 21., 28., 42., 57., 63., 70., 79.]) + + def fun(self, x, *args): + self.nfev += 1 + + vec = x[0] / (1 + exp(x[1] - x[2] * self.b)) + return sum((self.a - vec) ** 2) + + +class Ripple01(Benchmark): + + r""" + Ripple 1 objective function. + + This class defines the Ripple 1 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Ripple01}}(x) = \sum_{i=1}^2 -e^{-2 \log 2 + (\frac{x_i-0.1}{0.8})^2} \left[\sin^6(5 \pi x_i) + + 0.1\cos^2(500 \pi x_i) \right] + + + with :math:`x_i \in [0, 1]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -2.2` for :math:`x_i = 0.1` for + :math:`i = 1, 2` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([0.0] * self.N, [1.0] * self.N)) + + self.global_optimum = [[0.1 for _ in range(self.N)]] + self.fglob = -2.2 + + def fun(self, x, *args): + self.nfev += 1 + + u = -2.0 * log(2.0) * ((x - 0.1) / 0.8) ** 2.0 + v = sin(5.0 * pi * x) ** 6.0 + 0.1 * cos(500.0 * pi * x) ** 2.0 + return sum(-exp(u) * v) + + +class Ripple25(Benchmark): + + r""" + Ripple 25 objective function. + + This class defines the Ripple 25 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Ripple25}}(x) = \sum_{i=1}^2 -e^{-2 + \log 2 (\frac{x_i-0.1}{0.8})^2} + \left[\sin^6(5 \pi x_i) \right] + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [0, 1]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = -2` for :math:`x_i = 0.1` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([0.0] * self.N, [1.0] * self.N)) + + self.global_optimum = [[0.1 for _ in range(self.N)]] + self.fglob = -2.0 + + def fun(self, x, *args): + self.nfev += 1 + + u = -2.0 * log(2.0) * ((x - 0.1) / 0.8) ** 2.0 + v = sin(5.0 * pi * x) ** 6.0 + return sum(-exp(u) * v) + + +class Rosenbrock(Benchmark): + + r""" + Rosenbrock objective function. + + This class defines the Rosenbrock [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Rosenbrock}}(x) = \sum_{i=1}^{n-1} [100(x_i^2 + - x_{i+1})^2 + (x_i - 1)^2] + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-5, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 1` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-30.] * self.N, [30.0] * self.N)) + self.custom_bounds = [(-2, 2), (-2, 2)] + + self.global_optimum = [[1 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return rosen(x) + + +class RosenbrockModified(Benchmark): + + r""" + Modified Rosenbrock objective function. + + This class defines the Modified Rosenbrock [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{RosenbrockModified}}(x) = 74 + 100(x_2 - x_1^2)^2 + + (1 - x_1)^2 - 400 e^{-\frac{(x_1+1)^2 + (x_2 + 1)^2}{0.1}} + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-2, 2]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 34.04024310` for + :math:`x = [-0.90955374, -0.95057172]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: We have different global minimum compared to Jamil #106. This is + possibly because of the (1-x) term is using the wrong parameter. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-2.0] * self.N, [2.0] * self.N)) + self.custom_bounds = ([-1.0, 0.5], [-1.0, 1.0]) + + self.global_optimum = [[-0.90955374, -0.95057172]] + self.fglob = 34.040243106640844 + + def fun(self, x, *args): + self.nfev += 1 + + a = 74 + 100. * (x[1] - x[0] ** 2) ** 2 + (1 - x[0]) ** 2 + a -= 400 * exp(-((x[0] + 1.) ** 2 + (x[1] + 1.) ** 2) / 0.1) + return a + + +class RotatedEllipse01(Benchmark): + + r""" + Rotated Ellipse 1 objective function. + + This class defines the Rotated Ellipse 1 [1]_ global optimization problem. This + is a unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{RotatedEllipse01}}(x) = 7x_1^2 - 6 \sqrt{3} x_1x_2 + 13x_2^2 + + with :math:`x_i \in [-500, 500]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-500.0] * self.N, + [500.0] * self.N)) + self.custom_bounds = ([-2.0, 2.0], [-2.0, 2.0]) + + self.global_optimum = [[0.0, 0.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return (7.0 * x[0] ** 2.0 - 6.0 * sqrt(3) * x[0] * x[1] + + 13 * x[1] ** 2.0) + + +class RotatedEllipse02(Benchmark): + + r""" + Rotated Ellipse 2 objective function. + + This class defines the Rotated Ellipse 2 [1]_ global optimization problem. This + is a unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{RotatedEllipse02}}(x) = x_1^2 - x_1 x_2 + x_2^2 + + with :math:`x_i \in [-500, 500]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-500.0] * self.N, + [500.0] * self.N)) + self.custom_bounds = ([-2.0, 2.0], [-2.0, 2.0]) + + self.global_optimum = [[0.0, 0.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return x[0] ** 2.0 - x[0] * x[1] + x[1] ** 2.0 diff --git a/go_benchmark_functions/go_funcs_S.py b/go_benchmark_functions/go_funcs_S.py new file mode 100644 index 0000000..b4a2374 --- /dev/null +++ b/go_benchmark_functions/go_funcs_S.py @@ -0,0 +1,1366 @@ +# -*- coding: utf-8 -*- +from numpy import (abs, asarray, cos, floor, arange, pi, prod, roll, sin, + sqrt, sum, repeat, atleast_2d, tril) +from numpy.random import uniform +from .go_benchmark import Benchmark + + +class Salomon(Benchmark): + + r""" + Salomon objective function. + + This class defines the Salomon [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Salomon}}(x) = 1 - \cos \left (2 \pi + \sqrt{\sum_{i=1}^{n} x_i^2} \right) + 0.1 \sqrt{\sum_{i=1}^n x_i^2} + + Here, :math:`n` represents the number of dimensions and :math:`x_i \in + [-100, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = [(-50, 50), (-50, 50)] + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + u = sqrt(sum(x ** 2)) + return 1 - cos(2 * pi * u) + 0.1 * u + + +class Sargan(Benchmark): + + r""" + Sargan objective function. + + This class defines the Sargan [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Sargan}}(x) = \sum_{i=1}^{n} n \left (x_i^2 + + 0.4 \sum_{i \neq j}^{n} x_ix_j \right) + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-100, 100]` for + :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = [(-5, 5), (-5, 5)] + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + x0 = x[:-1] + x1 = roll(x, -1)[:-1] + + return sum(self.N * (x ** 2 + 0.4 * sum(x0 * x1))) + + +class Schaffer01(Benchmark): + + r""" + Schaffer 1 objective function. + + This class defines the Schaffer 1 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schaffer01}}(x) = 0.5 + \frac{\sin^2 (x_1^2 + x_2^2)^2 - 0.5} + {1 + 0.001(x_1^2 + x_2^2)^2} + + with :math:`x_i \in [-100, 100]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, 0]` for + :math:`i = 1, 2` + + .. [1] Mishra, S. Some new test functions for global optimization and + performance of repulsive particle swarm method. + Munich Personal RePEc Archive, 2006, 2718 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = [(-10, 10), (-10, 10)] + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + u = (x[0] ** 2 + x[1] ** 2) + num = sin(u) ** 2 - 0.5 + den = (1 + 0.001 * u) ** 2 + return 0.5 + num / den + + +class Schaffer02(Benchmark): + + r""" + Schaffer 2 objective function. + + This class defines the Schaffer 2 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schaffer02}}(x) = 0.5 + \frac{\sin^2 (x_1^2 - x_2^2)^2 - 0.5} + {1 + 0.001(x_1^2 + x_2^2)^2} + + with :math:`x_i \in [-100, 100]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, 0]` for + :math:`i = 1, 2` + + .. [1] Mishra, S. Some new test functions for global optimization and + performance of repulsive particle swarm method. + Munich Personal RePEc Archive, 2006, 2718 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = [(-10, 10), (-10, 10)] + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + num = sin((x[0] ** 2 - x[1] ** 2)) ** 2 - 0.5 + den = (1 + 0.001 * (x[0] ** 2 + x[1] ** 2)) ** 2 + return 0.5 + num / den + + +class Schaffer03(Benchmark): + + r""" + Schaffer 3 objective function. + + This class defines the Schaffer 3 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schaffer03}}(x) = 0.5 + \frac{\sin^2 \left( \cos \lvert x_1^2 + - x_2^2 \rvert \right ) - 0.5}{1 + 0.001(x_1^2 + x_2^2)^2} + + with :math:`x_i \in [-100, 100]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0.00156685` for :math:`x = [0, 1.253115]` + + .. [1] Mishra, S. Some new test functions for global optimization and + performance of repulsive particle swarm method. + Munich Personal RePEc Archive, 2006, 2718 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = [(-10, 10), (-10, 10)] + + self.global_optimum = [[0.0, 1.253115]] + self.fglob = 0.00156685 + + def fun(self, x, *args): + self.nfev += 1 + + num = sin(cos(abs(x[0] ** 2 - x[1] ** 2))) ** 2 - 0.5 + den = (1 + 0.001 * (x[0] ** 2 + x[1] ** 2)) ** 2 + return 0.5 + num / den + + +class Schaffer04(Benchmark): + + r""" + Schaffer 4 objective function. + + This class defines the Schaffer 4 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schaffer04}}(x) = 0.5 + \frac{\cos^2 \left( \sin(x_1^2 - x_2^2) + \right ) - 0.5}{1 + 0.001(x_1^2 + x_2^2)^2}^2 + + with :math:`x_i \in [-100, 100]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0.292579` for :math:`x = [0, 1.253115]` + + .. [1] Mishra, S. Some new test functions for global optimization and + performance of repulsive particle swarm method. + Munich Personal RePEc Archive, 2006, 2718 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = [(-10, 10), (-10, 10)] + + self.global_optimum = [[0.0, 1.253115]] + self.fglob = 0.292579 + + def fun(self, x, *args): + self.nfev += 1 + + num = cos(sin(abs(x[0] ** 2 - x[1] ** 2))) ** 2 - 0.5 + den = (1 + 0.001 * (x[0] ** 2 + x[1] ** 2)) ** 2 + return 0.5 + num / den + + +# class SchmidtVetters(Benchmark): +# +# r""" +# Schmidt-Vetters objective function. +# +# This class defines the Schmidt-Vetters global optimization problem. This +# is a multimodal minimization problem defined as follows: +# +# .. math:: +# +# f_{\text{SchmidtVetters}}(x) = \frac{1}{1 + (x_1 - x_2)^2} +# + \sin \left(\frac{\pi x_2 + x_3}{2} \right) +# + e^{\left(\frac{x_1+x_2}{x_2} - 2\right)^2} +# +# with :math:`x_i \in [0, 10]` for :math:`i = 1, 2, 3`. +# +# *Global optimum*: :math:`f(x) = 2.99643266` for +# :math:`x = [0.79876108, 0.79962581, 0.79848824]` +# +# TODO equation seems right, but [7.07083412 , 10., 3.14159293] produces a +# lower minimum, 0.193973 +# """ +# +# def __init__(self, dimensions=3): +# Benchmark.__init__(self, dimensions) +# self._bounds = zip([0.0] * self.N, [10.0] * self.N) +# +# self.global_optimum = [[0.79876108, 0.79962581, 0.79848824]] +# self.fglob = 2.99643266 +# +# def fun(self, x, *args): +# self.nfev += 1 +# +# return (1 / (1 + (x[0] - x[1]) ** 2) + sin((pi * x[1] + x[2]) / 2) +# + exp(((x[0] + x[1]) / x[1] - 2) ** 2)) + + +class Schwefel01(Benchmark): + + r""" + Schwefel 1 objective function. + + This class defines the Schwefel 1 [1]_ global optimization problem. This is a + unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schwefel01}}(x) = \left(\sum_{i=1}^n x_i^2 \right)^{\alpha} + + + Where, in this exercise, :math:`\alpha = \sqrt{\pi}`. + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-100, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` + for :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = ([-4.0, 4.0], [-4.0, 4.0]) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + alpha = sqrt(pi) + return (sum(x ** 2.0)) ** alpha + + +class Schwefel02(Benchmark): + + r""" + Schwefel 2 objective function. + + This class defines the Schwefel 2 [1]_ global optimization problem. This + is a unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schwefel02}}(x) = \sum_{i=1}^n \left(\sum_{j=1}^i + x_i \right)^2 + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-100, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = ([-4.0, 4.0], [-4.0, 4.0]) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + mat = repeat(atleast_2d(x), self.N, axis=0) + inner = sum(tril(mat), axis=1) + return sum(inner ** 2) + + +class Schwefel04(Benchmark): + + r""" + Schwefel 4 objective function. + + This class defines the Schwefel 4 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schwefel04}}(x) = \sum_{i=1}^n \left[(x_i - 1)^2 + + (x_1 - x_i^2)^2 \right] + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [0, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for:math:`x_i = 1` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([0.0] * self.N, [10.0] * self.N)) + self.custom_bounds = ([0.0, 2.0], [0.0, 2.0]) + + self.global_optimum = [[1.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum((x - 1.0) ** 2.0 + (x[0] - x ** 2.0) ** 2.0) + + +class Schwefel06(Benchmark): + + r""" + Schwefel 6 objective function. + + This class defines the Schwefel 6 [1]_ global optimization problem. This + is a unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schwefel06}}(x) = \max(\lvert x_1 + 2x_2 - 7 \rvert, + \lvert 2x_1 + x_2 - 5 \rvert) + + + with :math:`x_i \in [-100, 100]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 3]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = ([-10.0, 10.0], [-10.0, 10.0]) + + self.global_optimum = [[1.0, 3.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return max(abs(x[0] + 2 * x[1] - 7), abs(2 * x[0] + x[1] - 5)) + + +class Schwefel20(Benchmark): + + r""" + Schwefel 20 objective function. + + This class defines the Schwefel 20 [1]_ global optimization problem. This + is a unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schwefel20}}(x) = \sum_{i=1}^n \lvert x_i \rvert + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-100, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: Jamil #122 is incorrect. There shouldn't be a leading minus sign. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(abs(x)) + + +class Schwefel21(Benchmark): + + r""" + Schwefel 21 objective function. + + This class defines the Schwefel 21 [1]_ global optimization problem. This + is a unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schwefel21}}(x) = \smash{\displaystyle\max_{1 \leq i \leq n}} + \lvert x_i \rvert + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-100, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return max(abs(x)) + + +class Schwefel22(Benchmark): + + r""" + Schwefel 22 objective function. + + This class defines the Schwefel 22 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schwefel22}}(x) = \sum_{i=1}^n \lvert x_i \rvert + + \prod_{i=1}^n \lvert x_i \rvert + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-100, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = ([-10.0, 10.0], [-10.0, 10.0]) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(abs(x)) + prod(abs(x)) + + +class Schwefel26(Benchmark): + + r""" + Schwefel 26 objective function. + + This class defines the Schwefel 26 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schwefel26}}(x) = 418.9829n - \sum_{i=1}^n x_i + \sin(\sqrt{|x_i|}) + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-500, 500]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 420.968746` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-500.0] * self.N, + [500.0] * self.N)) + + self.global_optimum = [[420.968746 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return 418.982887 * self.N - sum(x * sin(sqrt(abs(x)))) + + +class Schwefel36(Benchmark): + + r""" + Schwefel 36 objective function. + + This class defines the Schwefel 36 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Schwefel36}}(x) = -x_1x_2(72 - 2x_1 - 2x_2) + + + with :math:`x_i \in [0, 500]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -3456` for :math:`x = [12, 12]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([0.0] * self.N, [500.0] * self.N)) + self.custom_bounds = ([0.0, 20.0], [0.0, 20.0]) + + self.global_optimum = [[12.0, 12.0]] + self.fglob = -3456.0 + + def fun(self, x, *args): + self.nfev += 1 + + return -x[0] * x[1] * (72 - 2 * x[0] - 2 * x[1]) + + +class Shekel05(Benchmark): + + r""" + Shekel 5 objective function. + + This class defines the Shekel 5 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Shekel05}}(x) = \sum_{i=1}^{m} \frac{1}{c_{i} + + \sum_{j=1}^{n} (x_{j} - a_{ij})^2 }` + + Where, in this exercise: + + .. math:: + + a = + \begin{bmatrix} + 4.0 & 4.0 & 4.0 & 4.0 \\ 1.0 & 1.0 & 1.0 & 1.0 \\ + 8.0 & 8.0 & 8.0 & 8.0 \\ 6.0 & 6.0 & 6.0 & 6.0 \\ + 3.0 & 7.0 & 3.0 & 7.0 + \end{bmatrix} + .. math:: + + c = \begin{bmatrix} 0.1 \\ 0.2 \\ 0.2 \\ 0.4 \\ 0.4 \end{bmatrix} + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [0, 10]` for :math:`i = 1, ..., 4`. + + *Global optimum*: :math:`f(x) = -10.15319585` for :math:`x_i = 4` for + :math:`i = 1, ..., 4` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: this is a different global minimum compared to Jamil#130. The + minimum is found by doing lots of optimisations. The solution is supposed + to be at [4] * N, is there any numerical overflow? + """ + + def __init__(self, dimensions=4): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[4.00003715092, + 4.00013327435, + 4.00003714871, + 4.0001332742]] + self.fglob = -10.1531996791 + self.A = asarray([[4.0, 4.0, 4.0, 4.0], + [1.0, 1.0, 1.0, 1.0], + [8.0, 8.0, 8.0, 8.0], + [6.0, 6.0, 6.0, 6.0], + [3.0, 7.0, 3.0, 7.0]]) + + self.C = asarray([0.1, 0.2, 0.2, 0.4, 0.4]) + + def fun(self, x, *args): + self.nfev += 1 + + return -sum(1 / (sum((x - self.A) ** 2, axis=1) + self.C)) + + +class Shekel07(Benchmark): + + r""" + Shekel 7 objective function. + + This class defines the Shekel 7 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Shekel07}}(x) = \sum_{i=1}^{m} \frac{1}{c_{i} + + \sum_{j=1}^{n} (x_{j} - a_{ij})^2 }` + + Where, in this exercise: + + .. math:: + + a = + \begin{bmatrix} + 4.0 & 4.0 & 4.0 & 4.0 \\ 1.0 & 1.0 & 1.0 & 1.0 \\ + 8.0 & 8.0 & 8.0 & 8.0 \\ 6.0 & 6.0 & 6.0 & 6.0 \\ + 3.0 & 7.0 & 3.0 & 7.0 \\ 2.0 & 9.0 & 2.0 & 9.0 \\ + 5.0 & 5.0 & 3.0 & 3.0 + \end{bmatrix} + + + .. math:: + + c = + \begin{bmatrix} + 0.1 \\ 0.2 \\ 0.2 \\ 0.4 \\ 0.4 \\ 0.6 \\ 0.3 + \end{bmatrix} + + + with :math:`x_i \in [0, 10]` for :math:`i = 1, ..., 4`. + + *Global optimum*: :math:`f(x) = -10.4028188` for :math:`x_i = 4` for + :math:`i = 1, ..., 4` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: this is a different global minimum compared to Jamil#131. This + minimum is obtained after running lots of minimisations! Is there any + numerical overflow that causes the minimum solution to not be [4] * N? + """ + + def __init__(self, dimensions=4): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[4.00057291078, + 4.0006893679, + 3.99948971076, + 3.99960615785]] + self.fglob = -10.4029405668 + self.A = asarray([[4.0, 4.0, 4.0, 4.0], + [1.0, 1.0, 1.0, 1.0], + [8.0, 8.0, 8.0, 8.0], + [6.0, 6.0, 6.0, 6.0], + [3.0, 7.0, 3.0, 7.0], + [2.0, 9.0, 2.0, 9.0], + [5.0, 5.0, 3.0, 3.0]]) + + self.C = asarray([0.1, 0.2, 0.2, 0.4, 0.4, 0.6, 0.3]) + + def fun(self, x, *args): + self.nfev += 1 + + return -sum(1 / (sum((x - self.A) ** 2, axis=1) + self.C)) + + +class Shekel10(Benchmark): + + r""" + Shekel 10 objective function. + + This class defines the Shekel 10 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Shekel10}}(x) = \sum_{i=1}^{m} \frac{1}{c_{i} + + \sum_{j=1}^{n} (x_{j} - a_{ij})^2 }` + + Where, in this exercise: + + .. math:: + + a = + \begin{bmatrix} + 4.0 & 4.0 & 4.0 & 4.0 \\ 1.0 & 1.0 & 1.0 & 1.0 \\ + 8.0 & 8.0 & 8.0 & 8.0 \\ 6.0 & 6.0 & 6.0 & 6.0 \\ + 3.0 & 7.0 & 3.0 & 7.0 \\ 2.0 & 9.0 & 2.0 & 9.0 \\ + 5.0 & 5.0 & 3.0 & 3.0 \\ 8.0 & 1.0 & 8.0 & 1.0 \\ + 6.0 & 2.0 & 6.0 & 2.0 \\ 7.0 & 3.6 & 7.0 & 3.6 + \end{bmatrix} + + + .. math:: + + c = + \begin{bmatrix} + 0.1 \\ 0.2 \\ 0.2 \\ 0.4 \\ 0.4 \\ 0.6 \\ 0.3 \\ 0.7 \\ 0.5 \\ 0.5 + \end{bmatrix} + + + with :math:`x_i \in [0, 10]` for :math:`i = 1, ..., 4`. + + *Global optimum*: :math:`f(x) = -10.5362837` for :math:`x_i = 4` for + :math:`i = 1, ..., 4` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO Found a lower global minimum than Jamil#132... Is this numerical overflow? + """ + + def __init__(self, dimensions=4): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[4.0007465377266271, + 4.0005929234621407, + 3.9996633941680968, + 3.9995098017834123]] + self.fglob = -10.536409816692023 + self.A = asarray([[4.0, 4.0, 4.0, 4.0], + [1.0, 1.0, 1.0, 1.0], + [8.0, 8.0, 8.0, 8.0], + [6.0, 6.0, 6.0, 6.0], + [3.0, 7.0, 3.0, 7.0], + [2.0, 9.0, 2.0, 9.0], + [5.0, 5.0, 3.0, 3.0], + [8.0, 1.0, 8.0, 1.0], + [6.0, 2.0, 6.0, 2.0], + [7.0, 3.6, 7.0, 3.6]]) + + self.C = asarray([0.1, 0.2, 0.2, 0.4, 0.4, 0.6, 0.3, 0.7, 0.5, 0.5]) + + def fun(self, x, *args): + self.nfev += 1 + + return -sum(1 / (sum((x - self.A) ** 2, axis=1) + self.C)) + + +class Shubert01(Benchmark): + + r""" + Shubert 1 objective function. + + This class defines the Shubert 1 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Shubert01}}(x) = \prod_{i=1}^{n}\left(\sum_{j=1}^{5} + cos(j+1)x_i+j \right ) + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = -186.7309` for + :math:`x = [-7.0835, 4.8580]` (and many others). + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO: Jamil#133 is missing a prefactor of j before the cos function. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.global_optimum = [[-7.0835, 4.8580]] + + self.fglob = -186.7309 + + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + j = atleast_2d(arange(1, 6)).T + y = j * cos((j + 1) * x + j) + return prod(sum(y, axis=0)) + + +class Shubert03(Benchmark): + + r""" + Shubert 3 objective function. + + This class defines the Shubert 3 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Shubert03}}(x) = \sum_{i=1}^n \sum_{j=1}^5 -j + \sin((j+1)x_i + j) + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = -24.062499` for + :math:`x = [5.791794, 5.791794]` (and many others). + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO: Jamil#134 has wrong global minimum value, and is missing a minus sign + before the whole thing. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[5.791794, 5.791794]] + self.fglob = -24.062499 + + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + j = atleast_2d(arange(1, 6)).T + y = -j * sin((j + 1) * x + j) + return sum(sum(y)) + + +class Shubert04(Benchmark): + + r""" + Shubert 4 objective function. + + This class defines the Shubert 4 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Shubert04}}(x) = \left(\sum_{i=1}^n \sum_{j=1}^5 -j + \cos ((j+1)x_i + j)\right) + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = -29.016015` for + :math:`x = [-0.80032121, -7.08350592]` (and many others). + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO: Jamil#135 has wrong global minimum value, and is missing a minus sign + before the whole thing. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[-0.80032121, -7.08350592]] + self.fglob = -29.016015 + + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + j = atleast_2d(arange(1, 6)).T + y = -j * cos((j + 1) * x + j) + return sum(sum(y)) + + +class SineEnvelope(Benchmark): + + r""" + SineEnvelope objective function. + + This class defines the SineEnvelope [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{SineEnvelope}}(x) = -\sum_{i=1}^{n-1}\left[\frac{\sin^2( + \sqrt{x_{i+1}^2+x_{i}^2}-0.5)} + {(0.001(x_{i+1}^2+x_{i}^2)+1)^2} + + 0.5\right] + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-100, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO: Jamil #136 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = [(-20, 20), (-20, 20)] + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + X0 = x[:-1] + X1 = x[1:] + X02X12 = X0 ** 2 + X1 ** 2 + return sum((sin(sqrt(X02X12)) ** 2 - 0.5) / (1 + 0.001 * X02X12) ** 2 + + 0.5) + + +class SixHumpCamel(Benchmark): + + r""" + Six Hump Camel objective function. + + This class defines the Six Hump Camel [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{SixHumpCamel}}(x) = 4x_1^2+x_1x_2-4x_2^2-2.1x_1^4+ + 4x_2^4+\frac{1}{3}x_1^6 + + with :math:`x_i \in [-5, 5]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -1.031628453489877` for + :math:`x = [0.08984201368301331 , -0.7126564032704135]` or + :math:`x = [-0.08984201368301331, 0.7126564032704135]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + self.custom_bounds = [(-2, 2), (-1.5, 1.5)] + + self.global_optimum = [(0.08984201368301331, -0.7126564032704135), + (-0.08984201368301331, 0.7126564032704135)] + self.fglob = -1.031628 + + def fun(self, x, *args): + self.nfev += 1 + return ((4 - 2.1 * x[0] ** 2 + x[0] ** 4 / 3) * x[0] ** 2 + x[0] * x[1] + + (4 * x[1] ** 2 - 4) * x[1] ** 2) + + +class Sodp(Benchmark): + + r""" + Sodp objective function. + + This class defines the Sum Of Different Powers [1]_ global optimization + problem. This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Sodp}}(x) = \sum_{i=1}^{n} \lvert{x_{i}}\rvert^{i + 1} + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-1, 1]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-1.0] * self.N, [1.0] * self.N)) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + i = arange(1, self.N + 1) + return sum(abs(x) ** (i + 1)) + + +class Sphere(Benchmark): + + r""" + Sphere objective function. + + This class defines the Sphere [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Sphere}}(x) = \sum_{i=1}^{n} x_i^2 + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-1, 1]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO Jamil has stupid limits + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-5.12] * self.N, [5.12] * self.N)) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(x ** 2) + + +class Step(Benchmark): + + r""" + Step objective function. + + This class defines the Step [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Step}}(x) = \sum_{i=1}^{n} \left ( \lfloor x_i + + 0.5 \rfloor \right )^2 + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-100, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0.5` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = ([-5, 5], [-5, 5]) + + self.global_optimum = [[0. for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(floor(abs(x))) + + +class Step2(Benchmark): + + r""" + Step objective function. + + This class defines the Step 2 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Step}}(x) = \sum_{i=1}^{n} \left ( \lfloor x_i + + 0.5 \rfloor \right )^2 + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-100, 100]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0.5` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + self.custom_bounds = ([-5, 5], [-5, 5]) + + self.global_optimum = [[0.5 for _ in range(self.N)]] + self.fglob = 0.5 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum((floor(x) + 0.5) ** 2.0) + + +class Stochastic(Benchmark): + + r""" + Stochastic objective function. + + This class defines the Stochastic [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Stochastic}}(x) = \sum_{i=1}^{n} \epsilon_i + \left | {x_i - \frac{1}{i}} \right | + + The variable :math:`\epsilon_i, (i=1,...,n)` is a random variable uniformly + distributed in :math:`[0, 1]`. + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-5, 5]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = [1/n]` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + + self.global_optimum = [[1.0 / _ for _ in range(1, self.N + 1)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + rnd = uniform(0.0, 1.0, size=(self.N, )) + i = arange(1, self.N + 1) + + return sum(rnd * abs(x - 1.0 / i)) + + +class StretchedV(Benchmark): + + r""" + StretchedV objective function. + + This class defines the Stretched V [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{StretchedV}}(x) = \sum_{i=1}^{n-1} t^{1/4} + [\sin (50t^{0.1}) + 1]^2 + + Where, in this exercise: + + .. math:: + + t = x_{i+1}^2 + x_i^2 + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0., 0.]` when + :math:`n = 2`. + + .. [1] Adorio, E. MVF - "Multivariate Test Functions Library in C for + Unconstrained Global Optimization", 2005 + + TODO All the sources disagree on the equation, in some the 1 is in the + brackets, in others it is outside. In Jamil#142 it's not even 1. Here + we go with the Adorio option. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10] * self.N, [10] * self.N)) + + self.global_optimum = [[0, 0]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + t = x[1:] ** 2 + x[: -1] ** 2 + return sum(t ** 0.25 * (sin(50.0 * t ** 0.1 + 1) ** 2)) + + +class StyblinskiTang(Benchmark): + + r""" + StyblinskiTang objective function. + + This class defines the Styblinski-Tang [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{StyblinskiTang}}(x) = \sum_{i=1}^{n} \left(x_i^4 + - 16x_i^2 + 5x_i \right) + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-5, 5]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = -39.16616570377142n` for + :math:`x_i = -2.903534018185960` for :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + + self.global_optimum = [[-2.903534018185960 for _ in range(self.N)]] + self.fglob = -39.16616570377142 * self.N + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(x ** 4 - 16 * x ** 2 + 5 * x) / 2 diff --git a/go_benchmark_functions/go_funcs_T.py b/go_benchmark_functions/go_funcs_T.py new file mode 100644 index 0000000..13b72ee --- /dev/null +++ b/go_benchmark_functions/go_funcs_T.py @@ -0,0 +1,389 @@ +# -*- coding: utf-8 -*- +from numpy import abs, asarray, cos, exp, arange, pi, sin, sum, atleast_2d +from .go_benchmark import Benchmark + + +class TestTubeHolder(Benchmark): + + r""" + TestTubeHolder objective function. + + This class defines the TestTubeHolder [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{TestTubeHolder}}(x) = - 4 \left | {e^{\left|{\cos + \left(\frac{1}{200} x_{1}^{2} + \frac{1}{200} x_{2}^{2}\right)} + \right|}\sin\left(x_{1}\right) \cos\left(x_{2}\right)}\right| + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -10.872299901558` for + :math:`x= [-\pi/2, 0]` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO Jamil#148 has got incorrect equation, missing an abs around the square + brackets + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[-pi / 2, 0.0]] + self.fglob = -10.87229990155800 + + def fun(self, x, *args): + self.nfev += 1 + + u = sin(x[0]) * cos(x[1]) + v = (x[0] ** 2 + x[1] ** 2) / 200 + return -4 * abs(u * exp(abs(cos(v)))) + + +class Thurber(Benchmark): + + r""" + Thurber [1]_ objective function. + + .. [1] https://www.itl.nist.gov/div898/strd/nls/data/thurber.shtml + """ + + def __init__(self, dimensions=7): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip( + [500., 500., 100., 10., 0.1, 0.1, 0.], + [2000., 2000., 1000., 150., 2., 1., 0.2])) + self.global_optimum = [[1.288139680e3, 1.4910792535e3, 5.8323836877e2, + 75.416644291, 0.96629502864, 0.39797285797, + 4.9727297349e-2]] + self.fglob = 5642.7082397 + self.a = asarray([80.574, 84.248, 87.264, 87.195, 89.076, 89.608, + 89.868, 90.101, 92.405, 95.854, 100.696, 101.06, + 401.672, 390.724, 567.534, 635.316, 733.054, 759.087, + 894.206, 990.785, 1090.109, 1080.914, 1122.643, + 1178.351, 1260.531, 1273.514, 1288.339, 1327.543, + 1353.863, 1414.509, 1425.208, 1421.384, 1442.962, + 1464.350, 1468.705, 1447.894, 1457.628]) + self.b = asarray([-3.067, -2.981, -2.921, -2.912, -2.840, -2.797, + -2.702, -2.699, -2.633, -2.481, -2.363, -2.322, + -1.501, -1.460, -1.274, -1.212, -1.100, -1.046, + -0.915, -0.714, -0.566, -0.545, -0.400, -0.309, + -0.109, -0.103, 0.010, 0.119, 0.377, 0.790, 0.963, + 1.006, 1.115, 1.572, 1.841, 2.047, 2.200]) + + def fun(self, x, *args): + self.nfev += 1 + + vec = x[0] + x[1] * self.b + x[2] * self.b ** 2 + x[3] * self.b ** 3 + vec /= 1 + x[4] * self.b + x[5] * self.b ** 2 + x[6] * self.b ** 3 + + return sum((self.a - vec) ** 2) + + +class Treccani(Benchmark): + + r""" + Treccani objective function. + + This class defines the Treccani [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Treccani}}(x) = x_1^4 + 4x_1^3 + 4x_1^2 + x_2^2 + + + with :math:`x_i \in + [-5, 5]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [-2, 0]` or + :math:`x = [0, 0]`. + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + self.custom_bounds = [(-2, 2), (-2, 2)] + + self.global_optimum = [[-2.0, 0.0]] + self.fglob = 0 + + def fun(self, x, *args): + self.nfev += 1 + + return x[0] ** 4 + 4.0 * x[0] ** 3 + 4.0 * x[0] ** 2 + x[1] ** 2 + + +class Trefethen(Benchmark): + + r""" + Trefethen objective function. + + This class defines the Trefethen [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Trefethen}}(x) = 0.25 x_{1}^{2} + 0.25 x_{2}^{2} + + e^{\sin\left(50 x_{1}\right)} + - \sin\left(10 x_{1} + 10 x_{2}\right) + + \sin\left(60 e^{x_{2}}\right) + + \sin\left[70 \sin\left(x_{1}\right)\right] + + \sin\left[\sin\left(80 x_{2}\right)\right] + + + with :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -3.3068686474` for + :math:`x = [-0.02440307923, 0.2106124261]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = [(-5, 5), (-5, 5)] + + self.global_optimum = [[-0.02440307923, 0.2106124261]] + self.fglob = -3.3068686474 + + def fun(self, x, *args): + self.nfev += 1 + + val = 0.25 * x[0] ** 2 + 0.25 * x[1] ** 2 + val += exp(sin(50. * x[0])) - sin(10 * x[0] + 10 * x[1]) + val += sin(60 * exp(x[1])) + val += sin(70 * sin(x[0])) + val += sin(sin(80 * x[1])) + return val + + +class ThreeHumpCamel(Benchmark): + + r""" + Three Hump Camel objective function. + + This class defines the Three Hump Camel [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{ThreeHumpCamel}}(x) = 2x_1^2 - 1.05x_1^4 + \frac{x_1^6}{6} + + x_1x_2 + x_2^2 + + + with :math:`x_i \in [-5, 5]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + self.custom_bounds = [(-2, 2), (-1.5, 1.5)] + + self.global_optimum = [[0.0, 0.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return (2.0 * x[0] ** 2.0 - 1.05 * x[0] ** 4.0 + x[0] ** 6 / 6.0 + + x[0] * x[1] + x[1] ** 2.0) + + +class Trid(Benchmark): + + r""" + Trid objective function. + + This class defines the Trid [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Trid}}(x) = \sum_{i=1}^{n} (x_i - 1)^2 + - \sum_{i=2}^{n} x_i x_{i-1} + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-20, 20]` for :math:`i = 1, ..., 6`. + + *Global optimum*: :math:`f(x) = -50` for :math:`x = [6, 10, 12, 12, 10, 6]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO Jamil#150, starting index of second summation term should be 2. + """ + + def __init__(self, dimensions=6): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-20.0] * self.N, [20.0] * self.N)) + + self.global_optimum = [[6, 10, 12, 12, 10, 6]] + self.fglob = -50.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum((x - 1.0) ** 2.0) - sum(x[1:] * x[:-1]) + + +class Trigonometric01(Benchmark): + + r""" + Trigonometric 1 objective function. + + This class defines the Trigonometric 1 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Trigonometric01}}(x) = \sum_{i=1}^{n} \left [n - + \sum_{j=1}^{n} \cos(x_j) + + i \left(1 - cos(x_i) + - sin(x_i) \right ) \right]^2 + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [0, \pi]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO: equaiton uncertain here. Is it just supposed to be the cos term + in the inner sum, or the whole of the second line in Jamil #153. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [pi] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + i = atleast_2d(arange(1.0, self.N + 1)).T + inner = cos(x) + i * (1 - cos(x) - sin(x)) + return sum((self.N - sum(inner, axis=1)) ** 2) + + +class Trigonometric02(Benchmark): + + r""" + Trigonometric 2 objective function. + + This class defines the Trigonometric 2 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Trigonometric2}}(x) = 1 + \sum_{i=1}^{n} 8 \sin^2 + \left[7(x_i - 0.9)^2 \right] + + 6 \sin^2 \left[14(x_i - 0.9)^2 \right] + + (x_i - 0.9)^2 + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-500, 500]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 1` for :math:`x_i = 0.9` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-500.0] * self.N, + [500.0] * self.N)) + self.custom_bounds = [(0, 2), (0, 2)] + + self.global_optimum = [[0.9 for _ in range(self.N)]] + self.fglob = 1.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + vec = (8 * sin(7 * (x - 0.9) ** 2) ** 2 + + 6 * sin(14 * (x - 0.9) ** 2) ** 2 + + (x - 0.9) ** 2) + return 1.0 + sum(vec) + + +class Tripod(Benchmark): + + r""" + Tripod objective function. + + This class defines the Tripod [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Tripod}}(x) = p(x_2) \left[1 + p(x_1) \right] + + \lvert x_1 + 50p(x_2) \left[1 - 2p(x_1) \right] + \rvert + \lvert x_2 + 50\left[1 - 2p(x_2)\right] + \rvert + + with :math:`x_i \in [-100, 100]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, -50]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-100.0] * self.N, + [100.0] * self.N)) + + self.global_optimum = [[0.0, -50.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + p1 = float(x[0] >= 0) + p2 = float(x[1] >= 0) + + return (p2 * (1.0 + p1) + abs(x[0] + 50.0 * p2 * (1.0 - 2.0 * p1)) + + abs(x[1] + 50.0 * (1.0 - 2.0 * p2))) diff --git a/go_benchmark_functions/go_funcs_U.py b/go_benchmark_functions/go_funcs_U.py new file mode 100644 index 0000000..5adb875 --- /dev/null +++ b/go_benchmark_functions/go_funcs_U.py @@ -0,0 +1,166 @@ +# -*- coding: utf-8 -*- +from numpy import abs, sin, cos, pi, sqrt +from .go_benchmark import Benchmark + + +class Ursem01(Benchmark): + + r""" + Ursem 1 objective function. + + This class defines the Ursem 1 [1]_ global optimization problem. This is a + unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Ursem01}}(x) = - \sin(2x_1 - 0.5 \pi) - 3 \cos(x_2) - 0.5 x_1 + + with :math:`x_1 \in [-2.5, 3]` and :math:`x_2 \in [-2, 2]`. + + *Global optimum*: :math:`f(x) = -4.81681406371` for + :math:`x = [1.69714, 0.0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-2.5, 3.0), (-2.0, 2.0)] + + self.global_optimum = [[1.69714, 0.0]] + self.fglob = -4.81681406371 + + def fun(self, x, *args): + self.nfev += 1 + + return -sin(2 * x[0] - 0.5 * pi) - 3.0 * cos(x[1]) - 0.5 * x[0] + + +class Ursem03(Benchmark): + + r""" + Ursem 3 objective function. + + This class defines the Ursem 3 [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Ursem03}}(x) = - \sin(2.2 \pi x_1 + 0.5 \pi) + \frac{2 - \lvert x_1 \rvert}{2} + \frac{3 - \lvert x_1 \rvert}{2} + - \sin(2.2 \pi x_2 + 0.5 \pi) + \frac{2 - \lvert x_2 \rvert}{2} + \frac{3 - \lvert x_2 \rvert}{2} + + with :math:`x_1 \in [-2, 2]`, :math:`x_2 \in [-1.5, 1.5]`. + + *Global optimum*: :math:`f(x) = -3` for :math:`x = [0, 0]` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO Gavana and Jamil #157 disagree on the formulae here. Jamil squares the + x[1] term in the sine expression. Gavana doesn't. Go with Gavana here. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-2, 2), (-1.5, 1.5)] + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = -3.0 + + def fun(self, x, *args): + self.nfev += 1 + + u = -(sin(2.2 * pi * x[0] + 0.5 * pi) + * ((2.0 - abs(x[0])) / 2.0) * ((3.0 - abs(x[0])) / 2)) + v = -(sin(2.2 * pi * x[1] + 0.5 * pi) + * ((2.0 - abs(x[1])) / 2) * ((3.0 - abs(x[1])) / 2)) + return u + v + + +class Ursem04(Benchmark): + + r""" + Ursem 4 objective function. + + This class defines the Ursem 4 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Ursem04}}(x) = -3 \sin(0.5 \pi x_1 + 0.5 \pi) + \frac{2 - \sqrt{x_1^2 + x_2 ^ 2}}{4} + + with :math:`x_i \in [-2, 2]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -1.5` for :math:`x = [0, 0]` for + :math:`i = 1, 2` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-2.0] * self.N, [2.0] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = -1.5 + + def fun(self, x, *args): + self.nfev += 1 + + return (-3 * sin(0.5 * pi * x[0] + 0.5 * pi) + * (2 - sqrt(x[0] ** 2 + x[1] ** 2)) / 4) + + +class UrsemWaves(Benchmark): + + r""" + Ursem Waves objective function. + + This class defines the Ursem Waves [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{UrsemWaves}}(x) = -0.9x_1^2 + (x_2^2 - 4.5x_2^2)x_1x_2 + + 4.7 \cos \left[ 2x_1 - x_2^2(2 + x_1) + \right ] \sin(2.5 \pi x_1) + + with :math:`x_1 \in [-0.9, 1.2]`, :math:`x_2 \in [-1.2, 1.2]`. + + *Global optimum*: :math:`f(x) = -8.5536` for :math:`x = [1.2, 1.2]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO Jamil #159, has an x_2^2 - 4.5 x_2^2 in the brackets. Why wasn't this + rationalised to -5.5 x_2^2? This makes me wonder if the equation is listed + correctly? + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-0.9, 1.2), (-1.2, 1.2)] + + self.global_optimum = [[1.2 for _ in range(self.N)]] + self.fglob = -8.5536 + + def fun(self, x, *args): + self.nfev += 1 + + u = -0.9 * x[0] ** 2 + v = (x[1] ** 2 - 4.5 * x[1] ** 2) * x[0] * x[1] + w = 4.7 * cos(3 * x[0] - x[1] ** 2 * (2 + x[0])) * sin(2.5 * pi * x[0]) + return u + v + w diff --git a/go_benchmark_functions/go_funcs_V.py b/go_benchmark_functions/go_funcs_V.py new file mode 100644 index 0000000..b56cace --- /dev/null +++ b/go_benchmark_functions/go_funcs_V.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +from numpy import sum, cos, sin, log +from .go_benchmark import Benchmark + + +class VenterSobiezcczanskiSobieski(Benchmark): + + r""" + Venter Sobiezcczanski-Sobieski objective function. + + This class defines the Venter Sobiezcczanski-Sobieski [1]_ global optimization + problem. This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{VenterSobiezcczanskiSobieski}}(x) = x_1^2 - 100 \cos^2(x_1) + - 100 \cos(x_1^2/30) + + x_2^2 - 100 \cos^2(x_2) + - 100 \cos(x_2^2/30) + + + with :math:`x_i \in [-50, 50]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -400` for :math:`x = [0, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO Jamil #160 hasn't written the equation very well. Normally a cos + squared term is written as cos^2(x) rather than cos(x)^2 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-50.0] * self.N, [50.0] * self.N)) + self.custom_bounds = ([-10, 10], [-10, 10]) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = -400 + + def fun(self, x, *args): + self.nfev += 1 + + u = x[0] ** 2.0 - 100.0 * cos(x[0]) ** 2.0 + v = -100.0 * cos(x[0] ** 2.0 / 30.0) + x[1] ** 2.0 + w = - 100.0 * cos(x[1]) ** 2.0 - 100.0 * cos(x[1] ** 2.0 / 30.0) + return u + v + w + + +class Vincent(Benchmark): + + r""" + Vincent objective function. + + This class defines the Vincent [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Vincent}}(x) = - \sum_{i=1}^{n} \sin(10 \log(x)) + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [0.25, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = -n` for :math:`x_i = 7.70628098` + for :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.25] * self.N, [10.0] * self.N)) + + self.global_optimum = [[7.70628098 for _ in range(self.N)]] + self.fglob = -float(self.N) + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return -sum(sin(10.0 * log(x))) diff --git a/go_benchmark_functions/go_funcs_W.py b/go_benchmark_functions/go_funcs_W.py new file mode 100644 index 0000000..a5ea0c4 --- /dev/null +++ b/go_benchmark_functions/go_funcs_W.py @@ -0,0 +1,323 @@ +# -*- coding: utf-8 -*- +from numpy import atleast_2d, arange, sum, cos, exp, pi +from .go_benchmark import Benchmark + + +class Watson(Benchmark): + + r""" + Watson objective function. + + This class defines the Watson [1]_ global optimization problem. This is a + unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Watson}}(x) = \sum_{i=0}^{29} \left\{ + \sum_{j=0}^4 ((j + 1)a_i^j x_{j+1}) + - \left[ \sum_{j=0}^5 a_i^j + x_{j+1} \right ]^2 - 1 \right\}^2 + + x_1^2 + + + Where, in this exercise, :math:`a_i = i/29`. + + with :math:`x_i \in [-5, 5]` for :math:`i = 1, ..., 6`. + + *Global optimum*: :math:`f(x) = 0.002288` for + :math:`x = [-0.0158, 1.012, -0.2329, 1.260, -1.513, 0.9928]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + + TODO Jamil #161 writes equation using (j - 1). According to code in Adorio + and Gavana it should be (j+1). However the equations in those papers + contain (j - 1) as well. However, I've got the right global minimum!!! + """ + + def __init__(self, dimensions=6): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + + self.global_optimum = [[-0.0158, 1.012, -0.2329, 1.260, -1.513, + 0.9928]] + self.fglob = 0.002288 + + def fun(self, x, *args): + self.nfev += 1 + + i = atleast_2d(arange(30.)).T + a = i / 29. + j = arange(5.) + k = arange(6.) + + t1 = sum((j + 1) * a ** j * x[1:], axis=1) + t2 = sum(a ** k * x, axis=1) + + inner = (t1 - t2 ** 2 - 1) ** 2 + + return sum(inner) + x[0] ** 2 + + +class Wavy(Benchmark): + + r""" + Wavy objective function. + + This class defines the W / Wavy [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Wavy}}(x) = 1 - \frac{1}{n} \sum_{i=1}^{n} + \cos(kx_i)e^{-\frac{x_i^2}{2}} + + + Where, in this exercise, :math:`k = 10`. The number of local minima is + :math:`kn` and :math:`(k + 1)n` for odd and even :math:`k` respectively. + + Here, :math:`x_i \in [-\pi, \pi]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-pi] * self.N, [pi] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return 1.0 - (1.0 / self.N) * sum(cos(10 * x) * exp(-x ** 2.0 / 2.0)) + + +class WayburnSeader01(Benchmark): + + r""" + Wayburn and Seader 1 objective function. + + This class defines the Wayburn and Seader 1 [1]_ global optimization + problem. This is a unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{WayburnSeader01}}(x) = (x_1^6 + x_2^4 - 17)^2 + + (2x_1 + x_2 - 4)^2 + + + with :math:`x_i \in [-5, 5]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [1, 2]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + self.custom_bounds = ([-2, 2], [-2, 2]) + + self.global_optimum = [[1.0, 2.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return (x[0] ** 6 + x[1] ** 4 - 17) ** 2 + (2 * x[0] + x[1] - 4) ** 2 + + +class WayburnSeader02(Benchmark): + + r""" + Wayburn and Seader 2 objective function. + + This class defines the Wayburn and Seader 2 [1]_ global optimization + problem. This is a unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{WayburnSeader02}}(x) = \left[ 1.613 - 4(x_1 - 0.3125)^2 + - 4(x_2 - 1.625)^2 \right]^2 + + (x_2 - 1)^2 + + + with :math:`x_i \in [-500, 500]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0.2, 1]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-500.0] * self.N, + [500.0] * self.N)) + self.custom_bounds = ([-1, 2], [-1, 2]) + + self.global_optimum = [[0.2, 1.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + u = (1.613 - 4 * (x[0] - 0.3125) ** 2 - 4 * (x[1] - 1.625) ** 2) ** 2 + v = (x[1] - 1) ** 2 + return u + v + + +class Weierstrass(Benchmark): + + r""" + Weierstrass objective function. + + This class defines the Weierstrass [1]_ global optimization problem. + This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Weierstrass}}(x) = \sum_{i=1}^{n} \left [ + \sum_{k=0}^{kmax} a^k \cos + \left( 2 \pi b^k (x_i + 0.5) \right) - n + \sum_{k=0}^{kmax} a^k \cos(\pi b^k) \right ] + + + Where, in this exercise, :math:`kmax = 20`, :math:`a = 0.5` and + :math:`b = 3`. + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-0.5, 0.5]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 4` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO line 1591. + TODO Jamil, Gavana have got it wrong. The second term is not supposed to + be included in the outer sum. Mishra code has it right as does the + reference referred to in Jamil#166. + """ + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-0.5] * self.N, [0.5] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + kmax = 20 + a, b = 0.5, 3.0 + + k = atleast_2d(arange(kmax + 1.)).T + t1 = a ** k * cos(2 * pi * b ** k * (x + 0.5)) + t2 = self.N * sum(a ** k.T * cos(pi * b ** k.T)) + + return sum(sum(t1, axis=0)) - t2 + + +class Whitley(Benchmark): + + r""" + Whitley objective function. + + This class defines the Whitley [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Whitley}}(x) = \sum_{i=1}^n \sum_{j=1}^n + \left[\frac{(100(x_i^2-x_j)^2 + + (1-x_j)^2)^2}{4000} - \cos(100(x_i^2-x_j)^2 + + (1-x_j)^2)+1 \right] + + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10.24, 10.24]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 1` for + :math:`i = 1, ..., n` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO Jamil#167 has '+ 1' inside the cos term, when it should be outside it. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.24] * self.N, + [10.24] * self.N)) + self.custom_bounds = ([-1, 2], [-1, 2]) + + self.global_optimum = [[1.0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + XI = x + XJ = atleast_2d(x).T + + temp = 100.0 * ((XI ** 2.0) - XJ) + (1.0 - XJ) ** 2.0 + inner = (temp ** 2.0 / 4000.0) - cos(temp) + 1.0 + return sum(sum(inner, axis=0)) + + +class Wolfe(Benchmark): + + r""" + Wolfe objective function. + + This class defines the Wolfe [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Wolfe}}(x) = \frac{4}{3}(x_1^2 + x_2^2 - x_1x_2)^{0.75} + x_3 + + + with :math:`x_i \in [0, 2]` for :math:`i = 1, 2, 3`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [0, 0, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=3): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [2.0] * self.N)) + + self.global_optimum = [[0.0 for _ in range(self.N)]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + return 4 / 3 * (x[0] ** 2 + x[1] ** 2 - x[0] * x[1]) ** 0.75 + x[2] diff --git a/go_benchmark_functions/go_funcs_X.py b/go_benchmark_functions/go_funcs_X.py new file mode 100644 index 0000000..4bbb5de --- /dev/null +++ b/go_benchmark_functions/go_funcs_X.py @@ -0,0 +1,241 @@ +# -*- coding: utf-8 -*- +import numpy as np +from numpy import abs, sum, sin, cos, pi, exp, arange, prod, sqrt +from .go_benchmark import Benchmark + + +class XinSheYang01(Benchmark): + + r""" + Xin-She Yang 1 objective function. + + This class defines the Xin-She Yang 1 [1]_ global optimization problem. + This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{XinSheYang01}}(x) = \sum_{i=1}^{n} \epsilon_i \lvert x_i + \rvert^i + + + The variable :math:`\epsilon_i, (i = 1, ..., n)` is a random variable + uniformly distributed in :math:`[0, 1]`. + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-5, 5]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [5.0] * self.N)) + self.custom_bounds = ([-2, 2], [-2, 2]) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + i = arange(1.0, self.N + 1.0) + return sum(np.random.random(self.N) * (abs(x) ** i)) + + +class XinSheYang02(Benchmark): + + r""" + Xin-She Yang 2 objective function. + + This class defines the Xin-She Yang 2 [1]_ global optimization problem. + This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{XinSheYang02}}(\x) = \frac{\sum_{i=1}^{n} \lvert{x_{i}}\rvert} + {e^{\sum_{i=1}^{n} \sin\left(x_{i}^{2.0} + \right)}} + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-2\pi, 2\pi]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-2 * pi] * self.N, + [2 * pi] * self.N)) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(abs(x)) * exp(-sum(sin(x ** 2.0))) + + +class XinSheYang03(Benchmark): + + r""" + Xin-She Yang 3 objective function. + + This class defines the Xin-She Yang 3 [1]_ global optimization problem. + This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{XinSheYang03}}(x) = e^{-\sum_{i=1}^{n} (x_i/\beta)^{2m}} + - 2e^{-\sum_{i=1}^{n} x_i^2} + \prod_{i=1}^{n} \cos^2(x_i) + + + Where, in this exercise, :math:`\beta = 15` and :math:`m = 3`. + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-20, 20]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = -1` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-20.0] * self.N, [20.0] * self.N)) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = -1.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + beta, m = 15.0, 5.0 + u = sum((x / beta) ** (2 * m)) + v = sum(x ** 2) + w = prod(cos(x) ** 2) + + return exp(-u) - 2 * exp(-v) * w + + +class XinSheYang04(Benchmark): + + r""" + Xin-She Yang 4 objective function. + + This class defines the Xin-She Yang 4 [1]_ global optimization problem. + This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{XinSheYang04}}(x) = \left[ \sum_{i=1}^{n} \sin^2(x_i) + - e^{-\sum_{i=1}^{n} x_i^2} \right ] + e^{-\sum_{i=1}^{n} \sin^2 \sqrt{ \lvert + x_i \rvert }} + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = -1` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = -1.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + u = sum(sin(x) ** 2) + v = sum(x ** 2) + w = sum(sin(sqrt(abs(x))) ** 2) + return (u - exp(-v)) * exp(-w) + + +class Xor(Benchmark): + + r""" + Xor objective function. + + This class defines the Xor [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Xor}}(x) = \left[ 1 + \exp \left( - \frac{x_7}{1 + + \exp(-x_1 - x_2 - x_5)} - \frac{x_8}{1 + \exp(-x_3 - x_4 - x_6)} + - x_9 \right ) \right ]^{-2} \\ + + \left [ 1 + \exp \left( -\frac{x_7}{1 + \exp(-x_5)} + - \frac{x_8}{1 + \exp(-x_6)} - x_9 \right ) \right] ^{-2} \\ + + \left [1 - \left\{1 + \exp \left(-\frac{x_7}{1 + \exp(-x_1 - x_5)} + - \frac{x_8}{1 + \exp(-x_3 - x_6)} - x_9 \right ) \right\}^{-1} + \right ]^2 \\ + + \left [1 - \left\{1 + \exp \left(-\frac{x_7}{1 + \exp(-x_2 - x_5)} + - \frac{x_8}{1 + \exp(-x_4 - x_6)} - x_9 \right ) \right\}^{-1} + \right ]^2 + + + with :math:`x_i \in [-1, 1]` for :math:`i=1,...,9`. + + *Global optimum*: :math:`f(x) = 0.9597588` for + :math:`\x = [1, -1, 1, -1, -1, 1, 1, -1, 0.421134]` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=9): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-1.0] * self.N, [1.0] * self.N)) + + self.global_optimum = [[1.0, -1.0, 1.0, + -1.0, -1.0, 1.0, 1.0, -1.0, 0.421134]] + self.fglob = 0.9597588 + + def fun(self, x, *args): + self.nfev += 1 + + F11 = x[6] / (1.0 + exp(-x[0] - x[1] - x[4])) + F12 = x[7] / (1.0 + exp(-x[2] - x[3] - x[5])) + F1 = (1.0 + exp(-F11 - F12 - x[8])) ** (-2) + F21 = x[6] / (1.0 + exp(-x[4])) + F22 = x[7] / (1.0 + exp(-x[5])) + F2 = (1.0 + exp(-F21 - F22 - x[8])) ** (-2) + F31 = x[6] / (1.0 + exp(-x[0] - x[4])) + F32 = x[7] / (1.0 + exp(-x[2] - x[5])) + F3 = (1.0 - (1.0 + exp(-F31 - F32 - x[8])) ** (-1)) ** 2 + F41 = x[6] / (1.0 + exp(-x[1] - x[4])) + F42 = x[7] / (1.0 + exp(-x[3] - x[5])) + F4 = (1.0 - (1.0 + exp(-F41 - F42 - x[8])) ** (-1)) ** 2 + + return F1 + F2 + F3 + F4 diff --git a/go_benchmark_functions/go_funcs_Y.py b/go_benchmark_functions/go_funcs_Y.py new file mode 100644 index 0000000..2ab7485 --- /dev/null +++ b/go_benchmark_functions/go_funcs_Y.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +from numpy import abs, sum, cos, pi +from .go_benchmark import Benchmark + + +class YaoLiu04(Benchmark): + + r""" + Yao-Liu 4 objective function. + + This class defines the Yao-Liu function 4 [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{YaoLiu04}}(x) = {max}_i \left\{ \left | x_i \right | , + 1 \leq i \leq n \right\} + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Yao X., Liu Y. (1997) Fast evolution strategies. + In: Angeline P.J., Reynolds R.G., McDonnell J.R., Eberhart R. (eds) + Evolutionary Programming VI. EP 1997. + Lecture Notes in Computer Science, vol 1213. Springer, Berlin, Heidelberg + + .. [2] Mishra, S. Global Optimization by Differential Evolution and + Particle Swarm Methods: Evaluation on Some Benchmark Functions. + Munich Personal RePEc Archive, 2006, 1005 + + TODO line 1201. Gavana code and documentation differ. + max(abs(x)) != abs(max(x)) + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return abs(x).max() + + +class YaoLiu09(Benchmark): + + r""" + Yao-Liu 9 objective function. + + This class defines the Yao-Liu [1]_ function 9 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{YaoLiu09}}(x) = \sum_{i=1}^n \left [ x_i^2 + - 10 \cos(2 \pi x_i ) + 10 \right ] + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-5.12, 5.12]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Yao X., Liu Y. (1997) Fast evolution strategies. + In: Angeline P.J., Reynolds R.G., McDonnell J.R., Eberhart R. (eds) + Evolutionary Programming VI. EP 1997. + Lecture Notes in Computer Science, vol 1213. Springer, Berlin, Heidelberg + + .. [2] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.12] * self.N, [5.12] * self.N)) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + return sum(x ** 2.0 - 10.0 * cos(2 * pi * x) + 10) diff --git a/go_benchmark_functions/go_funcs_Z.py b/go_benchmark_functions/go_funcs_Z.py new file mode 100644 index 0000000..b6030b0 --- /dev/null +++ b/go_benchmark_functions/go_funcs_Z.py @@ -0,0 +1,226 @@ +# -*- coding: utf-8 -*- +from numpy import abs, sum, sign, arange +from .go_benchmark import Benchmark + + +class Zacharov(Benchmark): + + r""" + Zacharov objective function. + + This class defines the Zacharov [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Zacharov}}(x) = \sum_{i=1}^{n} x_i^2 + \left ( \frac{1}{2} + \sum_{i=1}^{n} i x_i \right )^2 + + \left ( \frac{1}{2} \sum_{i=1}^{n} i x_i + \right )^4 + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-5, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x_i = 0` for + :math:`i = 1, ..., n` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [10.0] * self.N)) + self.custom_bounds = ([-1, 1], [-1, 1]) + + self.global_optimum = [[0 for _ in range(self.N)]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + u = sum(x ** 2) + v = sum(arange(1, self.N + 1) * x) + return u + (0.5 * v) ** 2 + (0.5 * v) ** 4 + + +class ZeroSum(Benchmark): + + r""" + ZeroSum objective function. + + This class defines the ZeroSum [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{ZeroSum}}(x) = \begin{cases} + 0 & \textrm{if} \sum_{i=1}^n x_i = 0 \\ + 1 + \left(10000 \left |\sum_{i=1}^n x_i\right| + \right)^{0.5} & \textrm{otherwise} + \end{cases} + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, ..., n`. + + *Global optimum*: :math:`f(x) = 0` where :math:`\sum_{i=1}^n x_i = 0` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[]] + self.fglob = 0.0 + self.change_dimensionality = True + + def fun(self, x, *args): + self.nfev += 1 + + if abs(sum(x)) < 3e-16: + return 0.0 + return 1.0 + (10000.0 * abs(sum(x))) ** 0.5 + + +class Zettl(Benchmark): + + r""" + Zettl objective function. + + This class defines the Zettl [1]_ global optimization problem. This is a + multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Zettl}}(x) = \frac{1}{4} x_{1} + \left(x_{1}^{2} - 2 x_{1} + + x_{2}^{2}\right)^{2} + + + with :math:`x_i \in [-1, 5]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -0.0037912` for :math:`x = [-0.029896, 0.0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-5.0] * self.N, [10.0] * self.N)) + + self.global_optimum = [[-0.02989597760285287, 0.0]] + self.fglob = -0.003791237220468656 + + def fun(self, x, *args): + self.nfev += 1 + + return (x[0] ** 2 + x[1] ** 2 - 2 * x[0]) ** 2 + 0.25 * x[0] + + +class Zimmerman(Benchmark): + + r""" + Zimmerman objective function. + + This class defines the Zimmerman [1]_ global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Zimmerman}}(x) = \max \left[Zh1(x), Zp(Zh2(x)) + \textrm{sgn}(Zh2(x)), Zp(Zh3(x)) + \textrm{sgn}(Zh3(x)), + Zp(-x_1)\textrm{sgn}(x_1), + Zp(-x_2)\textrm{sgn}(x_2) \right] + + + Where, in this exercise: + + .. math:: + + \begin{cases} + Zh1(x) = 9 - x_1 - x_2 \\ + Zh2(x) = (x_1 - 3)^2 + (x_2 - 2)^2 \\ + Zh3(x) = x_1x_2 - 14 \\ + Zp(t) = 100(1 + t) + \end{cases} + + + Where :math:`x` is a vector and :math:`t` is a scalar. + + Here, :math:`x_i \in [0, 100]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = 0` for :math:`x = [7, 2]` + + .. [1] Gavana, A. Global Optimization Benchmarks and AMPGO retrieved 2015 + + TODO implementation from Gavana + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([0.0] * self.N, [100.0] * self.N)) + self.custom_bounds = ([0.0, 8.0], [0.0, 8.0]) + + self.global_optimum = [[7.0, 2.0]] + self.fglob = 0.0 + + def fun(self, x, *args): + self.nfev += 1 + + Zh1 = lambda x: 9.0 - x[0] - x[1] + Zh2 = lambda x: (x[0] - 3.0) ** 2.0 + (x[1] - 2.0) ** 2.0 - 16.0 + Zh3 = lambda x: x[0] * x[1] - 14.0 + Zp = lambda x: 100.0 * (1.0 + x) + + return max(Zh1(x), + Zp(Zh2(x)) * sign(Zh2(x)), + Zp(Zh3(x)) * sign(Zh3(x)), + Zp(-x[0]) * sign(x[0]), + Zp(-x[1]) * sign(x[1])) + + +class Zirilli(Benchmark): + + r""" + Zettl objective function. + + This class defines the Zirilli [1]_ global optimization problem. This is a + unimodal minimization problem defined as follows: + + .. math:: + + f_{\text{Zirilli}}(x) = 0.25x_1^4 - 0.5x_1^2 + 0.1x_1 + 0.5x_2^2 + + Here, :math:`n` represents the number of dimensions and + :math:`x_i \in [-10, 10]` for :math:`i = 1, 2`. + + *Global optimum*: :math:`f(x) = -0.3523` for :math:`x = [-1.0465, 0]` + + .. [1] Jamil, M. & Yang, X.-S. A Literature Survey of Benchmark Functions + For Global Optimization Problems Int. Journal of Mathematical Modelling + and Numerical Optimisation, 2013, 4, 150-194. + """ + + def __init__(self, dimensions=2): + Benchmark.__init__(self, dimensions) + + self._bounds = list(zip([-10.0] * self.N, [10.0] * self.N)) + self.custom_bounds = ([-2.0, 2.0], [-2.0, 2.0]) + + self.global_optimum = [[-1.0465, 0.0]] + self.fglob = -0.35238603 + + def fun(self, x, *args): + self.nfev += 1 + + return 0.25 * x[0] ** 4 - 0.5 * x[0] ** 2 + 0.1 * x[0] + 0.5 * x[1] ** 2 diff --git a/go_benchmark_functions/go_funcs_univariate.py b/go_benchmark_functions/go_funcs_univariate.py new file mode 100644 index 0000000..b5f80f7 --- /dev/null +++ b/go_benchmark_functions/go_funcs_univariate.py @@ -0,0 +1,729 @@ +# -*- coding: utf-8 -*- +from numpy import cos, exp, log, pi, sin, sqrt + +from .go_benchmark import Benchmark, safe_import + +with safe_import(): + try: + from scipy.special import factorial # new + except ImportError: + from scipy.misc import factorial # old + + +#----------------------------------------------------------------------- +# UNIVARIATE SINGLE-OBJECTIVE PROBLEMS +#----------------------------------------------------------------------- +class Problem02(Benchmark): + + """ + Univariate Problem02 objective function. + + This class defines the Univariate Problem02 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem02}}(x) = \\sin(x) + \\sin \\left(\\frac{10}{3}x \\right) + + Bound constraints: :math:`x \\in [2.7, 7.5]` + + .. figure:: figures/Problem02.png + :alt: Univariate Problem02 function + :align: center + + **Univariate Problem02 function** + + *Global optimum*: :math:`f(x)=-1.899599` for :math:`x = 5.145735` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(2.7, 7.5)] + + self.global_optimum = 5.145735 + self.fglob = -1.899599 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return sin(x) + sin(10.0 / 3.0 * x) + + +class Problem03(Benchmark): + + """ + Univariate Problem03 objective function. + + This class defines the Univariate Problem03 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem03}}(x) = - \\sum_{k=1}^6 k \\sin[(k+1)x+k] + + Bound constraints: :math:`x \\in [-10, 10]` + + .. figure:: figures/Problem03.png + :alt: Univariate Problem03 function + :align: center + + **Univariate Problem03 function** + + *Global optimum*: :math:`f(x)=-12.03124` for :math:`x = -6.7745761` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-10, 10)] + + self.global_optimum = -6.7745761 + self.fglob = -12.03124 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + y = 0.0 + for k in range(1, 6): + y += k * sin((k + 1) * x + k) + + return -y + + +class Problem04(Benchmark): + + """ + Univariate Problem04 objective function. + + This class defines the Univariate Problem04 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem04}}(x) = - \\left(16x^2 - 24x + 5 \\right) e^{-x} + + Bound constraints: :math:`x \\in [1.9, 3.9]` + + .. figure:: figures/Problem04.png + :alt: Univariate Problem04 function + :align: center + + **Univariate Problem04 function** + + *Global optimum*: :math:`f(x)=-3.85045` for :math:`x = 2.868034` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(1.9, 3.9)] + + self.global_optimum = 2.868034 + self.fglob = -3.85045 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return -(16 * x ** 2 - 24 * x + 5) * exp(-x) + + +class Problem05(Benchmark): + + """ + Univariate Problem05 objective function. + + This class defines the Univariate Problem05 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem05}}(x) = - \\left(1.4 - 3x \\right) \\sin(18x) + + Bound constraints: :math:`x \\in [0, 1.2]` + + .. figure:: figures/Problem05.png + :alt: Univariate Problem05 function + :align: center + + **Univariate Problem05 function** + + *Global optimum*: :math:`f(x)=-1.48907` for :math:`x = 0.96609` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(0.0, 1.2)] + + self.global_optimum = 0.96609 + self.fglob = -1.48907 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return -(1.4 - 3 * x) * sin(18.0 * x) + + +class Problem06(Benchmark): + + """ + Univariate Problem06 objective function. + + This class defines the Univariate Problem06 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem06}}(x) = - \\left[x + \\sin(x) \\right] e^{-x^2} + + Bound constraints: :math:`x \\in [-10, 10]` + + .. figure:: figures/Problem06.png + :alt: Univariate Problem06 function + :align: center + + **Univariate Problem06 function** + + *Global optimum*: :math:`f(x)=-0.824239` for :math:`x = 0.67956` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-10.0, 10.0)] + + self.global_optimum = 0.67956 + self.fglob = -0.824239 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return -(x + sin(x)) * exp(-x ** 2.0) + + +class Problem07(Benchmark): + + """ + Univariate Problem07 objective function. + + This class defines the Univariate Problem07 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem07}}(x) = \\sin(x) + \\sin \\left(\\frac{10}{3}x \\right) + \\log(x) - 0.84x + 3 + + Bound constraints: :math:`x \\in [2.7, 7.5]` + + .. figure:: figures/Problem07.png + :alt: Univariate Problem07 function + :align: center + + **Univariate Problem07 function** + + *Global optimum*: :math:`f(x)=-1.6013` for :math:`x = 5.19978` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(2.7, 7.5)] + + self.global_optimum = 5.19978 + self.fglob = -1.6013 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return sin(x) + sin(10.0 / 3.0 * x) + log(x) - 0.84 * x + 3 + + +class Problem08(Benchmark): + + """ + Univariate Problem08 objective function. + + This class defines the Univariate Problem08 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem08}}(x) = - \\sum_{k=1}^6 k \\cos[(k+1)x+k] + + Bound constraints: :math:`x \\in [-10, 10]` + + .. figure:: figures/Problem08.png + :alt: Univariate Problem08 function + :align: center + + **Univariate Problem08 function** + + *Global optimum*: :math:`f(x)=-14.508` for :math:`x = -7.083506` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-10, 10)] + + self.global_optimum = -7.083506 + self.fglob = -14.508 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + + y = 0.0 + for k in range(1, 6): + y += k * cos((k + 1) * x + k) + + return -y + + +class Problem09(Benchmark): + + """ + Univariate Problem09 objective function. + + This class defines the Univariate Problem09 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem09}}(x) = \\sin(x) + \\sin \\left(\\frac{2}{3} x \\right) + + Bound constraints: :math:`x \\in [3.1, 20.4]` + + .. figure:: figures/Problem09.png + :alt: Univariate Problem09 function + :align: center + + **Univariate Problem09 function** + + *Global optimum*: :math:`f(x)=-1.90596` for :math:`x = 17.039` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(3.1, 20.4)] + + self.global_optimum = 17.039 + self.fglob = -1.90596 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return sin(x) + sin(2.0 / 3.0 * x) + + +class Problem10(Benchmark): + + """ + Univariate Problem10 objective function. + + This class defines the Univariate Problem10 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem10}}(x) = -x\\sin(x) + + Bound constraints: :math:`x \\in [0, 10]` + + .. figure:: figures/Problem10.png + :alt: Univariate Problem10 function + :align: center + + **Univariate Problem10 function** + + *Global optimum*: :math:`f(x)=-7.916727` for :math:`x = 7.9787` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(0, 10)] + + self.global_optimum = 7.9787 + self.fglob = -7.916727 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return -x * sin(x) + + +class Problem11(Benchmark): + + """ + Univariate Problem11 objective function. + + This class defines the Univariate Problem11 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem11}}(x) = 2\\cos(x) + \\cos(2x) + + Bound constraints: :math:`x \\in [-\\pi/2, 2\\pi]` + + .. figure:: figures/Problem11.png + :alt: Univariate Problem11 function + :align: center + + **Univariate Problem11 function** + + *Global optimum*: :math:`f(x)=-1.5` for :math:`x = 2.09439` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-pi / 2, 2 * pi)] + + self.global_optimum = 2.09439 + self.fglob = -1.5 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return 2 * cos(x) + cos(2 * x) + + +class Problem12(Benchmark): + + """ + Univariate Problem12 objective function. + + This class defines the Univariate Problem12 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem12}}(x) = \\sin^3(x) + \\cos^3(x) + + Bound constraints: :math:`x \\in [0, 2\\pi]` + + .. figure:: figures/Problem12.png + :alt: Univariate Problem12 function + :align: center + + **Univariate Problem12 function** + + *Global optimum*: :math:`f(x)=-1` for :math:`x = \\pi` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(0, 2 * pi)] + + self.global_optimum = pi + self.fglob = -1 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return (sin(x)) ** 3.0 + (cos(x)) ** 3.0 + + +class Problem13(Benchmark): + + """ + Univariate Problem13 objective function. + + This class defines the Univariate Problem13 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem13}}(x) = -x^{2/3} - (1 - x^2)^{1/3} + + Bound constraints: :math:`x \\in [0.001, 0.99]` + + .. figure:: figures/Problem13.png + :alt: Univariate Problem13 function + :align: center + + **Univariate Problem13 function** + + *Global optimum*: :math:`f(x)=-1.5874` for :math:`x = 1/\\sqrt(2)` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(0.001, 0.99)] + + self.global_optimum = 1.0 / sqrt(2) + self.fglob = -1.5874 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return -x ** (2.0 / 3.0) - (1.0 - x ** 2) ** (1.0 / 3.0) + + +class Problem14(Benchmark): + + """ + Univariate Problem14 objective function. + + This class defines the Univariate Problem14 global optimization problem. This + is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem14}}(x) = -e^{-x} \\sin(2\\pi x) + + Bound constraints: :math:`x \\in [0, 4]` + + .. figure:: figures/Problem14.png + :alt: Univariate Problem14 function + :align: center + + **Univariate Problem14 function** + + *Global optimum*: :math:`f(x)=-0.788685` for :math:`x = 0.224885` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(0.0, 4.0)] + + self.global_optimum = 0.224885 + self.fglob = -0.788685 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return -exp(-x) * sin(2.0 * pi * x) + + +class Problem15(Benchmark): + + """ + Univariate Problem15 objective function. + + This class defines the Univariate Problem15 global optimization problem. + This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem15}}(x) = \\frac{x^{2} - 5 x + 6}{x^{2} + 1} + + Bound constraints: :math:`x \\in [-5, 5]` + + .. figure:: figures/Problem15.png + :alt: Univariate Problem15 function + :align: center + + **Univariate Problem15 function** + + *Global optimum*: :math:`f(x)=-0.03553` for :math:`x = 2.41422` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-5.0, 5.0)] + + self.global_optimum = 2.41422 + self.fglob = -0.03553 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return -(-x ** 2.0 + 5 * x - 6) / (x ** 2 + 1) + + +class Problem18(Benchmark): + + """ + Univariate Problem18 objective function. + + This class defines the Univariate Problem18 global optimization problem. + This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem18}}(x) = \\begin{cases}(x-2)^2 & \\textrm{if} \\hspace{5pt} x \\leq 3 \\\\ + 2\\log(x-2)+1&\\textrm{otherwise}\\end{cases} + + Bound constraints: :math:`x \\in [0, 6]` + + .. figure:: figures/Problem18.png + :alt: Univariate Problem18 function + :align: center + + **Univariate Problem18 function** + + *Global optimum*: :math:`f(x)=0` for :math:`x = 2` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(0.0, 6.0)] + + self.global_optimum = 2 + self.fglob = 0 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + + if x <= 3: + return (x - 2.0) ** 2.0 + + return 2 * log(x - 2.0) + 1 + + +class Problem20(Benchmark): + + """ + Univariate Problem20 objective function. + + This class defines the Univariate Problem20 global optimization problem. + This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem20}}(x) = -[x-\\sin(x)]e^{-x^2} + + Bound constraints: :math:`x \\in [-10, 10]` + + .. figure:: figures/Problem20.png + :alt: Univariate Problem20 function + :align: center + + **Univariate Problem20 function** + + *Global optimum*: :math:`f(x)=-0.0634905` for :math:`x = 1.195137` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(-10, 10)] + + self.global_optimum = 1.195137 + self.fglob = -0.0634905 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return -(x - sin(x)) * exp(-x ** 2.0) + + +class Problem21(Benchmark): + + """ + Univariate Problem21 objective function. + + This class defines the Univariate Problem21 global optimization problem. + This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem21}}(x) = x \\sin(x) + x \\cos(2x) + + Bound constraints: :math:`x \\in [0, 10]` + + .. figure:: figures/Problem21.png + :alt: Univariate Problem21 function + :align: center + + **Univariate Problem21 function** + + *Global optimum*: :math:`f(x)=-9.50835` for :math:`x = 4.79507` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(0, 10)] + + self.global_optimum = 4.79507 + self.fglob = -9.50835 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return x * sin(x) + x * cos(2.0 * x) + + +class Problem22(Benchmark): + + """ + Univariate Problem22 objective function. + + This class defines the Univariate Problem22 global optimization problem. + This is a multimodal minimization problem defined as follows: + + .. math:: + + f_{\\text{Problem22}}(x) = e^{-3x} - \\sin^3(x) + + Bound constraints: :math:`x \\in [0, 20]` + + .. figure:: figures/Problem22.png + :alt: Univariate Problem22 function + :align: center + + **Univariate Problem22 function** + + *Global optimum*: :math:`f(x)=e^{-27\\pi/2} - 1` for :math:`x = 9\\pi/2` + + """ + + def __init__(self, dimensions=1): + Benchmark.__init__(self, dimensions) + + self._bounds = [(0, 20)] + + self.global_optimum = 9.0 * pi / 2.0 + self.fglob = exp(-27.0 * pi / 2.0) - 1.0 + + def fun(self, x, *args): + self.nfev += 1 + + x = x[0] + return exp(-3.0 * x) - (sin(x)) ** 3.0