Skip to content

Commit

Permalink
Merge pull request #418 from zStupan/fix-problem-definitions
Browse files Browse the repository at this point in the history
Fix problem definitions
  • Loading branch information
firefly-cpp authored Nov 6, 2023
2 parents 3ac2ae7 + a9e68b4 commit 174747e
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 311 deletions.
2 changes: 1 addition & 1 deletion niapy/problems/bent_cigar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BentCigar(Problem):
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
**Global minimum:**
:math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
:math:`f(x^*) = 0`, at :math:`x_i^* = 0`
LaTeX formats:
Inline:
Expand Down
2 changes: 1 addition & 1 deletion niapy/problems/discus.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Discus(Problem):
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
**Global minimum:**
:math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
:math:`f(x^*) = 0`, at :math:`x_i^* = 0`
LaTeX formats:
Inline:
Expand Down
4 changes: 2 additions & 2 deletions niapy/problems/elliptic.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Elliptic(Problem):
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
**Global minimum:**
:math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
:math:`f(x^*) = 0`, at :math:`x_i^* = 0`
LaTeX formats:
Inline:
Expand Down Expand Up @@ -70,4 +70,4 @@ def latex_code():

def _evaluate(self, x):
indices = np.arange(self.dimension)
return np.sum(1000000.0 ** (indices / (self.dimension - 1)) * x)
return np.sum(1000000.0 ** (indices / (self.dimension - 1)) * x ** 2)
2 changes: 1 addition & 1 deletion niapy/problems/griewank.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ExpandedGriewankPlusRosenbrock(Problem):
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
**Global minimum:**
:math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
:math:`f(x^*) = 0`, at :math:`x_i^* = 0`
LaTeX formats:
Inline:
Expand Down
2 changes: 1 addition & 1 deletion niapy/problems/hgbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class HGBat(Problem):
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
**Global minimum:**
:math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
:math:`f(x^*) = 0`, at :math:`x_i^* = -1`
LaTeX formats:
Inline:
Expand Down
25 changes: 11 additions & 14 deletions niapy/problems/katsuura.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""Implementations of Katsuura functions."""

from math import fabs
import numpy as np
from niapy.problems.problem import Problem

__all__ = ['Katsuura']
Expand All @@ -20,25 +20,25 @@ class Katsuura(Problem):
Function:
**Katsuura Function**
:math:`f(\textbf{x}) = \frac{10}{D^2} \prod_{i=1}^D \left( 1 + i \sum_{j=1}^{32} \frac{\lvert 2^j x_i - round\left(2^j x_i \right) \rvert}{2^j} \right)^\frac{10}{D^{1.2}} - \frac{10}{D^2}`
:math:`f(\textbf{x}) = \prod_{i=1}^D \left( 1 + i \sum_{j=1}^{32} \frac{\lvert 2^j x_i - round\left(2^j x_i \right) \rvert}{2^j} \right)`
**Input domain:**
The function can be defined on any input domain but it is usually
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
**Global minimum:** :math:`f(x^*) = 1`, at :math:`x_i^* = 0`
LaTeX formats:
Inline:
$f(\textbf{x}) = \frac{10}{D^2} \prod_{i=1}^D \left( 1 + i \sum_{j=1}^{32} \frac{\lvert 2^j x_i - round\left(2^j x_i \right) \rvert}{2^j} \right)^\frac{10}{D^{1.2}} - \frac{10}{D^2}$
$f(\textbf{x}) = \prod_{i=1}^D \left( 1 + i \sum_{j=1}^{32} \frac{\lvert 2^j x_i - round\left(2^j x_i \right) \rvert}{2^j} \right)$
Equation:
\begin{equation} f(\textbf{x}) = \frac{10}{D^2} \prod_{i=1}^D \left( 1 + i \sum_{j=1}^{32} \frac{\lvert 2^j x_i - round\left(2^j x_i \right) \rvert}{2^j} \right)^\frac{10}{D^{1.2}} - \frac{10}{D^2} \end{equation}
\begin{equation} f(\textbf{x}) = \prod_{i=1}^D \left( 1 + i \sum_{j=1}^{32} \frac{\lvert 2^j x_i - round\left(2^j x_i \right) \rvert}{2^j} \right)\end{equation}
Domain:
$-100 \leq x_i \leq 100$
Reference:
http://www5.zzu.edu.cn/__local/A/69/BC/D3B5DFE94CD2574B38AD7CD1D12_C802DAFE_BC0C0.pdf
Adorio, E. P., & Diliman, U. P. MVF - Multivariate Test Functions Library in C for Unconstrained Global Optimization (2005).
"""

