class documentation

class FitnessFunctions(object):

View In Hierarchy

collection of objective functions.

Static Method binval return sum_i(0 if (optimum[0] <= x[i] <= optimum[1]) else 2**i)
Static Method leadingones return len(x) - nb of leading-ones-in-x to be minimized,
Static Method onemax return sum_i(0 if (optimum[0] <= x[i] <= optimum[1]) else 1)
Method __init__ Undocumented
Method absplussin multimodal function with the global optimum at x_i = -1.152740846
Method branin Undocumented
Method bukin Bukin function from Wikipedia, generalized simplistically from 2-D.
Method cigar Cigar test objective function
Method cigtab Cigtab test objective function
Method cigtab2 cigtab with 1 + 5% long and short axes.
Method cornerelli Undocumented
Method cornerellirot Undocumented
Method cornersphere Sphere (squared norm) test objective function constraint to the corner
Method diagonal_cigar Undocumented
Method diffpow Diffpow test objective function
Method elli Ellipsoid test objective function
Method elliconstraint ellipsoid test objective function with "constraints"
Method ellihalfrot return ellirot(x[:N2]) + elli(x[N2:]) where N2 is roughly frac*len(x)
Method ellirot Undocumented
Method elliwithoneconstraint Undocumented
Method epslow Undocumented
Method epslowsphere TODO: define as wrapper
Method flat Undocumented
Method fun_as_arg fun_as_arg(x, fun, *more_args) calls fun(x, *more_args).
Method goldsteinprice Undocumented
Method grad_cigar Undocumented
Method grad_elli Undocumented
Method grad_numerical symmetric gradient
Method grad_rosen Undocumented
Method grad_sphere Undocumented
Method grad_tablet Undocumented
Method grad_to_one Undocumented
Method griewank Undocumented
Method halfelli Undocumented
Method happycat a difficult sharp ridge type function.
Method hyperelli Undocumented
Method levy a rather benign multimodal function.
Method lincon ridge like linear function with one linear constraint
Method linear Undocumented
Method lineard Undocumented
Method noise Undocumented
Method noiseC Undocumented
Method noisysphere noise=10 does not work with default popsize, cma.NoiseHandler(dimension, 1e7) helps
Method normalSkew Undocumented
Method optprob Undocumented
Method partsphere Sphere (squared norm) test objective function
Method pnorm Undocumented
Method powel_singular Undocumented
Method rand Random test objective function
Method rastrigin Rastrigin test objective function
Method ridge Undocumented
Method ridgecircle a difficult sharp ridge type function.
Method rosen Rosenbrock test objective function, x0=0
Method rosen0 Rosenbrock test objective function with optimum in all-zeros, x0=-1
Method rosen_chained Undocumented
Method rosen_nesterov needs exponential number of steps in a non-increasing f-sequence.
Method rosenelli Undocumented
Method rot returns fun(rotation(x), *args), ie. fun applied to a rotated argument
Method schaffer Schaffer function x0 in [-100..100]
Method schwefel2_22 Schwefel 2.22 function
Method schwefelelli Undocumented
Method schwefelmult multimodal Schwefel function with domain -500..500
Method sectorsphere asymmetric Sphere (squared norm) test objective function
Method somenan returns sometimes np.nan, otherwise fun(x)
Method sphere Sphere (squared norm) test objective function
Method sphere_pos Sphere (squared norm) test objective function
Method spherew Sphere (squared norm) with sum x_i = 1 test objective function
Method spherewithnconstraints Undocumented
Method spherewithoneconstraint Undocumented
Method styblinski_tang in [-5, 5] found also in Lazar and Jarre 2016, optimum in f(-2.903534...)=0
Method subspace_sphere No summary
Method tablet Tablet test objective function
Method trid Undocumented
Method twoaxes Cigtab test objective function
Method xinsheyang2 a multimodal function which is rather unsolvable in larger dimension.
Class Variable binary_foffset default f-offset for binary functions at the optimum.
Class Variable binary_optimum_interval default interval where the optimum is assumed on binary functions.
Class Variable evaluations Undocumented
Property BBOB Undocumented
@staticmethod
def binval(x, foffset=binary_foffset, optimum=binary_optimum_interval):

