class FitnessFunctions(object):
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 | bohachevsky |
a moderately difficult multimodal function with global structure, |
| 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 |
Undocumented |
| Method | diffpow |
Diffpow test objective function |
| Method | dixonprice |
Dixon-Price 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 |
fun_as_arg(x, fun, *more_args) calls fun(x, *more_args). |
| Method | goldsteinprice |
Undocumented |
| Method | grad |
Undocumented |
| Method | grad |
Undocumented |
| Method | grad |
symmetric gradient |
| Method | grad |
Undocumented |
| Method | grad |
Undocumented |
| Method | grad |
Undocumented |
| Method | grad |
Undocumented |
| Method | griewank |
with search range [-5, 5] instead of [-600, 600] |
| Method | halfelli |
Undocumented |
| Method | happycat |
a difficult sharp ridge type function on a circle with xopt == -1. |
| 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 | noise |
Undocumented |
| Method | noisysphere |
noise/len(x) is the multiplicative, noise_offset is the additive factor. |
| Method | normal |
Undocumented |
| Method | optprob |
Undocumented |
| Method | partsphere |
Sphere (squared norm) test objective function |
| Method | pnorm |
Undocumented |
| Method | powel |
Undocumented |
| Method | rand |
Random test objective function |
| Method | rastrigin |
Rastrigin test objective function |
| Method | ridge |
Undocumented |
| Method | ridgecircle |
deprecated, see ridgeoncircle |
| Method | ridgeoncircle |
A sharp ridge on the hypersphere surface with xopt = -1 |
| Method | ridgeopt |
ridge with optimum in zero, by default a sharp ridge, namely return |
| Method | rosen |
Rosenbrock test objective function, x0=0 |
| Method | rosen0 |
Rosenbrock test objective function with optimum in all-zeros, x0=-1 |
| Method | rosen |
Undocumented |
| Method | rosen |
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 |
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 (norm squared) test objective function. |
| Method | sphere |
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 |
in [-5, 5] found also in Lazar and Jarre 2016, optimum in f(-2.903534...)=0 |
| Method | subspace |
random subspace sphere function, may be very difficult to solve |
| 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 | evaluations |
Undocumented |
| Property | BBOB |
Undocumented |
| Instance Variable | _subspace |
Undocumented |
| Instance Variable | _subspace |
Undocumented |
| Instance Variable | _subspace |
Undocumented |
return sum_i(0 if (optimum[0] <= x[i] <= optimum[1]) else 2**i)
to be minimized and add binary_foffset at the optimum.
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.
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 and add binary_foffset at the optimum.
return sum_i(0 if (optimum[0] <= x[i] <= optimum[1]) else 1)
to be minimized and add binary_foffset at the optimum.
a moderately difficult multimodal function with global structure,
generalized from 2-D like the Rosenbrock function. The search domain is [-100, 100].
Bukin function from Wikipedia, generalized simplistically from 2-D.
http://en.wikipedia.org/wiki/Test_functions_for_optimization
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.
Dixon-Price function.
The function has a local attractor at [1/3, 0, ..., 0] which starts to dominate for dimensions larger than about five. The global optimum is [1, 0.70710678, ...] with the limit of 1/2 for increasing index.
>>> import cma >>> def xstar(n): ... return [2**-((2**i - 2) / 2**i) for i in range(1, n + 1)] >>> assert cma.ff.dixonprice(xstar(4)) < 1e-11, cma.ff.dixonprice(xstar(4))
see https://al-roomi.org/benchmarks/unconstrained/n-dimensions/236-dixon-price-s-function
Ellipsoid test objective function
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)
a difficult sharp ridge type function on a circle with xopt == -1.
See ridgeoncircle for a more accessible implementation.
Reference: Beyer & Finck 2012, Happycat - a simple function class where well-known direct search algorithms do fail.
noise/len(x) is the multiplicative, noise_offset is the additive factor.
noise=10 does not work with default popsize, cma.NoiseHandler(dimension, 1e7) helps.
See also cma.fitness_transformations.NoisyFitness.
A sharp ridge on the hypersphere surface with xopt = -1
and f(xopt) = 0. The ridge surface is at the radius r = sqrt(n).
This is an implementation of happycat with a richer and more intuitive
parametrization and different defaults. The function is composed of
three different terms. Conceptually, while omitting an appropriate
weighting of terms, we have with decreasing relevance:
f(x) = ||x| - r| + linear(x) + |x|^2
where |.| means Eucledian norm or absolute value. The purpose of the last term is to prevent domination of the linear term when |x| > r.
expo = 1 is the exponent for ||x| - r|. The happycat default
is 1/4 (alpha == 1/8).
factor = 100 weighs the towards-ridge component in comparison to the
position-along-the-ridge component. By construction, df/dx of the latter
converges to zero when approaching the optimum, whereas the former
remains constant when expo == 1 and diverges when expo < 1. This
discrepancy between vanishing and nonvanishing (potentially infinite)
gradients makes this function difficult to solve. For the happycat,
this factor is not parametrized but equals in effect 2 * sqrt(n),
see below.
inner_expo = 1 is the exponent for both, |x| and r in the first
term. It creates an implicit factor multiplier which is, close to the
ridge, about inner_expo * sqrt(n)**(inner_expo - 1), hence 1 by
default. The happycat default is 2 which makes the factor multiplier
2 * sqrt(n) and different dimensions slightly incomparable.
Details
The most interesting parameter range is probably like 1 <= factor <= 1000 and 0.5 <= expo <= 1.5. SLSQP succeeds to get close to the optimum with expo >= 1.5 and, with expo <= 1, fails when factor >= 10 or expo <= 0.8.
This function can be considered as a nonstraight version of ridgeopt.
The vanishing gradient along the ridge due to the quadratic nature
of the hypersphere surface is analogous to exponent0 = 2 for
ridgeopt.
The inner_expo does not cancel expo, because the argument becomes
zero at the optimum only for the latter. The idea that these exponents
cancel might have lead to the default parameter choice for alpha of the
original Happycat function.
As by default, with expo=1 and factor=100, this looks quite similar to "the curve fitting problem".
functools.partial(cma.ff.ridgeoncircle, expo=1/2, factor=1,
inner_expo=2) instantiates ridgecircle up to a missing |x|^2/n/2 -
0.5 which is zero at -1. The happycat is instantiated below. The
expo=0.25 makes the Happycat much more difficult by default.
>>> import cma >>> val = cma.ff.ridgeoncircle([-1.01, -1.02]) >>> assert 2.12318 < val < 2.12319, val # ~ 100 * 0.02 >>> import functools # instantiate the happycat function >>> happycat = functools.partial(cma.ff.ridgeoncircle, ... expo=0.25, factor=1, inner_expo=2) >>> assert happycat([-1.2,3,4]) == cma.ff.happycat([-1.2,3,4]) >>> assert val != happycat([-1.01, -1.02]), val
ridge with optimum in zero, by default a sharp ridge, namely return
(x[0]**2)**(2/2) + 100 * sum(x[1:]**2)**(1/2). In general, return (x[0]**2)**(exponent0 / 2) + 100 * sum(x[1:]**2)**(ridge_exponent / 2).
The exponents reflect the respective shapes with increasing |x|, like 1 for linear, 2 for quadratic, and 0.5 for square root.
See also ridgeoncircle.
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"
Sphere (norm squared) test objective function.
The optimum is at -xoffset=0.
effective_dimensions can be an int or a ratio -> max(1, int(ratio
* len(x))).
See also cma.ff.noisysphere,
cma.fitness_transformations.NoisyFitness,
cma.fitness_transformations.LowEffectiveDimension and
cma.fitness_transformations.NeutralVariables.
random subspace sphere function, may be very difficult to solve
when the subspace changes with each evaluation.
same_subspace determines for how many evaluations the subspace remains
the same, True means always. The call subspace_sphere('new
subspace') resets the subspace such that a callback to fmin2 like:
fun = func_tools.partial(cma.ff.subspace_sphere, same_subspace=True)
mod = 1
cma.fmin2(..., callback=lambda es: (es.countiter % mod) or fun('new subspace'))
would reset the subspace every mod iterations.
Caveat: the same_subspace parameter has not been thoroughly tested.
>>> import functools, cma >>> fun = functools.partial(cma.ff.subspace_sphere, same_subspace=True) >>> val = fun(range(200)) >>> assert fun(range(200)) == val, val # fun does not change the subspace >>> perm = cma.ff._subspace_sphere_permutation >>> val2 = cma.ff.subspace_sphere(range(200)) # changes the subspace >>> assert perm is not cma.ff._subspace_sphere_permutation >>> perm = cma.ff._subspace_sphere_permutation >>> assert fun(range(200)) == val2 # fun does not change the subspace >>> assert perm is cma.ff._subspace_sphere_permutation >>> fun('new subspace') >>> assert perm is not cma.ff._subspace_sphere_permutation
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