fmin(objectivefct,
xstart,
sigma,
args=( ) ,
max_eval=' 1e3*N**2 ' ,
ftarget=None,
verb_disp=100,
verb_log=1,
verb_plot=100)
| source code
|
non-linear non-convex minimization procedure.
The functional interface to CMA-ES.
Parameters
objectivefct
- a function that takes as input a list of floats (like
[3.0, 2.2, 1.1]) and returns a single float (a scalar).
The objective is to find x with objectivefct(x)
to be as small as possible.
xstart
- list of numbers (like
[3,2,1.2] ), initial solution vector
sigma
- float, initial step-size, standard deviation in any coordinate
args
- arguments to
objectivefct
ftarget
- float, target function value
max_eval
- int or str, maximal number of function evaluations, a string
is evaluated with N being the search space dimension
verb_disp
- int, display on console every verb_disp iteration, 0 for never
verb_log
- int, data logging every verb_log iteration, 0 for never
verb_plot
- int, plot logged data every verb_plot iteration, 0 for never
Returns
return es.result() + (es.stop(), es, logger), that is,
(xbest, fbest, evalsbest, evals, iterations, xmean,
`` termination_condition, CMAES_object_instance, data_logger)``
Example
The following example minimizes the function Fcts.elli:
>> import barecmaes2 as cma
>> res = cma.fmin(cma.Fcts.elli, 10 * [0.5], 0.3, verb_disp=100)
evals: ax-ratio max(std) f-value
10: 1.0 2.8e-01 198003.585517
1000: 8.4 5.5e-02 95.9162313173
2000: 40.5 3.6e-02 5.07618122556
3000: 149.1 8.5e-03 0.271537247667
4000: 302.2 4.2e-03 0.0623570374451
5000: 681.1 5.9e-03 0.000485971681802
6000: 1146.4 9.5e-06 5.26919100476e-10
6510: 1009.1 2.3e-07 3.34128914738e-13
termination by {'tolfun': 1e-12}
best f-value = 3.34128914738e-13
>> print(res[0])
[2.1187532328944602e-07, 6.893386424102321e-08, -2.008255256456535e-09, 4.472078873398156e-09, -9.421306741003398e-09, 7.331265238205156e-09, 2.4804701814730273e-10, -6.030651566971234e-10, -6.063921614755129e-10, -1.066906137937511e-10]
>> print(res[1])
3.34128914738e-13
>> res[-1].plot() # needs pylab/matplotlib to be installed
Details
By default fmin() tries to plot some output. This works only with
Python module matplotlib being installed. The first and last lines
cma.fmin(cma.Fcts.elli, 10 * [0.5], 0.3, verb_plot=0)
logger = cma.CMADataLogger()
cma.CMAES(10 * [0.5], 0.3).optimize(cma.Fcts.elli, logger=logger)
do the same. fmin() adds the possibility to plot during the
execution.
|