return sum_i(0 if (optimum[0] <= x[i] <= optimum[1]) else 2**i)

to be minimized.

Details: the result is computed as int, because in dimension > 54 a float representation can not account for the least sensitive bit anymore. Because we minimize, this is not necessarily a big problem.

@staticmethod
def leadingones(x, foffset=binary_foffset, optimum=binary_optimum_interval):

return len(x) - nb of leading-ones-in-x to be minimized,

where only values in [optimum[0], optimum[1]] are considered to be "equal to" 1.

@staticmethod
def onemax(x, foffset=binary_foffset, optimum=binary_optimum_interval):

return sum_i(0 if (optimum[0] <= x[i] <= optimum[1]) else 1)

to be minimized.

def __init__(self):

Undocumented

def absplussin(self, x):

multimodal function with the global optimum at x_i = -1.152740846

def branin(self, x):

Undocumented

def bukin(self, x):

Bukin function from Wikipedia, generalized simplistically from 2-D.

http://en.wikipedia.org/wiki/Test_functions_for_optimization

def cigar(self, x, rot=0, cond=1000000.0, noise=0):

Cigar test objective function

def cigtab(self, y):

Cigtab test objective function

def cigtab2(self, x, condition=100000000.0, n_axes=None):

cigtab with 1 + 5% long and short axes.

n_axes: int, if > 0, sets the number of long as well as short axes to n_axes, respectively.

def cornerelli(self, x):

Undocumented

def cornerellirot(self, x):

Undocumented

def cornersphere(self, x):

Sphere (squared norm) test objective function constraint to the corner

def diagonal_cigar(self, x, cond=1000000.0):

Undocumented

def diffpow(self, x, rot=0):

Diffpow test objective function

def elli(self, x, rot=0, xoffset=0, cond=1000000.0, actuator_noise=0.0, beta_noise=0, both=False):

Ellipsoid test objective function

def elliconstraint(self, x, cfac=100000000.0, tough=True, cond=1000000.0):

ellipsoid test objective function with "constraints"

def ellihalfrot(self, x, frac=0.5, cond1=1000000.0, cond2=1000000.0):

return ellirot(x[:N2]) + elli(x[N2:]) where N2 is roughly frac*len(x)

def ellirot(self, x, cond=1000000.0):

Undocumented

def elliwithoneconstraint(self, x, idx=[(-1)]):

Undocumented

def epslow(self, fun, eps=1e-07, Neff=(lambda x: int(len(x) ** 0.5))):

Undocumented

def epslowsphere(self, x, eps=1e-07, Neff=(lambda x: int(len(x) ** 0.5))):

TODO: define as wrapper

def flat(self, x):

Undocumented

def fun_as_arg(self, x, *args):

fun_as_arg(x, fun, *more_args) calls fun(x, *more_args).

Use case:

fmin(cma.fun_as_arg, args=(fun,), gradf=grad_numerical)

calls fun_as_args(x, args) and grad_numerical(x, fun, args=args)

def goldsteinprice(self, x):

Undocumented

def grad_cigar(self, x, *args):

Undocumented

def grad_elli(self, x, *args):

Undocumented

def grad_numerical(self, x, func, epsilon=None):

symmetric gradient

def grad_rosen(self, x, *args):

Undocumented

def grad_sphere(self, x, *args):

Undocumented

def grad_tablet(self, x, *args):

Undocumented

def grad_to_one(self, x, *args):

Undocumented

def griewank(self, x):

Undocumented

def halfelli(self, x):

Undocumented

def happycat(self, x, alpha=1.0/8):

a difficult sharp ridge type function.

Proposed by HG Beyer.

def hyperelli(self, x):

Undocumented

def levy(self, x):

a rather benign multimodal function.

xopt == ones, fopt == 0.0

def lincon(self, x, theta=0.01):

ridge like linear function with one linear constraint

def linear(self, x):

Undocumented

def lineard(self, x):

Undocumented

def noise(self, x, func=sphere, fac=10, expon=1):

Undocumented

def noiseC(self, x, func=sphere, fac=10, expon=0.8):

Undocumented

def noisysphere(self, x, noise=2.1e-09, cond=1.0, noise_offset=0.1):

noise=10 does not work with default popsize, cma.NoiseHandler(dimension, 1e7) helps