Expand All @@ -64,13 +64,10 @@ def latex_code():
str: Latex code.
"""
return r'''$f(\textbf{x}) = \frac{10}{D^2} \prod_{i=1}^D \left( 1 + i \sum_{j=1}^{32} \frac{| 2^j x_i - round\left(2^j x_i \right) |}{2^j} \right)^\frac{10}{D^{1.2}} - \frac{10}{D^2}$'''
return r'''$f(\textbf{x}) = \prod_{i=1}^D \left( 1 + i \sum_{j=1}^{32} \frac{| 2^j x_i - round\left(2^j x_i \right) |}{2^j} \right)$'''

def _evaluate(self, x):
val = 1.0
for i in range(self.dimension):
val_t = 1.0
for j in range(1, 33):
val_t += fabs(2 ** j * x[i] - round(2 ** j * x[i])) / 2 ** j
val *= (1 + (i + 1) * val_t) ** (10 / self.dimension ** 1.2) - (10 / self.dimension ** 2)
return 10 / self.dimension ** 2 * val
k = np.atleast_2d(np.arange(1, 33)).T
i = np.arange(1, self.dimension + 1)
inner = np.round(2 ** k * x) * (2.0 ** (-k))
return np.prod(np.sum(inner, axis=0) * i + 1)
8 changes: 4 additions & 4 deletions niapy/problems/powell.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def latex_code():
return r'''$f(\textbf{x}) = \sum_{i = 1}^{D / 4} \left( (x_{4 i - 3} + 10 x_{4 i - 2})^2 + 5 (x_{4 i - 1} - x_{4 i})^2 + (x_{4 i - 2} - 2 x_{4 i - 1})^4 + 10 (x_{4 i - 3} - x_{4 i})^4 \right)$'''

def _evaluate(self, x):
x1 = x[range(1, self.dimension - 3, 4)]
x2 = x[range(2, self.dimension - 2, 4)]
x3 = x[range(3, self.dimension - 1, 4)]
x4 = x[range(4, self.dimension, 4)]
x1 = x[0::4]
x2 = x[1::4]
x3 = x[2::4]
x4 = x[3::4]

term1 = (x1 + 10 * x2) ** 2.0
term2 = 5 * (x3 - x4) ** 2.0
Expand Down
2 changes: 1 addition & 1 deletion niapy/problems/quintic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Quintic(Problem):
The function can be defined on any input domain but it is usually
evaluated on the hypercube :math:`x_i ∈ [-10, 10]`, for all :math:`i = 1, 2,..., D`.
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = f(-1\; \text{or}\; 2)`
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x_i^* = -1`
LaTeX formats:
Inline:
Expand Down
4 changes: 2 additions & 2 deletions niapy/problems/salomon.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ def latex_code():
\right)+ 0.1 \sqrt{\sum_{i=1}^D x_i^2}$'''

def _evaluate(self, x):
val = np.sum(x ** 2.0)
return 1.0 - np.cos(2.0 * np.pi * np.sqrt(val)) + 0.1 * val
val = np.sqrt(np.sum(x ** 2.0))
return 1.0 - np.cos(2.0 * np.pi * val) + 0.1 * val
17 changes: 11 additions & 6 deletions niapy/problems/schaffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class SchafferN2(Problem):
**Input domain:**
The function can be defined on any input domain but it is usually
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2`.
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = (0, 0)`
LaTeX formats:
Inline:
Expand Down Expand Up @@ -85,9 +85,9 @@ class SchafferN4(Problem):
**Input domain:**
The function can be defined on any input domain but it is usually
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2`.
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = (0, 0)`
LaTeX formats:
Inline:
Expand Down Expand Up @@ -143,13 +143,18 @@ class ExpandedSchaffer(Problem):
Function:
**Expanded Schaffer Function**
:math:`f(\textbf{x}) = g(x_D, x_1) + \sum_{i=2}^D g(x_{i - 1}, x_i) \\ g(x, y) = 0.5 + \frac{\sin \left(\sqrt{x^2 + y^2} \right)^2 - 0.5}{\left( 1 + 0.001 (x^2 + y^2) \right)}^2`
.. math::
f(\textbf{x}) = g(x_D, x_1) + \sum_{i=2}^D g(x_{i - 1}, x_i)
g(x, y) = 0.5 + \frac{\sin \left(\sqrt{x^2 + y^2} \right)^2 - 0.5}{\left( 1 + 0.001 (x^2 + y^2) \right)}^2`
**Input domain:**
The function can be defined on any input domain but it is usually
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x_i^* = 0`
LaTeX formats:
Inline:
Expand Down
2 changes: 1 addition & 1 deletion niapy/problems/schwefel.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def latex_code():
return r'''$f(\textbf{x}) = 418.9829d - \sum_{i=1}^{D} x_i \sin(\sqrt{\lvert x_i \rvert})$'''

def _evaluate(self, x):
return 418.9829 * self.dimension - np.sum(x * np.sin(np.sqrt(np.abs(x))))
return 418.982887272433799807913601398 * self.dimension - np.sum(x * np.sin(np.sqrt(np.abs(x))))


class Schwefel221(Problem):
Expand Down
2 changes: 1 addition & 1 deletion niapy/problems/styblinski_tang.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StyblinskiTang(Problem):
The function can be defined on any input domain but it is usually
evaluated on the hypercube :math:`x_i ∈ [-5, 5]`, for all :math:`i = 1, 2,..., D`.
**Global minimum:** :math:`f(x^*) = -78.332`, at :math:`x^* = (-2.903534,...,-2.903534)`
**Global minimum:** :math:`f(x^*) = -39.16616570377142d`, at :math:`x_i^* = -2.903534018185960`
LaTeX formats:
Inline:
Expand Down
19 changes: 7 additions & 12 deletions niapy/problems/weierstrass.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Weierstrass(Problem):
evaluated on the hypercube :math:`x_i ∈ [-100, 100]`, for all :math:`i = 1, 2,..., D`.
Default value of a = 0.5, b = 3 and k_max = 20.
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x^* = (420.968746,...,420.968746)`
**Global minimum:** :math:`f(x^*) = 0`, at :math:`x_i^* = 0`
LaTeX formats:
Inline:
Expand All @@ -44,7 +44,7 @@ class Weierstrass(Problem):
"""

