(func, x0, sigma0=None, args=()
    # the follow string arguments are evaluated, besides the verb_filenameprefix
    , CMA_active='False  # exponential negative update, conducted after the original update'
    , CMA_activefac='1  # learning rate multiplier for active update'
    , CMA_cmean='1  # learning rate for the mean value'
    , CMA_const_trace='False  # normalize trace, value CMA_const_trace=2 normalizes sum log eigenvalues to zero'
    , CMA_diagonal='0*100*N/sqrt(popsize)  # nb of iterations with diagonal covariance matrix, True for always' # TODO 4/ccov_separable?
    , CMA_eigenmethod='np.linalg.eigh  # 0=numpy-s eigh, -1=pygsl, otherwise cma.Misc.eig (slower)'
    , CMA_elitist='False # elitism likely impairs global search performance'
    , CMA_mirrors='popsize < 6  # values <0.5 are interpreted as fraction, values >1 as numbers (rounded), otherwise about 0.16 is used'
    , CMA_mu='None  # parents selection parameter, default is popsize // 2'
    , CMA_on='True  # False or 0 for no adaptation of the covariance matrix'
    , CMA_rankmu='True  # False or 0 for omitting rank-mu update of covariance matrix'
    , CMA_rankmualpha='0.3  # factor of rank-mu update if mu=1, subject to removal, default might change to 0.0'
    , CMA_dampfac='1  #v positive multiplier for step-size damping, 0.3 is close to optimal on the sphere'
    , CMA_dampsvec_fac='np.Inf  # tentative and subject to changes, 0.5 would be a "default" damping for sigma vector update'
    , CMA_dampsvec_fade='0.1  # tentative fading out parameter for sigma vector update'
    , CMA_teststds='None  # factors for non-isotropic initial distr. mainly for test purpose, see scaling_...'
    , CMA_AII='False  # not yet tested'
    , bounds='[None, None]  # lower (=bounds[0]) and upper domain boundaries, each a scalar or a list/vector'
    , eval_parallel='False  # when True, func might be called with more than one solution as first argument'
    , eval_initial_x='False  # '
    , fixed_variables='None  # dictionary with index-value pairs like {0:1.1, 2:0.1} that are not optimized'
    , ftarget='-inf  #v target function value, minimization'
    , incpopsize='2  # in fmin(): multiplier for increasing popsize before each restart'
    , maxfevals='inf  #v maximum number of function evaluations'
    , maxiter='100 + 50 * (N+3)**2 // popsize**0.5  #v maximum number of iterations'
    , mindx='0  #v minimal std in any direction, cave interference with tol*'
    , minstd='0  #v minimal std in any coordinate direction, cave interference with tol*'
    , noise_handling='False  # maximal number of evaluations for noise treatment, only fmin'
    , noise_reevals=' 1.5 + popsize/20  # number of solution to be reevaluated for noise measurement, only fmin'
    , noise_eps='1e-7  # perturbation factor for noise handling reevaluations, only fmin'
    , noise_change_sigma='True  # exponent to default sigma increment'
    , popsize='4+int(3*log(N))  # population size, AKA lambda, number of new solution per iteration'
    , randn='np.random.standard_normal  #v randn((lam, N)) must return an np.array of shape (lam, N)'
    , restarts='0  # in fmin(): number of restarts'
    , restart_from_best='False'
    , scaling_of_variables='None  # scale for each variable, sigma0 is interpreted w.r.t. this scale, in that effective_sigma0 = sigma0*scaling. Internally the variables are divided by scaling_of_variables and sigma is unchanged, default is ones(N)'
    , seed='None  # random number seed'
    , termination_callback='None  #v a function returning True for termination, called after each iteration step and could be abused for side effects'
    , tolfacupx='1e3  #v termination when step-size increases by tolfacupx (diverges). That is, the initial step-size was chosen far too small and better solutions were found far away from the initial solution x0'
    , tolupsigma='1e20  #v sigma/sigma0 > tolupsigma * max(sqrt(eivenvals(C))) indicates "creeping behavior" with usually minor improvements'
    , tolfun='1e-11  #v termination criterion: tolerance in function value, quite useful'
    , tolfunhist='1e-12  #v termination criterion: tolerance in function value history'
    , tolstagnation='int(100 + 100 * N**1.5 / popsize)  #v termination if no improvement over tolstagnation iterations'
    , tolx='1e-11  #v termination criterion: tolerance in x-changes'
    , transformation='None  # [t0, t1] are two mappings, t0 transforms solutions from CMA-representation to f-representation (tf_pheno), t1 is the (optional) back transformation, see class GenoPheno'
    , typical_x='None  # used with scaling_of_variables'
    , updatecovwait='None  #v number of iterations without distribution update, name is subject to future changes' # TODO: rename: iterwaitupdatedistribution?
    , verb_append='0  # initial evaluation counter, if append, do not overwrite output files'
    , verb_disp='100  #v verbosity: display console output every verb_disp iteration'
    , verb_filenameprefix='outcmaes  # output filenames prefix'
    , verb_log='1  #v verbosity: write data to files every verb_log iteration, writing can be time critical on fast to evaluate functions'
    , verb_plot='0  #v in fmin(): plot() is called every verb_plot iteration'
    , verb_time='True  #v output timings on console'
    , vv='0  #? versatile variable for hacking purposes, value found in self.opts[\'vv\']'
     )
