class for non-linear non-convex numerical minimization with CMA-ES.
Examples
The Jupyter notebook or IPython are the favorite environments to
execute these examples, both in %pylab mode. All examples
minimize the function elli
, output is not shown.
First we need to import the module we want to use. We import purecma
from cma
as (aliased to) pcma:
from cma import purecma as pcma
The shortest example uses the inherited method
OOOptimizer.optimize
:
es = pcma.CMAES(8 * [0.1], 0.5).optimize(pcma.ff.elli)
See method CMAES.__init__ for a documentation of the input
parameters to CMAES. We might have a look at the result:
print(es.result[0]) # best solution and
print(es.result[1]) # its function value
result is a property of CMAES. In order to display more exciting
output, we may use the CMAESDataLogger instance in the logger
attribute of CMAES:
es.logger.plot() # if matplotlib is available
Virtually the same example can be written with an explicit loop
instead of using optimize
, see also fmin. This gives insight
into the CMAES class interface and entire control over the
iteration loop:
pcma.fmin?? # print source, works in jupyter/ipython only
es = pcma.CMAES(9 * [0.5], 0.3) # calls CMAES.__init__()
# this loop resembles the method optimize
while not es.stop(): # iterate
X = es.ask() # get candidate solutions
f = [pcma.ff.elli(x) for x in X] # evaluate solutions
es.tell(X, f) # do all the real work
es.disp(20) # display info every 20th iteration
es.logger.add(es) # log another "data line"
# final output
print('termination by', es.stop())
print('best f-value =', es.result[1])
print('best solution =', es.result[0])
print('potentially better solution xmean =', es.result[5])
print("let's check f(xmean) = ", pcma.ff.elli(es.result[5]))
es.logger.plot() # if matplotlib is available
A very similar example which may also save the logged data within
the loop is the implementation of function fmin.
|
__init__(self,
xstart,
sigma,
popsize=' 4 + int(3 * log(N)) ' ,
ftarget=None,
maxfevals=' 100 * popsize + 150 * (N + 3)**2 * popsize**0.5 ' ,
randn=<bound method Random.normalvariate of <random.Random object at... )
Instantiate CMAES object instance using xstart and sigma . |
source code
|
|
|
|
|
tell(self,
arx,
fitvals)
update the evolution paths and the distribution parameters m,
sigma, and C within CMA-ES. |
source code
|
|
|
stop(self)
return satisfied termination conditions in a dictionary, |
source code
|
|
|
disp(self,
verb_modulo=1)
print some iteration info to stdout |
source code
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|