Skip to content

Commit

Permalink
Adding one more 1-dimensional function.
Browse files Browse the repository at this point in the history
  • Loading branch information
gugarosa committed May 7, 2020
1 parent f97d027 commit d3e0683
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/api/opytimark.markers.one_dimensional.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
opytimark.markers.one_dimensional
==================================

.. autoapiclass:: opytimark.markers.one_dimensional.Forrester
:members:
:show-inheritance:

.. autoapiclass:: opytimark.markers.one_dimensional.GramacyLee
:members:
:show-inheritance:
54 changes: 52 additions & 2 deletions opytimark/markers/one_dimensional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,56 @@
from opytimark.core import Benchmark


class Forrester(Benchmark):
"""Forrester class implements the Forrester's benchmarking function.
.. math:: f(x) = (6x - 2)^2 sin(12x - 4)
Domain:
The function is commonly evaluated using :math:`x \in [0, 1]`.
Global Minima:
:math:`f(x^*) \\approx -5.9932767166446155 \mid x^* \\approx (0.75)`.
"""

def __init__(self, name='Forrester', dims=1, continuous=True, convex=False,
differentiable=True, multimodal=True, separable=True):
"""Initialization method.
Args:
name (str): Name of the function.
dims (int): Number of allowed dimensions.
continuous (bool): Whether the function is continuous.
convex (bool): Whether the function is convex.
differentiable (bool): Whether the function is differentiable.
multimodal (bool): Whether the function is multimodal.
separable (bool): Whether the function is separable.
"""

# Override its parent class
super(Forrester, self).__init__(name, dims, continuous,
convex, differentiable, multimodal, separable)

@d.check_dimension
def __call__(self, x):
"""This method returns the function's output when the class is called.
Args:
x (np.array): An input array for calculating the function's output.
Returns:
The benchmarking function output `f(x)`.
"""

# Calculating the Forrester's function
f = (6 * x[0] - 2) ** 2 * np.sin(12 * x[0] - 4)

return f


class GramacyLee(Benchmark):
"""GramacyLee class implements the Gramacy & Lee's benchmarking function.
Expand All @@ -18,7 +68,7 @@ class GramacyLee(Benchmark):
"""

def __init__(self, name='GramacyLee', dims=-1, continuous=True, convex=False,
def __init__(self, name='GramacyLee', dims=1, continuous=True, convex=False,
differentiable=True, multimodal=False, separable=True):
"""Initialization method.
Expand Down Expand Up @@ -52,4 +102,4 @@ def __call__(self, x):
# Calculating the Gramacy & Lee's function
f = np.sin(10 * np.pi * x[0]) / (2 * x[0] + c.EPSILON) + ((x[0] - 1) ** 4)

return np.sum(f)
return f
10 changes: 10 additions & 0 deletions tests/opytimark/markers/test_one_dimensional.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from opytimark.markers import one_dimensional


def test_forrester():
f = one_dimensional.Forrester()

x = np.array([0.75])

y = f(x)

assert y == -5.9932767166446155


def test_gramacy_lee():
f = one_dimensional.GramacyLee()

Expand Down

0 comments on commit d3e0683

Please sign in to comment.