Source code for niapy.problems.elliptic

# encoding=utf8

"""Implementations of High Conditioned Elliptic functions."""

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

__all__ = ['Elliptic']

[docs]class Elliptic(Problem):
r"""Implementations of High Conditioned Elliptic functions.

Date: 2018

Author: Klemen Berkovič

License: MIT

Function:
**High Conditioned Elliptic Function**

:math:f(\textbf{x}) = \sum_{i=1}^D \left( 10^6 \right)^{ \frac{i - 1}{D - 1} } x_i^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)

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

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

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

Reference:
http://www5.zzu.edu.cn/__local/A/69/BC/D3B5DFE94CD2574B38AD7CD1D12_C802DAFE_BC0C0.pdf

"""

[docs]    def __init__(self, dimension=4, lower=-100.0, upper=100.0, *args, **kwargs):
r"""Initialize High Conditioned Elliptic 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.

See Also:
: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}) = \sum_{i=1}^D \left( 10^6 \right)^{ \frac{i - 1}{D - 1} } x_i^2$'''

def _evaluate(self, x):
indices = np.arange(self.dimension)
return np.sum(1000000.0 ** (indices / (self.dimension - 1)) * x)