Source code for niapy.problems.hgbat

# encoding=utf8

"""Implementations of HGBat functions."""

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

__all__ = ['HGBat']

[docs]class HGBat(Problem):
r"""Implementations of HGBat functions.

Date: 2018

Author: Klemen Berkovič

Function:
**HGBat Function**
:math:f(\textbf{x}) = \left| \left( \sum_{i=1}^D x_i^2 \right)^2 - \left( \sum_{i=1}^D x_i \right)^2 \right|^{\frac{1}{2}} + \frac{0.5 \sum_{i=1}^D x_i^2 + \sum_{i=1}^D x_i}{D} + 0.5

**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)

LaTeX formats:
Inline:
f(\textbf{x}) = \left| \left( \sum_{i=1}^D x_i^2 \right)^2 - \left( \sum_{i=1}^D x_i \right)^2 \right|^{\frac{1}{2}} + \frac{0.5 \sum_{i=1}^D x_i^2 + \sum_{i=1}^D x_i}{D} + 0.5

Equation:
$$f(\textbf{x}) = \left| \left( \sum_{i=1}^D x_i^2 \right)^2 - \left( \sum_{i=1}^D x_i \right)^2 \right|^{\frac{1}{2}} + \frac{0.5 \sum_{i=1}^D x_i^2 + \sum_{i=1}^D x_i}{D} + 0.5$$

Domain:
$-100 \leq x_i \leq 100$

Reference:

"""

[docs]    def __init__(self, dimension=4, lower=-100.0, upper=100.0, *args, **kwargs):
r"""Initialize HGBat problem..

Args:
dimension (Optional[int]): Dimension of the problem.
lower (Optional[Union[float, Iterable[float]]]): Lower bounds of the problem.
upper (Optional[Union[float, Iterable[float]]]): Upper bounds of the problem.

:func:niapy.problems.Problem.__init__

"""
super().__init__(dimension, lower, upper, *args, **kwargs)

[docs]    @staticmethod
def latex_code():
r"""Return the latex code of the problem.

Returns:
str: Latex code.

"""
return r'''$f(\textbf{x}) = \left| \left( \sum_{i=1}^D x_i^2 \right)^2 - \left( \sum_{i=1}^D x_i \right)^2 \right|^{\frac{1}{2}} + \frac{0.5 \sum_{i=1}^D x_i^2 + \sum_{i=1}^D x_i}{D} + 0.5$'''

def _evaluate(self, x):
val1 = np.sum(x ** 2)
val2 = np.sum(x)
return np.sqrt(np.abs(val1 * val1 - val2 ** 2)) + (0.5 * val1 + val2) / self.dimension + 0.5