Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quintic function added #47

Merged
merged 3 commits into from Feb 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion NiaPy/benchmarks/__init__.py
Expand Up @@ -17,6 +17,7 @@
from NiaPy.benchmarks.csendes import Csendes
from NiaPy.benchmarks.pinter import Pinter
from NiaPy.benchmarks.qing import Qing
from NiaPy.benchmarks.quintic import Quintic


__all__ = [
Expand All @@ -36,5 +37,6 @@
'ChungReynolds',
'Csendes',
'Pinter',
'Qing'
'Qing',
'Quintic'
]
59 changes: 59 additions & 0 deletions NiaPy/benchmarks/quintic.py
@@ -0,0 +1,59 @@
# encoding=utf8
# pylint: disable=anomalous-backslash-in-string
"""Implementation of Quintic function.

Date: 2018

Author: Lucija Brezočnik

License: MIT

Function: Quintic function

Input domain:
The function can be defined on any input domain but it is usually
evaluated on the hypercube x_i ∈ [-10, 10], for all i = 1, 2,..., D.

Global minimum:
f(x*) = 0, at x* = f(-1 or 2)

LaTeX formats:
Inline: $f(\mathbf{x}) = \sum_{i=1}^D \left| x_i^5 - 3x_i^4 +
4x_i^3 + 2x_i^2 - 10x_i - 4\right|$
Equation: \begin{equation} f(\mathbf{x}) =
\sum_{i=1}^D \left| x_i^5 - 3x_i^4 + 4x_i^3 + 2x_i^2 -
10x_i - 4\right| \end{equation}
Domain: $-10 \leq x_i \leq 10$

Reference paper:
Jamil, M., and Yang, X. S. (2013).
A literature survey of benchmark functions for global optimisation problems.
International Journal of Mathematical Modelling and Numerical Optimisation,
4(2), 150-194.
"""

import math

__all__ = ['Quintic']


class Quintic(object):

def __init__(self, Lower=-10, Upper=10):
self.Lower = Lower
self.Upper = Upper

@classmethod
def function(cls):
def evaluate(D, sol):

val = 0.0

for i in range(D):
val += abs(math.pow(sol[i], 5) - 3.0 * math.pow(sol[i], 4) + \
4.0 * math.pow(sol[i], 3) + 2.0 * math.pow(sol[i], 2) - \
10.0 * sol[i] - 4)

return val

return evaluate
9 changes: 8 additions & 1 deletion NiaPy/benchmarks/utility.py
Expand Up @@ -2,7 +2,7 @@

from . import Rastrigin, Rosenbrock, Griewank, \
Sphere, Ackley, Schwefel, Schwefel221, \
Schwefel222, Whitley, Alpine1, Alpine2, HappyCat, Ridge, ChungReynolds, Csendes, Pinter, Qing
Schwefel222, Whitley, Alpine1, Alpine2, HappyCat, Ridge, ChungReynolds, Csendes, Pinter, Qing, Quintic


__all__ = ['Utility']
Expand Down Expand Up @@ -138,6 +138,13 @@ def get_benchmark(self, benchmark, Lower=None, Upper=None):
return Qing(Lower, Upper)
else:
self.__raiseLowerAndUpperNotDefined()
elif benchmark == 'quintic':
if Lower is None and Upper is None:
return Quintic()
elif Lower is not None and Upper is not None:
return Quintic(Lower, Upper)
else:
self.__raiseLowerAndUpperNotDefined()
else:
raise TypeError('Passed benchmark is not defined!')

Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -44,6 +44,7 @@ The following benchmark functions are included in NiaPy:
- Happy cat
- Pintér
- Qing
- Quintic
- Rastrigin
- Ridge
- Rosenbrock
Expand Down
2 changes: 1 addition & 1 deletion examples/run.py
Expand Up @@ -28,6 +28,6 @@ def evaluate(D, sol):
algorithms = ['BatAlgorithm', 'DifferentialEvolutionAlgorithm',
'ArtificialBeeColonyAlgorithm']
benchmarks = ['sphere', 'ackley', 'rosenbrock', 'griewank', 'rastrigin',
'rosenbrock', 'schwefel', 'schwefel221', 'schwefel222', 'whitley', 'alpine1', 'alpine2', 'happyCat', 'ridge', 'chungReynolds', 'csendes', 'pinter', 'qing', MyBenchmark()]
'rosenbrock', 'schwefel', 'schwefel221', 'schwefel222', 'whitley', 'alpine1', 'alpine2', 'happyCat', 'ridge', 'chungReynolds', 'csendes', 'pinter', 'qing', 'quintic', MyBenchmark()]

NiaPy.Runner(10, 40, 10000, 10, algorithms, benchmarks).run(export='latex', verbose=True)