functional interface to the stochastic optimizer CMA-ES
    for non-convex function minimization.

    Calling Sequences
    =================
        ``fmin([],[])``
            returns all optional arguments, that is,
            all keyword arguments to fmin with their default values
            in a dictionary.
        ``fmin(func, x0, sigma0)``
            minimizes `func` starting at `x0` and with standard deviation
            `sigma0` (step-size)
        ``fmin(func, x0, sigma0, ftarget=1e-5)``
            minimizes `func` up to target function value 1e-5
        ``fmin(func, x0, sigma0, args=('f',), **options)``
            minimizes `func` called with an additional argument ``'f'``.
            `options` is a dictionary with additional keyword arguments, e.g.
            delivered by `Options()`.
        ``fmin(func, x0, sigma0, **{'ftarget':1e-5, 'popsize':40})``
            the same as ``fmin(func, x0, sigma0, ftarget=1e-5, popsize=40)``
        ``fmin(func, esobj, **{'maxfevals': 1e5})``
            uses the `CMAEvolutionStrategy` object instance `esobj` to optimize
            `func`, similar to `CMAEvolutionStrategy.optimize()`.

    Arguments
    =========
        `func`
            function to be minimized. Called as
            ``func(x,*args)``. `x` is a one-dimensional `numpy.ndarray`. `func`
            can return `numpy.NaN`,
            which is interpreted as outright rejection of solution `x`
            and invokes an immediate resampling and (re-)evaluation
            of a new solution not counting as function evaluation.
        `x0`
            list or `numpy.ndarray`, initial guess of minimum solution
            or `cma.CMAEvolutionStrategy` object instance. In this case
            `sigma0` can be omitted.
        `sigma0`
            scalar, initial standard deviation in each coordinate.
            `sigma0` should be about 1/4 of the search domain width where the
            optimum is to be expected. The variables in `func` should be
            scaled such that they presumably have similar sensitivity.
            See also option `scaling_of_variables`.

    Keyword Arguments
    =================
    All arguments besides `args` and `verb_filenameprefix` are evaluated
    if they are of type `str`, see class `Options` for details. The following
    list might not be fully up-to-date, use ``cma.Options()`` or
    ``cma.fmin([],[])`` to get the actual list.
    ::

        args=() -- additional arguments for func, not in `cma.Options()`
        CMA_active='False  # exponential negative update, conducted after the original
                update'
        CMA_activefac='1  # learning rate multiplier for active update'
        CMA_cmean='1  # learning rate for the mean value'
        CMA_dampfac='1  #v positive multiplier for step-size damping, 0.3 is close to
                optimal on the sphere'
        CMA_diagonal='0*100*N/sqrt(popsize)  # nb of iterations with diagonal
                covariance matrix, True for always'
        CMA_eigenmethod='np.linalg.eigh  # 0=numpy-s eigh, -1=pygsl, alternative: Misc.eig (slower)'
        CMA_elitist='False # elitism likely impairs global search performance'
        CMA_mirrors='0  # values <0.5 are interpreted as fraction, values >1 as numbers
                (rounded), otherwise about 0.16 is used'
        CMA_mu='None  # parents selection parameter, default is popsize // 2'
        CMA_on='True  # False or 0 for no adaptation of the covariance matrix'
        CMA_rankmu='True  # False or 0 for omitting rank-mu update of covariance
                matrix'
        CMA_rankmualpha='0.3  # factor of rank-mu update if mu=1, subject to removal,
                default might change to 0.0'
        CMA_teststds='None  # factors for non-isotropic initial distr. mainly for test
                purpose, see scaling_...'
        bounds='[None, None]  # lower (=bounds[0]) and upper domain boundaries, each a
                scalar or a list/vector'
        eval_initial_x='False  # '
        fixed_variables='None  # dictionary with index-value pairs like {0:1.1, 2:0.1}
                that are not optimized'
        ftarget='-inf  #v target function value, minimization'
        incpopsize='2  # in fmin(): multiplier for increasing popsize before each
                restart'
        maxfevals='inf  #v maximum number of function evaluations'
        maxiter='long(1e3*N**2/sqrt(popsize))  #v maximum number of iterations'
        mindx='0  #v minimal std in any direction, cave interference with tol*'
        minstd='0  #v minimal std in any coordinate direction, cave interference with
                tol*'
        noise_eps='1e-7  # perturbation factor for noise handling reevaluations, only
                fmin'
        noise_handling='False  # maximal number of evaluations for noise treatment,
                only fmin'
        noise_reevals=' 1.5 + popsize/20  # number of solution to be reevaluated for
                noise measurement, only fmin'
        popsize='4+int(3*log(N))  # population size, AKA lambda, number of new solution
                per iteration'
        randn='np.random.standard_normal  #v randn((lam, N)) must return an np.array of
                shape (lam, N)'
        restarts='0  # in fmin(): number of restarts'
        scaling_of_variables='None  # scale for each variable, sigma0 is interpreted
                w.r.t. this scale, in that effective_sigma0 = sigma0*scaling.
                Internally the variables are divided by scaling_of_variables and sigma
                is unchanged, default is ones(N)'
        seed='None  # random number seed'
        termination_callback='None  #v in fmin(): a function returning True for
                termination, called after each iteration step and could be abused for
                side effects'
        tolfacupx='1e3  #v termination when step-size increases by tolfacupx
                (diverges). That is, the initial step-size was chosen far too small and
                better solutions were found far away from the initial solution x0'
        tolupsigma='1e20  #v sigma/sigma0 > tolupsigma * max(sqrt(eivenvals(C)))
                indicates "creeping behavior" with usually minor improvements'
        tolfun='1e-11  #v termination criterion: tolerance in function value, quite
                useful'
        tolfunhist='1e-12  #v termination criterion: tolerance in function value
                history'
        tolstagnation='int(100 * N**1.5 / popsize)  #v termination if no improvement
                over tolstagnation iterations'
        tolx='1e-11  #v termination criterion: tolerance in x-changes'
        transformation='None  # [t0, t1] are two mappings, t0 transforms solutions from
                CMA-representation to f-representation, t1 is the back transformation,
                see class GenoPheno'
        typical_x='None  # used with scaling_of_variables'
        updatecovwait='None  #v number of iterations without distribution update, name
                is subject to future changes'
        verb_append='0  # initial evaluation counter, if append, do not overwrite
                output files'
        verb_disp='100  #v verbosity: display console output every verb_disp iteration'
        verb_filenameprefix='outcmaes  # output filenames prefix'
        verb_log='1  #v verbosity: write data to files every verb_log iteration,
                writing can be time critical on fast to evaluate functions'
        verb_plot='0  #v in fmin(): plot() is called every verb_plot iteration'
        verb_time='True  #v output timings on console'
        vv='0  #? versatile variable for hacking purposes, value found in
                self.opts['vv']'

    Subsets of options can be displayed, for example like ``cma.Options('tol')``,
    see also class `Options`.

    Return
    ======
    Similar to `OOOptimizer.optimize()` and/or `CMAEvolutionStrategy.optimize()`, return the
    list provided by `CMAEvolutionStrategy.result()` appended with an `OOOptimizer` and an
    `BaseDataLogger`::

        res = optim.result() + (optim.stop(), optim, logger)

    where
        - ``res[0]`` (``xopt``) -- best evaluated solution
        - ``res[1]`` (``fopt``) -- respective function value
        - ``res[2]`` (``evalsopt``) -- respective number of function evaluations
        - ``res[3]`` (``evals``) -- number of overall conducted objective function evaluations
        - ``res[4]`` (``iterations``) -- number of overall conducted iterations
        - ``res[5]`` (``xmean``) -- mean of the final sample distribution
        - ``res[6]`` (``stds``) -- effective stds of the final sample distribution
        - ``res[-3]`` (``stop``) -- termination condition(s) in a dictionary
        - ``res[-2]`` (``cmaes``) -- class `CMAEvolutionStrategy` instance
        - ``res[-1]`` (``logger``) -- class `CMADataLogger` instance

    Details
    =======
    This function is an interface to the class `CMAEvolutionStrategy`. The
    class can be used when full control over the iteration loop of the
    optimizer is desired.

    The noise handling follows closely [Hansen et al 2009, A Method for Handling
    Uncertainty in Evolutionary Optimization...] in the measurement part, but the
    implemented treatment is slightly different: for ``noiseS > 0``, ``evaluations``
    (time) and sigma are increased by ``alpha``. For ``noiseS < 0``, ``evaluations``
    (time) is decreased by ``alpha**(1/4)``. The option ``noise_handling`` switches
    the uncertainty handling on/off, the given value defines the maximal number
    of evaluations for a single fitness computation. If ``noise_handling`` is a list,
    the smallest element defines the minimal number and if the list has three elements,
    the median value is the start value for ``evaluations``. See also class
    `NoiseHandler`.

    Examples
    ========
    The following example calls `fmin` optimizing the Rosenbrock function
    in 10-D with initial solution 0.1 and initial step-size 0.5. The
    options are specified for the usage with the `doctest` module.

    >>> import cma
    >>> # cma.Options()  # returns all possible options
    >>> options = {'CMA_diagonal':10, 'seed':1234, 'verb_time':0}
    >>>
    >>> res = cma.fmin(cma.fcts.rosen, [0.1] * 10, 0.5, **options)
    (5_w,10)-CMA-ES (mu_w=3.2,w_1=45%) in dimension 10 (seed=1234)
       Covariance matrix is diagonal for 10 iterations (1/ccov=29.0)
    Iterat #Fevals   function value     axis ratio  sigma   minstd maxstd min:sec
        1      10 1.264232686260072e+02 1.1e+00 4.40e-01  4e-01  4e-01
        2      20 1.023929748193649e+02 1.1e+00 4.00e-01  4e-01  4e-01
        3      30 1.214724267489674e+02 1.2e+00 3.70e-01  3e-01  4e-01
      100    1000 6.366683525319511e+00 6.2e+00 2.49e-02  9e-03  3e-02
      200    2000 3.347312410388666e+00 1.2e+01 4.52e-02  8e-03  4e-02
      300    3000 1.027509686232270e+00 1.3e+01 2.85e-02  5e-03  2e-02
      400    4000 1.279649321170636e-01 2.3e+01 3.53e-02  3e-03  3e-02
      500    5000 4.302636076186532e-04 4.6e+01 4.78e-03  3e-04  5e-03
      600    6000 6.943669235595049e-11 5.1e+01 5.41e-06  1e-07  4e-06
      650    6500 5.557961334063003e-14 5.4e+01 1.88e-07  4e-09  1e-07
    termination on tolfun : 1e-11
    final/bestever f-value = 5.55796133406e-14 2.62435631419e-14
    mean solution:  [ 1.          1.00000001  1.          1.
        1.          1.00000001  1.00000002  1.00000003 ...]
    std deviation: [ 3.9193387e-09  3.7792732e-09  4.0062285e-09  4.6605925e-09
        5.4966188e-09   7.4377745e-09   1.3797207e-08   2.6020765e-08 ...]
    >>>
    >>> print('best solutions fitness = %f' % (res[1]))
    best solutions fitness = 2.62435631419e-14
    >>> assert res[1] < 1e-12

    The method ::

        cma.plot();

    (based on `matplotlib.pylab`) produces a plot of the run and, if necessary::

        cma.show()

    shows the plot in a window. To continue you might need to
    close the pop-up window. This behavior seems to disappear in
    subsequent calls of `cma.plot()` and is avoided by using
    `ipython` with `-pylab` option. Finally ::

        cma.savefig('myfirstrun')  # savefig from matplotlib.pylab

    will save the figure in a png.

    :See: `CMAEvolutionStrategy`, `OOOptimizer.optimize(), `plot()`, `Options`, `scipy.optimize.fmin()`
functional interface to the stochastic optimizer CMA-ES
    for non-convex function minimization.
functional interface to the stochastic optimizer CMA - ES for non - convex function minimization .
def fmin(func, x0, sigma0=None, args=()
    # the follow string arguments are evaluated, besides the verb_filenameprefix
    , CMA_active='False  # exponential negative update, conducted after the original update'
    , CMA_activefac='1  # learning rate multiplier for active update'
    , CMA_cmean='1  # learning rate for the mean value'
    , CMA_const_trace='False  # normalize trace, value CMA_const_trace=2 normalizes sum log eigenvalues to zero'
    , CMA_diagonal='0*100*N/sqrt(popsize)  # nb of iterations with diagonal covariance matrix, True for always' # TODO 4/ccov_separable?
    , CMA_eigenmethod='np.linalg.eigh  # 0=numpy-s eigh, -1=pygsl, otherwise cma.Misc.eig (slower)'
    , CMA_elitist='False # elitism likely impairs global search performance'
    , CMA_mirrors='popsize < 6  # values <0.5 are interpreted as fraction, values >1 as numbers (rounded), otherwise about 0.16 is used'
    , CMA_mu='None  # parents selection parameter, default is popsize // 2'
    , CMA_on='True  # False or 0 for no adaptation of the covariance matrix'
    , CMA_rankmu='True  # False or 0 for omitting rank-mu update of covariance matrix'
    , CMA_rankmualpha='0.3  # factor of rank-mu update if mu=1, subject to removal, default might change to 0.0'
    , CMA_dampfac='1  #v positive multiplier for step-size damping, 0.3 is close to optimal on the sphere'
    , CMA_dampsvec_fac='np.Inf  # tentative and subject to changes, 0.5 would be a "default" damping for sigma vector update'
    , CMA_dampsvec_fade='0.1  # tentative fading out parameter for sigma vector update'
    , CMA_teststds='None  # factors for non-isotropic initial distr. mainly for test purpose, see scaling_...'
    , CMA_AII='False  # not yet tested'
    , bounds='[None, None]  # lower (=bounds[0]) and upper domain boundaries, each a scalar or a list/vector'
    , eval_parallel='False  # when True, func might be called with more than one solution as first argument'
    , eval_initial_x='False  # '
    , fixed_variables='None  # dictionary with index-value pairs like {0:1.1, 2:0.1} that are not optimized'
    , ftarget='-inf  #v target function value, minimization'
    , incpopsize='2  # in fmin(): multiplier for increasing popsize before each restart'
    , maxfevals='inf  #v maximum number of function evaluations'
    , maxiter='100 + 50 * (N+3)**2 // popsize**0.5  #v maximum number of iterations'
    , mindx='0  #v minimal std in any direction, cave interference with tol*'
    , minstd='0  #v minimal std in any coordinate direction, cave interference with tol*'
    , noise_handling='False  # maximal number of evaluations for noise treatment, only fmin'
    , noise_reevals=' 1.5 + popsize/20  # number of solution to be reevaluated for noise measurement, only fmin'
    , noise_eps='1e-7  # perturbation factor for noise handling reevaluations, only fmin'
    , noise_change_sigma='True  # exponent to default sigma increment'
    , popsize='4+int(3*log(N))  # population size, AKA lambda, number of new solution per iteration'
    , randn='np.random.standard_normal  #v randn((lam, N)) must return an np.array of shape (lam, N)'
    , restarts='0  # in fmin(): number of restarts'
    , restart_from_best='False'
    , scaling_of_variables='None  # scale for each variable, sigma0 is interpreted w.r.t. this scale, in that effective_sigma0 = sigma0*scaling. Internally the variables are divided by scaling_of_variables and sigma is unchanged, default is ones(N)'
    , seed='None  # random number seed'
    , termination_callback='None  #v a function returning True for termination, called after each iteration step and could be abused for side effects'
    , tolfacupx='1e3  #v termination when step-size increases by tolfacupx (diverges). That is, the initial step-size was chosen far too small and better solutions were found far away from the initial solution x0'
    , tolupsigma='1e20  #v sigma/sigma0 > tolupsigma * max(sqrt(eivenvals(C))) indicates "creeping behavior" with usually minor improvements'
    , tolfun='1e-11  #v termination criterion: tolerance in function value, quite useful'
    , tolfunhist='1e-12  #v termination criterion: tolerance in function value history'
    , tolstagnation='int(100 + 100 * N**1.5 / popsize)  #v termination if no improvement over tolstagnation iterations'
    , tolx='1e-11  #v termination criterion: tolerance in x-changes'
    , transformation='None  # [t0, t1] are two mappings, t0 transforms solutions from CMA-representation to f-representation (tf_pheno), t1 is the (optional) back transformation, see class GenoPheno'
    , typical_x='None  # used with scaling_of_variables'
    , updatecovwait='None  #v number of iterations without distribution update, name is subject to future changes' # TODO: rename: iterwaitupdatedistribution?
    , verb_append='0  # initial evaluation counter, if append, do not overwrite output files'
    , verb_disp='100  #v verbosity: display console output every verb_disp iteration'
    , verb_filenameprefix='outcmaes  # output filenames prefix'
    , verb_log='1  #v verbosity: write data to files every verb_log iteration, writing can be time critical on fast to evaluate functions'
    , verb_plot='0  #v in fmin(): plot() is called every verb_plot iteration'
    , verb_time='True  #v output timings on console'
    , vv='0  #? versatile variable for hacking purposes, value found in self.opts[\'vv\']'
     ):
    """functional interface to the stochastic optimizer CMA-ES
    for non-convex function minimization.

    Calling Sequences
    =================
        ``fmin([],[])``
            returns all optional arguments, that is,
            all keyword arguments to fmin with their default values
            in a dictionary.
        ``fmin(func, x0, sigma0)``
            minimizes `func` starting at `x0` and with standard deviation
            `sigma0` (step-size)
        ``fmin(func, x0, sigma0, ftarget=1e-5)``
            minimizes `func` up to target function value 1e-5
        ``fmin(func, x0, sigma0, args=('f',), **options)``
            minimizes `func` called with an additional argument ``'f'``.
            `options` is a dictionary with additional keyword arguments, e.g.
            delivered by `Options()`.
        ``fmin(func, x0, sigma0, **{'ftarget':1e-5, 'popsize':40})``
            the same as ``fmin(func, x0, sigma0, ftarget=1e-5, popsize=40)``
        ``fmin(func, esobj, **{'maxfevals': 1e5})``
            uses the `CMAEvolutionStrategy` object instance `esobj` to optimize
            `func`, similar to `CMAEvolutionStrategy.optimize()`.

    Arguments
    =========
        `func`
            function to be minimized. Called as
            ``func(x,*args)``. `x` is a one-dimensional `numpy.ndarray`. `func`
            can return `numpy.NaN`,
            which is interpreted as outright rejection of solution `x`
            and invokes an immediate resampling and (re-)evaluation
            of a new solution not counting as function evaluation.
        `x0`
            list or `numpy.ndarray`, initial guess of minimum solution
            or `cma.CMAEvolutionStrategy` object instance. In this case
            `sigma0` can be omitted.
        `sigma0`
            scalar, initial standard deviation in each coordinate.
            `sigma0` should be about 1/4 of the search domain width where the
            optimum is to be expected. The variables in `func` should be
            scaled such that they presumably have similar sensitivity.
            See also option `scaling_of_variables`.

    Keyword Arguments
    =================
    All arguments besides `args` and `verb_filenameprefix` are evaluated
    if they are of type `str`, see class `Options` for details. The following
    list might not be fully up-to-date, use ``cma.Options()`` or
    ``cma.fmin([],[])`` to get the actual list.
    ::

        args=() -- additional arguments for func, not in `cma.Options()`
        CMA_active='False  # exponential negative update, conducted after the original
                update'
        CMA_activefac='1  # learning rate multiplier for active update'
        CMA_cmean='1  # learning rate for the mean value'
        CMA_dampfac='1  #v positive multiplier for step-size damping, 0.3 is close to
                optimal on the sphere'
        CMA_diagonal='0*100*N/sqrt(popsize)  # nb of iterations with diagonal
                covariance matrix, True for always'
        CMA_eigenmethod='np.linalg.eigh  # 0=numpy-s eigh, -1=pygsl, alternative: Misc.eig (slower)'
        CMA_elitist='False # elitism likely impairs global search performance'
        CMA_mirrors='0  # values <0.5 are interpreted as fraction, values >1 as numbers
                (rounded), otherwise about 0.16 is used'
        CMA_mu='None  # parents selection parameter, default is popsize // 2'
        CMA_on='True  # False or 0 for no adaptation of the covariance matrix'
        CMA_rankmu='True  # False or 0 for omitting rank-mu update of covariance
                matrix'
        CMA_rankmualpha='0.3  # factor of rank-mu update if mu=1, subject to removal,
                default might change to 0.0'
        CMA_teststds='None  # factors for non-isotropic initial distr. mainly for test
                purpose, see scaling_...'
        bounds='[None, None]  # lower (=bounds[0]) and upper domain boundaries, each a
                scalar or a list/vector'
        eval_initial_x='False  # '
        fixed_variables='None  # dictionary with index-value pairs like {0:1.1, 2:0.1}
                that are not optimized'
        ftarget='-inf  #v target function value, minimization'
        incpopsize='2  # in fmin(): multiplier for increasing popsize before each
                restart'
        maxfevals='inf  #v maximum number of function evaluations'
        maxiter='long(1e3*N**2/sqrt(popsize))  #v maximum number of iterations'
        mindx='0  #v minimal std in any direction, cave interference with tol*'
        minstd='0  #v minimal std in any coordinate direction, cave interference with
                tol*'
        noise_eps='1e-7  # perturbation factor for noise handling reevaluations, only
                fmin'
        noise_handling='False  # maximal number of evaluations for noise treatment,
                only fmin'
        noise_reevals=' 1.5 + popsize/20  # number of solution to be reevaluated for
                noise measurement, only fmin'
        popsize='4+int(3*log(N))  # population size, AKA lambda, number of new solution
                per iteration'
        randn='np.random.standard_normal  #v randn((lam, N)) must return an np.array of
                shape (lam, N)'
        restarts='0  # in fmin(): number of restarts'
        scaling_of_variables='None  # scale for each variable, sigma0 is interpreted
                w.r.t. this scale, in that effective_sigma0 = sigma0*scaling.
                Internally the variables are divided by scaling_of_variables and sigma
                is unchanged, default is ones(N)'
        seed='None  # random number seed'
        termination_callback='None  #v in fmin(): a function returning True for
                termination, called after each iteration step and could be abused for
                side effects'
        tolfacupx='1e3  #v termination when step-size increases by tolfacupx
                (diverges). That is, the initial step-size was chosen far too small and
                better solutions were found far away from the initial solution x0'
        tolupsigma='1e20  #v sigma/sigma0 > tolupsigma * max(sqrt(eivenvals(C)))
                indicates "creeping behavior" with usually minor improvements'
        tolfun='1e-11  #v termination criterion: tolerance in function value, quite
                useful'
        tolfunhist='1e-12  #v termination criterion: tolerance in function value
                history'
        tolstagnation='int(100 * N**1.5 / popsize)  #v termination if no improvement
                over tolstagnation iterations'
        tolx='1e-11  #v termination criterion: tolerance in x-changes'
        transformation='None  # [t0, t1] are two mappings, t0 transforms solutions from
                CMA-representation to f-representation, t1 is the back transformation,
                see class GenoPheno'
        typical_x='None  # used with scaling_of_variables'
        updatecovwait='None  #v number of iterations without distribution update, name
                is subject to future changes'
        verb_append='0  # initial evaluation counter, if append, do not overwrite
                output files'
        verb_disp='100  #v verbosity: display console output every verb_disp iteration'
        verb_filenameprefix='outcmaes  # output filenames prefix'
        verb_log='1  #v verbosity: write data to files every verb_log iteration,
                writing can be time critical on fast to evaluate functions'
        verb_plot='0  #v in fmin(): plot() is called every verb_plot iteration'
        verb_time='True  #v output timings on console'
        vv='0  #? versatile variable for hacking purposes, value found in
                self.opts['vv']'

    Subsets of options can be displayed, for example like ``cma.Options('tol')``,
    see also class `Options`.

    Return
    ======
    Similar to `OOOptimizer.optimize()` and/or `CMAEvolutionStrategy.optimize()`, return the
    list provided by `CMAEvolutionStrategy.result()` appended with an `OOOptimizer` and an
    `BaseDataLogger`::

        res = optim.result() + (optim.stop(), optim, logger)

    where
        - ``res[0]`` (``xopt``) -- best evaluated solution
        - ``res[1]`` (``fopt``) -- respective function value
        - ``res[2]`` (``evalsopt``) -- respective number of function evaluations
        - ``res[3]`` (``evals``) -- number of overall conducted objective function evaluations
        - ``res[4]`` (``iterations``) -- number of overall conducted iterations
        - ``res[5]`` (``xmean``) -- mean of the final sample distribution
        - ``res[6]`` (``stds``) -- effective stds of the final sample distribution
        - ``res[-3]`` (``stop``) -- termination condition(s) in a dictionary
        - ``res[-2]`` (``cmaes``) -- class `CMAEvolutionStrategy` instance
        - ``res[-1]`` (``logger``) -- class `CMADataLogger` instance

    Details
    =======
    This function is an interface to the class `CMAEvolutionStrategy`. The
    class can be used when full control over the iteration loop of the
    optimizer is desired.

    The noise handling follows closely [Hansen et al 2009, A Method for Handling
    Uncertainty in Evolutionary Optimization...] in the measurement part, but the
    implemented treatment is slightly different: for ``noiseS > 0``, ``evaluations``
    (time) and sigma are increased by ``alpha``. For ``noiseS < 0``, ``evaluations``
    (time) is decreased by ``alpha**(1/4)``. The option ``noise_handling`` switches
    the uncertainty handling on/off, the given value defines the maximal number
    of evaluations for a single fitness computation. If ``noise_handling`` is a list,
    the smallest element defines the minimal number and if the list has three elements,
    the median value is the start value for ``evaluations``. See also class
    `NoiseHandler`.

    Examples
    ========
    The following example calls `fmin` optimizing the Rosenbrock function
    in 10-D with initial solution 0.1 and initial step-size 0.5. The
    options are specified for the usage with the `doctest` module.

    >>> import cma
    >>> # cma.Options()  # returns all possible options
    >>> options = {'CMA_diagonal':10, 'seed':1234, 'verb_time':0}
    >>>
    >>> res = cma.fmin(cma.fcts.rosen, [0.1] * 10, 0.5, **options)
    (5_w,10)-CMA-ES (mu_w=3.2,w_1=45%) in dimension 10 (seed=1234)
       Covariance matrix is diagonal for 10 iterations (1/ccov=29.0)
    Iterat #Fevals   function value     axis ratio  sigma   minstd maxstd min:sec
        1      10 1.264232686260072e+02 1.1e+00 4.40e-01  4e-01  4e-01
        2      20 1.023929748193649e+02 1.1e+00 4.00e-01  4e-01  4e-01
        3      30 1.214724267489674e+02 1.2e+00 3.70e-01  3e-01  4e-01
      100    1000 6.366683525319511e+00 6.2e+00 2.49e-02  9e-03  3e-02
      200    2000 3.347312410388666e+00 1.2e+01 4.52e-02  8e-03  4e-02
      300    3000 1.027509686232270e+00 1.3e+01 2.85e-02  5e-03  2e-02
      400    4000 1.279649321170636e-01 2.3e+01 3.53e-02  3e-03  3e-02
      500    5000 4.302636076186532e-04 4.6e+01 4.78e-03  3e-04  5e-03
      600    6000 6.943669235595049e-11 5.1e+01 5.41e-06  1e-07  4e-06
      650    6500 5.557961334063003e-14 5.4e+01 1.88e-07  4e-09  1e-07
    termination on tolfun : 1e-11
    final/bestever f-value = 5.55796133406e-14 2.62435631419e-14
    mean solution:  [ 1.          1.00000001  1.          1.
        1.          1.00000001  1.00000002  1.00000003 ...]
    std deviation: [ 3.9193387e-09  3.7792732e-09  4.0062285e-09  4.6605925e-09
        5.4966188e-09   7.4377745e-09   1.3797207e-08   2.6020765e-08 ...]
    >>>
    >>> print('best solutions fitness = %f' % (res[1]))
    best solutions fitness = 2.62435631419e-14
    >>> assert res[1] < 1e-12

    The method ::

        cma.plot();

    (based on `matplotlib.pylab`) produces a plot of the run and, if necessary::

        cma.show()

    shows the plot in a window. To continue you might need to
    close the pop-up window. This behavior seems to disappear in
    subsequent calls of `cma.plot()` and is avoided by using
    `ipython` with `-pylab` option. Finally ::

        cma.savefig('myfirstrun')  # savefig from matplotlib.pylab

    will save the figure in a png.

    :See: `CMAEvolutionStrategy`, `OOOptimizer.optimize(), `plot()`, `Options`, `scipy.optimize.fmin()`

    """ # style guides say there should be the above empty line
    try: # pass on KeyboardInterrupt
        opts = locals()  # collect all local variables (i.e. arguments) in a dictionary
        del opts['func'] # remove those without a default value
        del opts['args']
        del opts['x0']      # is not optional, no default available
        del opts['sigma0']  # is not optional for the constructor CMAEvolutionStrategy
        if not func:  # return available options in a dictionary
            return Options(opts, True)  # these opts are by definition valid

        # TODO: this is very ugly:
        incpopsize = Options({'incpopsize':incpopsize}).eval('incpopsize')
        restarts = Options({'restarts':restarts}).eval('restarts')
        del opts['restarts']
        noise_handling = Options({'noise_handling': noise_handling}).eval('noise_handling')
        del opts['noise_handling']# otherwise CMA throws an error

        irun = 0
        best = BestSolution()
        while 1:
            # recover from a CMA object
            if irun == 0 and isinstance(x0, CMAEvolutionStrategy):
                es = x0
                x0 = es.inputargs['x0']  # for the next restarts
                if sigma0 is None or not np.isscalar(array(sigma0)):
                    sigma0 = es.inputargs['sigma0']  # for the next restarts
                # ignore further input args and keep original options
            else:  # default case
                if irun and opts['restart_from_best']:
                    print('CAVE: restart_from_best is typically not useful')
                    es = CMAEvolutionStrategy(best.x, sigma0, opts)
                else:
                    es = CMAEvolutionStrategy(x0, sigma0, opts)
                if opts['eval_initial_x']:
                    x = es.gp.pheno(es.mean, bounds=es.gp.bounds)
                    es.best.update([x], None, [func(x, *args)], 1)
                    es.countevals += 1

            opts = es.opts  # processed options, unambiguous

            append = opts['verb_append'] or es.countiter > 0 or irun > 0
            logger = CMADataLogger(opts['verb_filenameprefix'], opts['verb_log'])
            logger.register(es, append).add()  # initial values, not fitness values

            # if es.countiter == 0 and es.opts['verb_log'] > 0 and not es.opts['verb_append']:
            #    logger = CMADataLogger(es.opts['verb_filenameprefix']).register(es)
            #    logger.add()
            # es.writeOutput()  # initial values for sigma etc

            noisehandler = NoiseHandler(es.N, noise_handling, np.median, opts['noise_reevals'], opts['noise_eps'], opts['eval_parallel'])
            while not es.stop():
                X, fit = es.ask_and_eval(func, args, evaluations=noisehandler.evaluations,
                                         aggregation=np.median) # treats NaN with resampling
                # TODO: check args and in case use args=(noisehandler.evaluations, )

                if 11 < 3 and opts['vv']:  # inject a solution
                    # use option check_point = [0]
                    if 0 * np.random.randn() >= 0:
                        X[0] = 0 + opts['vv'] * es.sigma**0 * np.random.randn(es.N)
                        fit[0] = func(X[0], *args)
                        # print fit[0]
                es.tell(X, fit)  # prepare for next iteration
                if noise_handling:
                    es.sigma *= noisehandler(X, fit, func, es.ask, args)**opts['noise_change_sigma']
                    es.countevals += noisehandler.evaluations_just_done  # TODO: this is a hack, not important though

                es.disp()
                logger.add(more_data=[noisehandler.evaluations, 10**noisehandler.noiseS] if noise_handling else [],
                           modulo=1 if es.stop() and logger.modulo else None)
                if opts['verb_log'] and opts['verb_plot'] and \
                    (es.countiter % max(opts['verb_plot'], opts['verb_log']) == 0 or es.stop()):
                    logger.plot(324, fontsize=10)

            # end while not es.stop
            mean_pheno = es.gp.pheno(es.mean, bounds=es.gp.bounds)
            fmean = func(mean_pheno, *args)
            es.countevals += 1

            es.best.update([mean_pheno], None, [fmean], es.countevals)
            best.update(es.best)  # in restarted case

            # final message
            if opts['verb_disp']:
                srestarts = (' after %i restart' + ('s' if irun > 1 else '')) % irun if irun else ''
                for k, v in list(es.stop().items()):
                    print('termination on %s=%s%s (%s)' % (k, str(v), srestarts, time.asctime()))

                print('final/bestever f-value = %e %e' % (es.best.last.f, best.f))
                if es.N < 9:
                    print('mean solution: ' + str(es.gp.pheno(es.mean)))
                    print('std deviation: ' + str(es.sigma * sqrt(es.dC) * es.gp.scales))
                else:
                    print('mean solution: %s ...]' % (str(es.gp.pheno(es.mean)[:8])[:-1]))
                    print('std deviations: %s ...]' % (str((es.sigma * sqrt(es.dC) * es.gp.scales)[:8])[:-1]))

            irun += 1
            if irun > restarts or 'ftarget' in es.stopdict or 'maxfunevals' in es.stopdict:
                break
            opts['verb_append'] = es.countevals
            opts['popsize'] = incpopsize * es.sp.popsize # TODO: use rather options?
            opts['seed'] += 1

        # while irun

        es.out['best'] = best  # TODO: this is a rather suboptimal type for inspection in the shell
        if 1 < 3:
            return es.result() + (es.stop(), es, logger)

        else: # previously: to be removed
            return (best.x.copy(), best.f, es.countevals,
                    dict((('stopdict', CMAStopDict(es.stopdict))
                          ,('mean', es.gp.pheno(es.mean))
                          ,('std', es.sigma * sqrt(es.dC) * es.gp.scales)
                          ,('out', es.out)
                          ,('opts', es.opts)  # last state of options
                          ,('cma', es)
                          ,('inputargs', es.inputargs)
                          ))
                   )
        # TODO refine output, can #args be flexible?
        # is this well usable as it is now?
    except KeyboardInterrupt:  # Exception, e:
        if opts['verb_disp'] > 0:
            print(' in/outcomment ``raise`` in last line of cma.fmin to prevent/restore KeyboardInterrupt exception')
        raise  # cave: swallowing this exception can silently mess up experiments, if ctrl-C is hit
def fmin ( func , x0 , sigma0 = None , args = ( ) # the follow string arguments are evaluated, besides the verb_filenameprefix , CMA_active = 'False  # exponential negative update, conducted after the original update' , CMA_activefac = '1  # learning rate multiplier for active update' , CMA_cmean = '1  # learning rate for the mean value' , CMA_const_trace = 'False  # normalize trace, value CMA_const_trace=2 normalizes sum log eigenvalues to zero' , CMA_diagonal = '0*100*N/sqrt(popsize)  # nb of iterations with diagonal covariance matrix, True for always' # TODO 4/ccov_separable? , CMA_eigenmethod = 'np.linalg.eigh  # 0=numpy-s eigh, -1=pygsl, otherwise cma.Misc.eig (slower)' , CMA_elitist = 'False # elitism likely impairs global search performance' , CMA_mirrors = 'popsize < 6  # values <0.5 are interpreted as fraction, values >1 as numbers (rounded), otherwise about 0.16 is used' , CMA_mu = 'None  # parents selection parameter, default is popsize // 2' , CMA_on = 'True  # False or 0 for no adaptation of the covariance matrix' , CMA_rankmu = 'True  # False or 0 for omitting rank-mu update of covariance matrix' , CMA_rankmualpha = '0.3  # factor of rank-mu update if mu=1, subject to removal, default might change to 0.0' , CMA_dampfac = '1  #v positive multiplier for step-size damping, 0.3 is close to optimal on the sphere' , CMA_dampsvec_fac = 'np.Inf  # tentative and subject to changes, 0.5 would be a "default" damping for sigma vector update' , CMA_dampsvec_fade = '0.1  # tentative fading out parameter for sigma vector update' , CMA_teststds = 'None  # factors for non-isotropic initial distr. mainly for test purpose, see scaling_...' , CMA_AII = 'False  # not yet tested' , bounds = '[None, None]  # lower (=bounds[0]) and upper domain boundaries, each a scalar or a list/vector' , eval_parallel = 'False  # when True, func might be called with more than one solution as first argument' , eval_initial_x = 'False  # ' , fixed_variables = 'None  # dictionary with index-value pairs like {0:1.1, 2:0.1} that are not optimized' , ftarget = '-inf  #v target function value, minimization' , incpopsize = '2  # in fmin(): multiplier for increasing popsize before each restart' , maxfevals = 'inf  #v maximum number of function evaluations' , maxiter = '100 + 50 * (N+3)**2 // popsize**0.5  #v maximum number of iterations' , mindx = '0  #v minimal std in any direction, cave interference with tol*' , minstd = '0  #v minimal std in any coordinate direction, cave interference with tol*' , noise_handling = 'False  # maximal number of evaluations for noise treatment, only fmin' , noise_reevals = ' 1.5 + popsize/20  # number of solution to be reevaluated for noise measurement, only fmin' , noise_eps = '1e-7  # perturbation factor for noise handling reevaluations, only fmin' , noise_change_sigma = 'True  # exponent to default sigma increment' , popsize = '4+int(3*log(N))  # population size, AKA lambda, number of new solution per iteration' , randn = 'np.random.standard_normal  #v randn((lam, N)) must return an np.array of shape (lam, N)' , restarts = '0  # in fmin(): number of restarts' , restart_from_best = 'False' , scaling_of_variables = 'None  # scale for each variable, sigma0 is interpreted w.r.t. this scale, in that effective_sigma0 = sigma0*scaling. Internally the variables are divided by scaling_of_variables and sigma is unchanged, default is ones(N)' , seed = 'None  # random number seed' , termination_callback = 'None  #v a function returning True for termination, called after each iteration step and could be abused for side effects' , tolfacupx = '1e3  #v termination when step-size increases by tolfacupx (diverges). That is, the initial step-size was chosen far too small and better solutions were found far away from the initial solution x0' , tolupsigma = '1e20  #v sigma/sigma0 > tolupsigma * max(sqrt(eivenvals(C))) indicates "creeping behavior" with usually minor improvements' , tolfun = '1e-11  #v termination criterion: tolerance in function value, quite useful' , tolfunhist = '1e-12  #v termination criterion: tolerance in function value history' , tolstagnation = 'int(100 + 100 * N**1.5 / popsize)  #v termination if no improvement over tolstagnation iterations' , tolx = '1e-11  #v termination criterion: tolerance in x-changes' , transformation = 'None  # [t0, t1] are two mappings, t0 transforms solutions from CMA-representation to f-representation (tf_pheno), t1 is the (optional) back transformation, see class GenoPheno' , typical_x = 'None  # used with scaling_of_variables' , updatecovwait = 'None  #v number of iterations without distribution update, name is subject to future changes' # TODO: rename: iterwaitupdatedistribution? , verb_append = '0  # initial evaluation counter, if append, do not overwrite output files' , verb_disp = '100  #v verbosity: display console output every verb_disp iteration' , verb_filenameprefix = 'outcmaes  # output filenames prefix' , verb_log = '1  #v verbosity: write data to files every verb_log iteration, writing can be time critical on fast to evaluate functions' , verb_plot = '0  #v in fmin(): plot() is called every verb_plot iteration' , verb_time = 'True  #v output timings on console' , vv = '0  #? versatile variable for hacking purposes, value found in self.opts[\'vv\']' ) : # style guides say there should be the above empty line try : # pass on KeyboardInterrupt opts = locals ( ) # collect all local variables (i.e. arguments) in a dictionary del opts [ 'func' ] # remove those without a default value del opts [ 'args' ] del opts [ 'x0' ] # is not optional, no default available del opts [ 'sigma0' ] # is not optional for the constructor CMAEvolutionStrategy if not func : # return available options in a dictionary return Options ( opts , True ) # these opts are by definition valid # TODO: this is very ugly: incpopsize = Options ( { 'incpopsize' : incpopsize } ) . eval ( 'incpopsize' ) restarts = Options ( { 'restarts' : restarts } ) . eval ( 'restarts' ) del opts [ 'restarts' ] noise_handling = Options ( { 'noise_handling' : noise_handling } ) . eval ( 'noise_handling' ) del opts [ 'noise_handling' ] # otherwise CMA throws an error irun = 0 best = BestSolution ( ) while 1 : # recover from a CMA object if irun == 0 and isinstance ( x0 , CMAEvolutionStrategy ) : es = x0 x0 = es . inputargs [ 'x0' ] # for the next restarts if sigma0 is None or not np . isscalar ( array ( sigma0 ) ) : sigma0 = es . inputargs [ 'sigma0' ] # for the next restarts # ignore further input args and keep original options else : # default case if irun and opts [ 'restart_from_best' ] : print ( 'CAVE: restart_from_best is typically not useful' ) es = CMAEvolutionStrategy ( best . x , sigma0 , opts ) else : es = CMAEvolutionStrategy ( x0 , sigma0 , opts ) if opts [ 'eval_initial_x' ] : x = es . gp . pheno ( es . mean , bounds = es . gp . bounds ) es . best . update ( [ x ] , None , [ func ( x , * args ) ] , 1 ) es . countevals += 1 opts = es . opts # processed options, unambiguous append = opts [ 'verb_append' ] or es . countiter > 0 or irun > 0 logger = CMADataLogger ( opts [ 'verb_filenameprefix' ] , opts [ 'verb_log' ] ) logger . register ( es , append ) . add ( ) # initial values, not fitness values # if es.countiter == 0 and es.opts['verb_log'] > 0 and not es.opts['verb_append']: #    logger = CMADataLogger(es.opts['verb_filenameprefix']).register(es) #    logger.add() # es.writeOutput()  # initial values for sigma etc noisehandler = NoiseHandler ( es . N , noise_handling , np . median , opts [ 'noise_reevals' ] , opts [ 'noise_eps' ] , opts [ 'eval_parallel' ] ) while not es . stop ( ) : X , fit = es . ask_and_eval ( func , args , evaluations = noisehandler . evaluations , aggregation = np . median ) # treats NaN with resampling # TODO: check args and in case use args=(noisehandler.evaluations, ) if 11 < 3 and opts [ 'vv' ] : # inject a solution # use option check_point = [0] if 0 * np . random . randn ( ) >= 0 : X [ 0 ] = 0 + opts [ 'vv' ] * es . sigma ** 0 * np . random . randn ( es . N ) fit [ 0 ] = func ( X [ 0 ] , * args ) # print fit[0] es . tell ( X , fit ) # prepare for next iteration if noise_handling : es . sigma *= noisehandler ( X , fit , func , es . ask , args ) ** opts [ 'noise_change_sigma' ] es . countevals += noisehandler . evaluations_just_done # TODO: this is a hack, not important though es . disp ( ) logger . add ( more_data = [ noisehandler . evaluations , 10 ** noisehandler . noiseS ] if noise_handling else [ ] , modulo = 1 if es . stop ( ) and logger . modulo else None ) if opts [ 'verb_log' ] and opts [ 'verb_plot' ] and ( es . countiter % max ( opts [ 'verb_plot' ] , opts [ 'verb_log' ] ) == 0 or es . stop ( ) ) : logger . plot ( 324 , fontsize = 10 ) # end while not es.stop mean_pheno = es . gp . pheno ( es . mean , bounds = es . gp . bounds ) fmean = func ( mean_pheno , * args ) es . countevals += 1 es . best . update ( [ mean_pheno ] , None , [ fmean ] , es . countevals ) best . update ( es . best ) # in restarted case # final message if opts [ 'verb_disp' ] : srestarts = ( ' after %i restart' + ( 's' if irun > 1 else '' ) ) % irun if irun else '' for k , v in list ( es . stop ( ) . items ( ) ) : print ( 'termination on %s=%s%s (%s)' % ( k , str ( v ) , srestarts , time . asctime ( ) ) ) print ( 'final/bestever f-value = %e %e' % ( es . best . last . f , best . f ) ) if es . N < 9 : print ( 'mean solution: ' + str ( es . gp . pheno ( es . mean ) ) ) print ( 'std deviation: ' + str ( es . sigma * sqrt ( es . dC ) * es . gp . scales ) ) else : print ( 'mean solution: %s ...]' % ( str ( es . gp . pheno ( es . mean ) [ : 8 ] ) [ : - 1 ] ) ) print ( 'std deviations: %s ...]' % ( str ( ( es . sigma * sqrt ( es . dC ) * es . gp . scales ) [ : 8 ] ) [ : - 1 ] ) ) irun += 1 if irun > restarts or 'ftarget' in es . stopdict or 'maxfunevals' in es . stopdict : break opts [ 'verb_append' ] = es . countevals opts [ 'popsize' ] = incpopsize * es . sp . popsize # TODO: use rather options? opts [ 'seed' ] += 1 # while irun es . out [ 'best' ] = best # TODO: this is a rather suboptimal type for inspection in the shell if 1 < 3 : return es . result ( ) + ( es . stop ( ) , es , logger ) else : # previously: to be removed return ( best . x . copy ( ) , best . f , es . countevals , dict ( ( ( 'stopdict' , CMAStopDict ( es . stopdict ) ) , ( 'mean' , es . gp . pheno ( es . mean ) ) , ( 'std' , es . sigma * sqrt ( es . dC ) * es . gp . scales ) , ( 'out' , es . out ) , ( 'opts' , es . opts ) # last state of options , ( 'cma' , es ) , ( 'inputargs' , es . inputargs ) ) ) ) # TODO refine output, can #args be flexible? # is this well usable as it is now? except KeyboardInterrupt : # Exception, e: if opts [ 'verb_disp' ] > 0 : print ( ' in/outcomment ``raise`` in last line of cma.fmin to prevent/restore KeyboardInterrupt exception' ) raise # cave: swallowing this exception can silently mess up experiments, if ctrl-C is hit