def normalSkew(self, f):

Undocumented

def optprob(self, x):

Undocumented

def partsphere(self, x):

Sphere (squared norm) test objective function

def pnorm(self, x, p=0.5):

Undocumented

def powel_singular(self, x):

Undocumented

def rand(self, x):

Random test objective function

def rastrigin(self, x):

Rastrigin test objective function

def ridge(self, x, expo=2):

Undocumented

def ridgecircle(self, x, expo=0.5):

a difficult sharp ridge type function.

A modified implementation of HG Beyers happycat.

def rosen(self, x, alpha=100.0):

Rosenbrock test objective function, x0=0

def rosen0(self, x, alpha=100.0):

Rosenbrock test objective function with optimum in all-zeros, x0=-1

def rosen_chained(self, x, alpha=100.0):

Undocumented

def rosen_nesterov(self, x, rho=100):

needs exponential number of steps in a non-increasing f-sequence.

x_0 = (-1,1,...,1) See Jarre (2011) "On Nesterov's Smooth Chebyshev-Rosenbrock Function"

def rosenelli(self, x):

Undocumented

def rot(self, x, fun, rot=1, args=()):

returns fun(rotation(x), *args), ie. fun applied to a rotated argument

def schaffer(self, x):

Schaffer function x0 in [-100..100]

def schwefel2_22(self, x):

Schwefel 2.22 function

def schwefelelli(self, x):

Undocumented

def schwefelmult(self, x, pen_fac=10000.0):

multimodal Schwefel function with domain -500..500

def sectorsphere(self, x):

asymmetric Sphere (squared norm) test objective function

def somenan(self, x, fun, p=0.1):

returns sometimes np.nan, otherwise fun(x)

def sphere(self, x):

Sphere (squared norm) test objective function

def sphere_pos(self, x):

Sphere (squared norm) test objective function

def spherew(self, x):

Sphere (squared norm) with sum x_i = 1 test objective function

def spherewithnconstraints(self, x):

Undocumented

def spherewithoneconstraint(self, x):

Undocumented

def styblinski_tang(self, x):

in [-5, 5] found also in Lazar and Jarre 2016, optimum in f(-2.903534...)=0

def subspace_sphere(self, x, visible_ratio=1/2):
def tablet(self, x, cond=1000000.0, rot=0):

Tablet test objective function

def trid(self, x):

Undocumented

def twoaxes(self, y, cond=1000000.0):

Cigtab test objective function

def xinsheyang2(self, x, termination_friendly=True):

a multimodal function which is rather unsolvable in larger dimension.

>>> import functools
>>> import numpy as np
>>> import cma
>>> f = functools.partial(cma.ff.xinsheyang2, termination_friendly=False)
>>> X = [(i * [0] + (4 - i) * [1.24]) for i in range(5)]
>>> for x in X: print(x)
[1.24, 1.24, 1.24, 1.24]
[0, 1.24, 1.24, 1.24]
[0, 0, 1.24, 1.24]
[0, 0, 0, 1.24]
[0, 0, 0, 0]
>>> ' '.join(['{0:.3}'.format(f(x)) for x in X])  # [np.round(f(x), 3) for x in X]
'0.091 0.186 0.336 0.456 0.0'

One needs to solve a trinary deceptive function where f-value (to be minimized) is monotonuously decreasing with increasing distance to the global optimum >= 1. That is, the global optimum is surrounded by 3^n - 1 local optima that have the better values the further they are away from the global optimum.

Conclusion: it is a rather suspicious sign if an algorithm finds the global optimum of this function in larger dimension.

See also http://benchmarkfcns.xyz/benchmarkfcns/xinsheyangn2fcn.html

binary_foffset =

default f-offset for binary functions at the optimum.

Changing this default is only effective before import.

binary_optimum_interval: tuple[float, ...] =

default interval where the optimum is assumed on binary functions.

The interval is chosen such that the value from round(.) or floor(. + 1/2) or int(. + 1/2) is in the interval middle. This prevents some unexpected outcomes with algorithms that search on the continuous values. The most logical domain boundary values are now [-0.5, 1.5] or [0, 1].

Details: Changing this default is only effective before import.

evaluations: int =

Undocumented

@property
BBOB =

Undocumented