def __init__(self, dimension=4, lower=-100.0, upper=100.0, a=0.5, b=3, k_max=20, *args, **kwargs):
r"""Initialize Bent Cigar problem..
r"""Initialize Weierstrass problem..
Args:
dimension (Optional[int]): Dimension of the problem.
Expand Down Expand Up @@ -74,13 +74,8 @@ def latex_code():
return r'''$f(\textbf{x}) = \sum_{i=1}^D \left( \sum_{k=0}^{k_{max}} a^k \cos\left( 2 \pi b^k ( x_i + 0.5) \right) \right) - D \sum_{k=0}^{k_{max}} a^k \cos \left( 2 \pi b^k \cdot 0.5 \right)$'''

def _evaluate(self, x):
val1 = 0.0
for i in range(self.dimension):
val = 0.0
for k in range(self.k_max):
val += self.a ** k * np.cos(2.0 * np.pi * self.b ** k * (x[i] + 0.5))
val1 += val
val2 = 0.0
for k in range(self.k_max):
val2 += self.a ** k * np.cos(2 * np.pi * self.b ** k * 0.5)
return val1 - self.dimension * val2
k = np.atleast_2d(np.arange(self.k_max + 1)).T
t1 = self.a ** k * np.cos(2 * np.pi * self.b ** k * (x + 0.5))
t2 = self.dimension * np.sum(self.a ** k.T * np.cos(np.pi * self.b ** k.T))

return np.sum(np.sum(t1, axis=0)) - t2
Loading

0 comments on commit 174747e

Please sign in to comment.