
    J-j                        d Z ddlmZ ddlmZ dZdZddlmZ ddl	Z
ddlmZmZ dd	lmZ 	 d
dlmZmZ 	 d
dlmZ [[dZdZdZ	 	 	 d'dZ G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de#      Z$ G d de$      Z%d Z&d(dZ'd  Z(d! Z)d" Z*d)d#Z+d$ Z,d% Z-e.d&k(  r e-        yy# eef$ r eecZZY w xY w# eef$ r dZY w xY w)*a  A minimalistic implemention of CMA-ES without using `numpy`.

The Covariance Matrix Adaptation Evolution Strategy, CMA-ES, serves for
numerical nonlinear function minimization.

The **main functionality** is implemented in

1. class `CMAES`, and

2. function `fmin` which is a small single-line-usage wrapper around
   `CMAES`.

This code has two **purposes**:

1. for READING and UNDERSTANDING the basic flow and the details of the
   CMA-ES *algorithm*. The source code is meant to be read. For a quick
   glance, study the first few code lines of `fmin` and the code of
   method `CMAES.tell`, where all the real work is done in about 20 lines
   of code (search "def tell" in the source). Otherwise, reading from
   the top is a feasible option, where the codes of `fmin`,
   `CMAES.__init__`, `CMAES.ask`, `CMAES.tell` are of particular
   interest.

2. apply CMA-ES when the python module `numpy` is not available.
   When `numpy` is available, `cma.fmin` or `cma.CMAEvolutionStrategy` are
   preferred to run "serious" simulations. The latter code has many more
   lines, but usually executes faster, offers a richer user interface,
   better termination options, boundary and noise handling, injection,
   automated restarts...

Dependencies: `math.exp`, `math.log` and `random.normalvariate` (modules
`matplotlib.pylab` and `sys` are optional).

Testing: call ``python purecma.py`` at the OS shell. Tested with
Python 2.6, 2.7, 3.3, 3.5, 3.6.

URL: http://github.com/CMA-ES/pycma

Last change: September, 2017, version 3.0.0

:Author: Nikolaus Hansen, 2010-2011, 2017

This code is released into the public domain (that is, you may
use and modify it however you like).

    )division)print_functionzNikolaus Hansenzpublic domain)stdoutN)logexp)normalvariate   )OOOptimizerBaseDataLogger)RecombinationWeightsz3.0.0reStructuredTextc	                 6   t        ||||      }	|r!t        |      j                  |	d      |	_        |	j	                         s|	j                         }
|
D cg c]  } | |g|  }}|	j                  |
|       |	j                  |       |r|	j                  |	j                  j                  z  |z  dk  r|	j                  j                  |	       |rF|	j                  |	j                  j                  z  ||z  z  dk  r|	j                  j                          |	j	                         s|r]|	j                  d       t        d|	j	                                t        d|	j                  d          t        d|	j                  d          |r;|	j                  j                  |	d       |r|	j                  j                         nd	 |	j                  j                   | |	j                         k  r|	j                  j"                  |	gS |	j                   |	gS c c}w )
a  non-linear non-convex minimization procedure, a functional
    interface to CMA-ES.

    Parameters
    ==========
        `objective_fct`: `callable`
            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 ``objective_fct(x)``
            to be as small as possible.
        `xstart`: `list` or sequence
            list of numbers (like `[3.2, 2, 1]`), initial solution vector,
            its length defines the search space dimension.
        `sigma`: `float`
            initial step-size, standard deviation in any coordinate
        `args`: `tuple` or sequence
            additional (optional) arguments passed to `objective_fct`
        `ftarget`: `float`
            target function value
        `maxfevals`: `int` or `str`
            maximal number of function evaluations, a string
            is evaluated with ``N`` as 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_save`: `int`
            save logged data every ``verb_save * verb_log`` iteration

    Return
    ======
    The `tuple` (``xmin``:`list`, ``es``:`CMAES`), where ``xmin`` is the
    best seen (evaluated) solution and ``es`` is the correspoding `CMAES`
    instance. Consult ``help(es.result)`` of property `result` for further
    results.

    Example
    =======
    The following example minimizes the function `ff.elli`:

    >>> try: from cma import purecma
    ... except ImportError: import purecma
    >>> def felli(x):
    ...     return sum(10**(6 * i / (len(x)-1)) * xi**2
    ...                for i, xi in enumerate(x))
    >>> x, es = purecma.fmin(felli, 3 * [0.5], 0.3, verb_disp=100)  # doctest:+SKIP
    evals: ax-ratio max(std)   f-value
        7:     1.0  3.4e-01  240.2716966
       14:     1.0  3.9e-01  2341.50170536
      700:   247.9  2.4e-01  0.629102574062
     1400:  1185.9  5.3e-07  4.83466373808e-13
     1421:  1131.2  2.9e-07  5.50167024417e-14
    termination by {'tolfun': 1e-12}
    best f-value = 2.72976881789e-14
    solution = [5.284564665206811e-08, 2.4608091035303e-09, -1.3582873173543187e-10]
    >>> print(x)  # doctest:+SKIP
    [5.284564665206811e-08, 2.4608091035303e-09, -1.3582873173543187e-10]
    >>> es.result[1]  # doctest:+SKIP
    2.72976881789e-14
    >>> es.logger.plot()  # doctest:+SKIP

    Details
    =======
    After importing `purecma`, this call:

    >>> es = purecma.fmin(pcma.ff.elli, 10 * [0.5], 0.3, verb_save=0)[1]  # doctest:+SKIP

    and these lines:

    >>> es = purecma.CMAES(10 * [0.5], 0.3)
    >>> es.optimize(purecma.ff.elli, callback=es.logger.add)  # doctest:+SKIP

    do pretty much the same. The `verb_save` parameter to `fmin` adds
    the possibility to plot the saved data *during* the execution from a
    different Python shell like ``pcma.CMAESDataLogger().load().plot()``.
    For example, with ``verb_save == 3`` every third time the logger
    records data they are saved to disk as well.

    :See: `CMAES`, `OOOptimizer`.
)	maxfevalsftargetT)forcer	   ztermination byzbest f-value =z
solution =r   N)CMAESCMAESDataLoggeraddloggerstopasktelldisp	countevalparamslamsaveprintresultbestfxmeanx)objective_fctxstartsigmaargsr   r   	verb_dispverb_log	verb_saveesXr#   fits                i/Users/jameslopez/projects/TradingBot25/.venv/lib/python3.12/site-packages/cma/more_algorithms/purecma.pyfminr/   I   s   h 
vu	7	CB#H-11"D1A	ggiFFH0121}Q&&2
3 		||biimm+h6:		b!bllRYY]]:!*X!579:;		  ggi 

	*		!-lBIIaL)
		b%%		4]288%<<BGGII HHb ) 3s   Hc                        e Zd ZdZdZ	 	 ddZy)CMAESParametersz5static "internal" parameter setting for `CMAES`

    z4 + int(3 * log(N))Nc           	         || _         |dz  ddd|z  z  z
  dd|dz  z  z  z   z  | _        t        t        |r|nt        j
                  dd|d	            | _        t        | j                  dz        | _        |r3 || j                        | _	        | j                  j                  | _
        nt        | j                        D cg c]=  }|| j                  k  r*t        | j                  dz  dz         t        |dz         z
  nd
? }}t        |d| j                         }|D cg c]  }||z  	 c}| _	        t        | j                  d| j                         dz  t        d | j                  d| j                   D              z  | _
        d| j                  |z  z   |dz   d| j                  z  |z  z   z  | _        | j                  dz   || j                  z   dz   z  | _        d|dz   dz  | j                  z   z  | _        t#        d| j                   z
  d| j                  dz
  d| j                  z  z   z  |dz   dz  | j                  z   z  g      | _        d| j                  z  | j                  z  dz   | j                  z   | _        |r1| j                  j)                  || j                   | j$                         d|z  | j                  z  | j                   | j$                  z   dz  z  |dz  z  | _        yc c}w c c}w )zset static, fixed "strategy" parameters once and for all.

        Input parameter ``RecombinationWeights`` may be set to the class
        `RecombinationWeights`.
              ?r	         ?         intr   )r8   r   Nr   Nc              3   &   K   | ]	  }|d z    ywr7   N ).0ws     r.   	<genexpr>z+CMAESParameters.__init__.<locals>.<genexpr>   s     B+AaQT+A      g?333333?)	dimensionchiNevalsafe_strr1   default_popsizer   r8   muweightsmueffranger   sumcccsc1mincmudampsfinalize_negative_weightslazy_gap_evals)selfr9   popsizer   i_weightsw_sumr>   s           r.   __init__zCMAESParameters.__init__   s    sFa"A,.rAqDy1AAB	 G!0!@!@).u1!EG H dhhl#/9DL++DJ "'txx2!0A ABDGGDHHqL3./#a!e*<QRR!0  2$''*+E/78x!AIx8DLT\\(47734a7B4<<+ABBCDJ tzz!|#!a$**nQ.>(>?::>a$**nq&89C!|djj01DGGQ$**q.1TZZ<*G%HQQRUUVJY]YcYcLc%def^DHH,s2TWW<
LL221dggtxxH "Ag0DGGdhh4F3KKaQRdR%2 9s   AK3#K8)NN)__name__
__module____qualname____doc__rH   r[   r<       r.   r1   r1      s     ,O"&&*%Sr`   r1   c                   ^    e Zd ZdZej
                  ddefdZd Zd Z	d Z
ed        Zd
d	Zy)r   a/
  class for non-linear non-convex numerical minimization with CMA-ES.

    The class implements the interface define in `OOOptimizer`, namely
    the methods `__init__`, `ask`, `tell`, `stop`, `disp` and property
    `result`.

    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`.

    Details
    -------
    Most of the work is done in the method `tell`. The property
    `result` contains more useful output.

    :See: `fmin`, `OOOptimizer.optimize`

    Nz/100 * popsize + 150 * (N + 3)**2 * popsize**0.5c                    t        |      }t        ||      | _        t        t	        ||| j                  j
                  d            | _        || _        || _        |dd | _	        || _
        |dgz  | _        |dgz  | _        t        |      | _        d| _        g | _        t#               | _        t'               | _        y)a  Instantiate `CMAES` object instance using `xstart` and `sigma`.

        Parameters
        ----------
            `xstart`: `list`
                of numbers (like ``[3, 2, 1.2]``), initial
                solution vector
            `sigma`: `float`
                initial step-size (standard deviation in each coordinate)
            `popsize`: `int` or `str`
                population size, number of candidate samples per iteration
            `maxfevals`: `int` or `str`
                maximal number of function evaluations, a string is
                evaluated with ``N`` as search space dimension
            `ftarget`: `float`
                target function value
            `randn`: `callable`
                normal random number generator, by default
                `random.normalvariate`

        Details: this method initializes the dynamic state variables and
        creates a `CMAESParameters` instance for static parameters.
        )r9   rW   )known_wordsNr   )lenr1   r   rF   rG   r   r   r   randnr"   r&   pcpsDecomposingPositiveMatrixCr   fitvalsBestSolutionr    r   r   )rV   r%   r&   rW   r   r   re   r9   s           r.   r[   zCMAES.__init__.  s    < K%a1hy9:t{{3WY Z
 AY

qc'qc'*1- N	%'r`   c           	         | j                   j                  | j                  | j                  j                         g }t        | j                  j                        D ]  }| j                   j                  D cg c]'  }| j                  |dz  z  | j                  dd      z  ) }}t        | j                   j                  |      }|j                  t        | j                  |              |S c c}w )a  sample lambda candidate solutions

        distributed according to::

            m + sigma * Normal(0,C) = m + sigma * B * D * Normal(0,I)
                                    = m + B * D * sigma * Normal(0,I)

        and return a `list` of the sampled "vectors".
        r3   r   r	   )ri   update_eigensystemr   r   rU   rL   r   eigenvaluesr&   re   dot
eigenbasisappendplusr"   )rV   candidate_solutions_keigenvalzys         r.   r   z	CMAES.ask^  s     	!!$.."&++"<"<	> (B!%!3!35!3X hm+djjA.>>!3  5DFF%%q)A&&tDJJ':;	 )
 #"	5s   7,C.c           
      `   | xj                   t        |      z  c_         t        | j                        }| j                  }| j                  }t	        |      D cg c]  }||   	 }}t        |      | _        | j                  j                  |d   | j                  d   | j                          t        |d|j                   |j                  d|j                   d      | _        t        | j                  |      }t        | j                  j                  |      }|j                  d|j                  z
  z  |j                   z  dz  | j"                  z  }	t%        |      D ]7  }
d|j                  z
  | j&                  |
   z  |	||
   z  z   | j&                  |
<   9 |j(                  d|j(                  z
  z  |j                   z  dz  | j"                  z  }t+        d | j&                  D              |z  dd|j                  z
  d| j                   z  |j,                  z  z  z
  z  dd	|dz   z  z   k  }t%        |      D ]:  }
d|j(                  z
  | j.                  |
   z  ||z  ||
   z  z   | j.                  |
<   < |j0                  dd|dz  z
  |j(                  z  d|j(                  z
  z  z
  z  }| j                  j3                  d|z
  |j4                  t+        |j                        z  z
         | j                  j7                  | j.                  |j0                         t9        |j                        D ]  \  }}|dk  r>||| j"                  | j                  j;                  t        ||   |            z  dz  z  z  }| j                  j7                  t        ||   |      ||j4                  z  | j"                  dz  z          |j                  |j<                  z  t+        d
 | j&                  D              }}| xj"                  t?        tA        d|||z  dz
  z  dz              z  c_        yc c}w )a  update the evolution paths and the distribution parameters m,
        sigma, and C within CMA-ES.

        Parameters
        ----------
            `arx`: `list` of "row vectors"
                a list of candidate solution vectors, presumably from
                calling `ask`. ``arx[k][i]`` is the i-th element of
                solution vector k.
            `fitvals`: `list`
                the corresponding objective function values, to be
                minimised
        r   NT)	transposer7   r3   r	   c              3   &   K   | ]	  }|d z    ywr;   r<   r=   r#   s     r.   r?   zCMAES.tell.<locals>.<genexpr>  s     *'QAqD'r@   g      @c              3   &   K   | ]	  }|d z    ywr;   r<   r{   s     r.   r?   zCMAES.tell.<locals>.<genexpr>  s     3J'QAqD'r@   )!r   rd   r"   r   argsortsortedrj   r    updatero   rI   rJ   minusri   invsqrtrO   rK   r&   rL   rg   rN   rM   r   rf   rP   multiply_withrR   addouter	enumeratemahalanobis_normrS   r   rQ   )rV   arxrj   r9   parxoldkrw   rv   csnrX   ccnhsigc1awkcnsum_square_pss                    r.   r   z
CMAES.tellr  sl    	#g,&

Okkzz  'w/0/!s1v/0g		Qa$..A QsvvGSVV(<M

 $**d#"vvSVV$syy036CqAcff*
2S1Q4Z?DGGAJ vvSVV$syy036C*$''**Q.ah!DNN"2377":;;=b!A#h, qAcff*
2S4Z!A$5FFDGGAJ 
 ffQtQwY#&&0AcffH==>QWswwS[[1A'AAB(s{{+EArAva4::(?(?c!fd@S(TTWXXXXFFOOE#a&$/L4::q=8: ,  FFSYY.3J$''3J0JM

c#a}q'81'<!=!ABCC
I 1s   P+c                 j   i }| j                   dk  r|S | j                   | j                  k\  r| j                  |d<   | j                  Ct        | j                        dkD  r+| j                  d   | j                  k  r| j                  |d<   | j
                  j                  dkD  r| j
                  j                  |d<   t        | j                        dkD  r'| j                  d   | j                  d   z
  dk  rd|d	<   | j                  t        | j
                  j                        d
z  z  dk  rd|d<   |S )zreturn satisfied termination conditions in a dictionary,

        generally speaking like ``{'termination_reason':value, ...}``,
        for example ``{'tolfun':1e-12}``, or the empty `dict` ``{}``.
        r   r   r   g  ļB	conditionr	   rC   g-q=tolfunr3   gdy=tolx)
r   r   r   rd   rj   ri   condition_numberr&   maxrn   )rV   ress     r.   r   z
CMAES.stop  s    >>QJ>>T^^+#~~C<<#DLL(9A(=LLOt||3!\\C	N66""T)#vv66Ct||q LL$t||A6>!CM::DFF../44u<CK
r`   c                 v   | j                   j                  | j                   j                  | j                   j                  | j                  t        | j                  | j                  j                  z        | j                  | j                  j                  D cg c]  }| j                  |dz  z   c}fS c c}w )zkthe `tuple` ``(xbest, f(xbest), evaluations_xbest, evaluations,
        iterations, xmean, stds)``
        r3   )r    r#   r!   evalsr   r8   r   r   r"   ri   diagr&   )rV   C_iis     r.   r   zCMAES.result  s    
 						DNNT[[__45

48FFKK@KDdCi'K@B 	B As   B6c           	         |d}|sy| j                   | j                  j                  z  }|dk(  s|d|z  z  dk  rt        d       |dk  s||z  dk  rt        t	        | j                         j                  d      dz   d	| j                  j                  d
z  | j                  t        | j                  j                        d
z  z  fz  z   t	        | j                  d         z          t        j                          yy)z0`print` some iteration info to `stdout`
        N   r	   
   z"evals: ax-ratio max(std)   f-valuer7   rA   z: z %6.1f %8.1e  r3   r   )r   r   r   r   strrjustri   r   r&   r   r   rj   _stdoutflush)rV   verb_modulo	iterations      r.   r   z
CMAES.disp  s     KNNT[[__4	>Y"{*:;a?67>Y4q8#dnn%++A.5"dff&=&=s&B&*jj3tvv{{3CS3H&H&J JJ dll1o&' ( MMO 9r`   r	   )r\   r]   r^   r_   r1   rH   random_normalvariater[   r   r   r   propertyr   r   r<   r`   r.   r   r      sQ    FP )88=+.(`#(9Dx0 
B 
Br`   r   c                   >    e Zd ZdZdZ	 d	dZd
dZddZddZddZ	y)r   a  data logger for class `CMAES`, that can record and plot data.

    Examples
    ========

    The data may come from `fmin` or `CMAES` and the simulation may
    still be running in a different Python shell.

    Use the default logger from `CMAES`:

    >>> try: from cma import purecma as pcma
    ... except ImportError: import purecma as pcma
    >>> es = pcma.CMAES(3 * [0.1], 1)
    >>> isinstance(es.logger, pcma.CMAESDataLogger)  # type(es.logger)
    True
    >>> while not es.stop():
    ...     X = es.ask()
    ...     es.tell(X, [pcma.ff.elli(x) for x in X])
    ...     es.logger.add(es)  # doctest: +SKIP
    >>> es.logger.save()
    >>> # es.logger.plot()  #

    Load and plot previously generated data:

    >>> logger = pcma.CMAESDataLogger().load()
    >>> logger.filename == "_CMAESDataLogger_datadict.py"
    True

    >>> # logger.plot()

    TODO: the recorded data are kept in memory and keep growing, which
    may well lead to performance issues for (very?) long runs. Ideally,
    it should be possible to dump data to a file and clear the memory and
    also to downsample data to prevent plotting of long runs to take
    forever. ``"], 'key': "`` or ``"]}"`` is the place where to
    prepend/append new data in the file.
r   c           	      \    d| _         d| _        || _        g g g g g g g g d| _        d| _        y)zo`verb_modulo` controls whether and when logging takes place
        for each call to the method `add`

        z_CMAESDataLogger_datadict.pyN)rF   iterstdsDr&   r-   r"   	more_datar   )filenameoptimmodulo_datacounter)rV   r   s     r.   r[   zCMAESDataLogger.__init__  s<     7
! "br!"rL
r`   Nc                    |xs | j                   }t        |t              st        dt	        |      z        | j
                  }| xj                  dz  c_        |r| j                  dk(  rd| _        | j                  rt        |d         dk(  s|j                  |d   d   k7  r| j                  dk  s(|s&t        | j                        | j                  z  dk(  rw|d   j                  |j                         |d   j                  |j                  |j                  j                  z         |d   j                  t        t        |j                              D cg c]  }|j                  |   |   d	z   c}       |d
   j                  t!        d |j                  j"                  D                     |d   j                  |j$                         |d   j                  t'        |d      r|j(                  r|j(                  d   nd       |d   j                  |j*                  D cg c]  }| c}       ||d   j                  |       | S c c}w c c}w )zappend some logging data from CMAES class instance `es`,
        if ``number_of_times_called modulo verb_modulo`` equals zero
        z.logged object must be a CMAES instance, was %sr	   r   rF   rC   r5   r   r   r3   r   c              3   &   K   | ]	  }|d z    ywr3   Nr<   )r=   evs     r.   r?   z&CMAESDataLogger.add.<locals>.<genexpr>3  s     "F5Er2s75Er@   r&   r-   rj   Nr"   r   )r   
isinstancer   RuntimeWarningtyper   r   r   rd   r   r8   rq   r   r   rL   ri   r~   rn   r&   hasattrrj   r"   )rV   r+   r   r   datrX   r#   s          r.   r   zCMAESDataLogger.add  s    4::"e$  "+-1"X"6 7 7jjT\\Q&DLKKV%*FB7\\A%DLL)DKK71<Kr||,Kr||biimm;<K).s244y)9 ;)9A !#Q
C)9 ; <HOOF"FRTT5E5E"FFGL)Jwr9/E"$** !jjm#') LBHH 5HqH 56$K ''	2 ; !6s   I-	Ic                    ddl m ddlm}m}m}m}m}m}m	}m
m}	m}
m}mm}mmm fd}fd}fd}fd}t'        |t(              r ||       | j*                  }|r|d   rt-        |d         d	k  ry
	 dt/        |d   d   |d   d   z
        z  } |d        |       j3                          |d   d   |d   d   |d   d<   |d   j5                  d
      dk(  sJ t7        |d         }|d   j9                  |      }t;        |d         dz   |d   |<   t7        |d         }||d   |<    ||d   |d   D cg c]  }||z
  dkD  r||z
  nd
 c}ddd        ||d   |d   D cg c]  }||z
  dk  rt;        ||z
  df      nd
 c}d        ||d   |d   D cg c]  }t=        |       c}dd        ||d   |d   dd        ||d   |   t=        |      dd       |d   r$ |       j?                           ||d   |d           |d         | |       jA                         D cg c]  }d!D cg c]  }||   	 c} c}}   |d"        |       j3                           ||d   |d#          tC        t-        |d#   d$               D ]F  } |d   d   |d#   d   |   t/        |              |d   d$   |d#   d$   |   t/        |             H  |d%        |d        |d&   d$   d   |d&   d$   d$   k7  rH |d'        |       j3                           ||d   |d&   d(        |d)|z           |d*        |d         |d+        |       j3                           ||d   |d,          tC        t-        |d,   d$               D ]$  } |d   d$   |d,   d$   |   t/        |             &  |d-        |d         |d)|z          tE        jF                           |         |         |
         |       jH                  j                          tJ        xjL                  dz  c_&        y
# t0        $ r d}Y w xY wc c}w c c}w c c}w c c}w c c}}w ).zbplot the stored data in figure `fig_number`.

        Dependencies: `matlabplotlib.pylab`
        r   )pylab)gcfgcafigureplotxlabelgridsemilogytextdrawshowionsubplottight_layoutrcParamsDefaultxlimylimc                  T    |j                  dd           j                  | i | y )Nsizezaxes.labelsize)
setdefaulttitler'   kwargsr   r   s     r.   title_z$CMAESDataLogger.plot.<locals>.title_G  s,    fo6F&GHEKK((r`   c                      |j                  dd        d        d           d   z
  z  d        d   z  g| i | y )Nhorizontalalignmentcenterr3   r	   r   g?)r   )r'   r   r   r   r   s     r.   subtitlez&CMAESDataLogger.plot.<locals>.subtitleJ  sP    3X>q	DF1I-.dfQi "" "r`   c                      |j                  dd       |j                  dd       |j                  dd   dz
          j                  | i | y )N
framealpharB   fancyboxTfontsizez	font.sizer7   )r   legendr   s     r.   legend_z%CMAESDataLogger.plot.<locals>.legend_N  sP    lC0j$/j/+*F*JKELL$)&)r`   c                      t        j                         5  t        j                  d        | i | d d d        y # 1 sw Y   y xY w)Nignore)	_warningscatch_warningssimplefilter)r'   r   _subplots     r.   r   z%CMAESDataLogger.plot.<locals>.subplotS  s6    ))+&&x0$)&) ,++s	   =ArF   r7   Nz (evaluations / %s)    r-   r	   r   gҶOɃ;czf-min(f))	linewidthlabelzC1*bzabs(f-value))r   r&   gzr*zabs(min(f))r   T)r	   r   r7         r"   rC   zmean solutionr      m
iterationszAxis lengths   r   zCoordinate-wise STDs w/o sigma)'
matplotlibr   matplotlib.pylabr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   r   rd   r   
IndexErrorclearcountrQ   indexr   abstwinxget_legend_handles_labelsrL   r   r   canvasr   plotted)rV   
fig_numberr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   
strpopsizer/   iminfmin2r!   vrX   r   r   r   r   r   r   s                            @@@@@@r.   r   zCMAESDataLogger.plot=  s   
 	%	 	 	 	 		)	"	*
	* j#&:jj#f+S[)9Q)>	.S[_58[_6E 2F FJ 	u:a= JqMCJqM5z%***3u:5z%s5z?Q.E
4CJE
4V(+E
4(21 ,-t8e+;q4xE(24	5 	V(+E
4(21 >?X=NsEDL%#89TXX(245:	< 	Vs5z:z!s1vz:C%	'Vc'lCw?VT"CIt=I{EKKMVc+./T
5::<><a "..A1Q4.<> 	? 	S[#g,'s3w<+,-AVQWa!3SV<VR#g,r"21"5s1v> . 	!T
 s8B<?c#hrl2..CLEKKMS[#c(C0<*,->"J 	
 	Vc&k*s3v;r?+,AVR#f+b/!"4c!f= -/0T
|j()1$O  	J	44 ; / >s<   Q Q
:!Q"
0Q'
	Q1
Q,Q1
QQ,Q1
c                     t        |xs | j                  d      5 }|j                  t        | j                               ddd       y# 1 sw Y   yxY w)z-save data to file `name` or ``self.filename``r>   N)openr   writereprr   )rV   namer!   s      r.   r   zCMAESDataLogger.save  s8    $'$---GGD$% .--s   %A		Ac                     ddl m} t        |xs | j                  d      5 } ||j	                               | _        ddd       | S # 1 sw Y   | S xY w)z/load data from file `name` or ``self.filename``r   )literal_evalrN)astr
  r  r   readr   )rV   r  r
  r!   s       r.   loadzCMAESDataLogger.load  sA    $$'$---%affh/DJ . .s   AAr   )NFN)iB  N)
r\   r]   r^   r_   r   r[   r   r   r   r  r<   r`   r.   r   r     s-    $L G&>j%X&
r`   r   c                   P    e Zd ZdZed        Zed        Zed        Zed        Zy)ffz8versatile collection of test functions in static methodsc                 `     t               dt         fdt              D              S )z!ellipsoid test objective functiong     @@c              3   L   K   | ]  }|   d z  d|z  dz
  z  z  z    yw)r7          @r	   Nr<   )r=   rX   arationr#   s     r.   r?   zff.elli.<locals>.<genexpr>  s0     D8a1Q47VbdAaCj118s   !$)rd   rM   rL   )r#   r  r  s   `@@r.   ellizff.elli  s(     FD58DDDr`   c                 P     t         fdt        t                     D              S )z.sphere, ``sum(x**2)``, test objective functionc              3   .   K   | ]  }|   d z    ywr;   r<   r=   rX   r#   s     r.   r?   zff.sphere.<locals>.<genexpr>  s     2Mq1Q47Ms   )rM   rL   rd   r#   s   `r.   spherez	ff.sphere  s     2E#a&M222r`   c                 >    t        d | D              d| d   dz  z  z   S )zdiscus test objective functionc              3   &   K   | ]	  }|d z    ywr;   r<   r=   xis     r.   r?   zff.tablet.<locals>.<genexpr>  s     %1R2q51r@   g    ~.Ar   r7   )rM   r  s    r.   tabletz	ff.tablet  s'     %1%%!A$'(999r`   c                 z     t               }|dk  rt        d      t         fdt        |dz
        D              S )z"Rosenbrock test objective functionr7   zdimension must be greater onec              3   d   K   | ]'  }d |   dz  |dz      z
  dz  z  |   dz
  dz  z    ) yw)d   r7   r	   Nr<   r  s     r.   r?   z ff.rosenbrock.<locals>.<genexpr>  sK      "  DE3!A$'AacF*Q..!A$(Q> s   -0r	   )rd   
ValueErrorrM   rL   )r#   r  s   ` r.   
rosenbrockzff.rosenbrock  sC     Fq5<== "AaCj" " 	"r`   N)	r\   r]   r^   r_   staticmethodr  r  r!  r&  r<   r`   r.   r  r    sU    BE E 3 3 : : " "r`   r  c                   0    e Zd ZdZddZddZed        Zy)rk   z1container to keep track of the best solution seenNc                 0    |||c| _         | _        | _        y)zCtake `x`, `f`, and `evals` to initialize the best solution
        Nr#   r!   r   rV   r#   r!   r   s       r.   r[   zBestSolution.__init__  s     &'5"
r`   c                 f    | j                   || j                   k  r|| _        || _         || _        | S )z3update the best solution if ``f < self.f``
        )r!   r#   r   r+  s       r.   r   zBestSolution.update  s1     66>QZDFDFDJr`   c                 H    | j                   | j                  | j                  fS )z+``(x, f, evals)`` of the best seen solutionr*  )rV   s    r.   allzBestSolution.all  s     vvtvvtzz))r`   )NNNr  )r\   r]   r^   r_   r[   r   r   r.  r<   r`   r.   rk   rk     s#    ;1
 * *r`   rk   c                   4    e Zd ZdZd Zd ZddZed        Zy)SquareMatrixzrudimental square matrix classc                 ^    t        |      D ]  }| j                  |dgz         d| |   |<   ! y)zinitialize with identity matrixr   r	   N)rL   rq   )rV   rD   rX   s      r.   r[   zSquareMatrix.__init__  s0    y!AKK	QC(DGAJ "r`   c                 `    | D ](  }t        t        |            D ]  }||xx   |z  cc<    * | S )z&multiply matrix in place with `factor`rL   rd   )rV   factorrowjs       r.   r   zSquareMatrix.multiply_with  s3    C3s8_A&  %  r`   c                     t        |       D ]7  \  }}t        t        |            D ]  }||xx   |||   z  ||   z  z  cc<    9 | S )zvAdd in place `factor` times outer product of vector `b`,

        without any dimensional consistency checks.
        )r   rL   rd   )rV   r   r4  rX   r5  r6  s         r.   r   zSquareMatrix.addouter  sN    
  oFAs3s8_A&1Q4-!A$.. % & r`   c                     t        t        |             D cg c]  }|t        | |         k  s| |   |    c}S c c}w )z:diagonal of the matrix as a copy (save to change)
        r3  )rV   rX   s     r.   r   zSquareMatrix.diag  s>     %*#d)$4I$4qCQL8HQ
$4IIIs   ;
;Nr   )	r\   r]   r^   r_   r[   r   r   r   r   r<   r`   r.   r0  r0    s*    ( J Jr`   r0  c                   (    e Zd ZdZd Zd Zd Zd Zy)rh   a  Symmetric matrix maintaining its own eigendecomposition.

    If ``isinstance(C, DecomposingPositiveMatrix)``,
    the eigendecomposion (the return value of `eig`) is stored in
    the attributes `eigenbasis` and `eigenvalues` such that the i-th
    eigenvector is::

        [row[i] for row in C.eigenbasis]  # or equivalently
        [C.eigenbasis[j][i] for j in range(len(C.eigenbasis))]

    with eigenvalue ``C.eigenvalues[i]`` and hence::

        C = C.eigenbasis x diag(C.eigenvalues) x C.eigenbasis^T

    c                     t         j                  | |       t        |      | _        |dgz  | _        d| _        t        |      | _        d| _        y )Nr	   r   )r0  r[   eyerp   rn   r   r   updated_eval)rV   rD   s     r.   r[   z"DecomposingPositiveMatrix.__init__  sF    dI.i.$s? !9~r`   c           
      |    | j                   |z   k  r S  j                          t               \   _         _        t         j                        dk  r7t        d|t         j                        t         j                        fz        t         j                        t         j                        z   _	        t        t                     D ]_  t        dz         D ]L  t         fdt        t                     D              x j                     <    j                     <   N a | _          S )zExecute eigendecomposition of `self` if
        ``current_eval > lazy_gap_evals + last_updated_eval``.

        Assumes (for sake of simplicity) that `self` is positive
        definite and hence raises a `RuntimeError` otherwise.
        r   zWThe smallest eigenvalue is <= 0 after %d evaluations!
eigenvectors:
%s 
eigenvalues:
%sr	   c              3      K   | ]<  }j                      |   j                      |   z  j                  |   d z  z   > ywr   )rp   rn   )r=   r   rX   r6  rV   s     r.   r?   z?DecomposingPositiveMatrix.update_eigensystem.<locals>.<genexpr>7  sS      >J8H1 OOA&q)DOOA,>q,AA&&q)3./8Hs   AA)r<  _enforce_symmetryeigrn   rp   rQ   RuntimeErrorr   r   r   rL   rd   rM   r   )rV   current_evalrU   rX   r6  s   `  @@r.   rm   z,DecomposingPositiveMatrix.update_eigensystem"  s'    4,,~==K ,/I)$/t A%9T__!5s4;K;K7LMNO O !$D$4$4 5D<L<L8M M s4y!A1Q3Z:= >J8=c$i8H>J ;J JQ"T\\!_Q%7   "
 )r`   c                 T    t        d t        | j                  |      D              dz  S )z+return ``(dx^T * C^-1 * dx)**0.5``
        c              3   &   K   | ]	  }|d z    ywr;   r<   r  s     r.   r?   z=DecomposingPositiveMatrix.mahalanobis_norm.<locals>.<genexpr>@  s     9#8R2q5#8r@   r3   )rM   ro   r   )rV   dxs     r.   r   z*DecomposingPositiveMatrix.mahalanobis_norm=  s%     93t||R#8993>>r`   c                     t        t        |             D ]4  }t        |      D ]$  }| |   |   | |   |   z   dz  x| |   |<   | |   |<   & 6 | S )Nr7   r3  )rV   rX   r6  s      r.   r?  z+DecomposingPositiveMatrix._enforce_symmetryB  s^    s4y!A1X+/71:Q
+Ba*GGQ
T!WQZ  " r`   N)r\   r]   r^   r_   r[   rm   r   r?  r<   r`   r.   rh   rh   
  s    6?
r`   rh   c                 x    t        |       D cg c]  }| dgz  
 }}t        |       D ]
  }d||   |<    |S c c}w )z@return identity matrix as `list` of "vectors" (lists themselves)r   r	   )rL   )rD   rX   r   s      r.   r;  r;  H  sI    "'	"23"2QaS"2A39!Q H	 	4s   7c                 J    |sIt        t                     D cg c]*  t         fdt        t                    D              , c}S t        t         d               D cg c]*  t         fdt        t                    D              , c}S c c}w c c}w )z usual dot product of "matrix" A with "vector" b.

    ``A[i]`` is the i-th row of A. With ``transpose=True``, A transposed
    is used.
    c              3   :   K   | ]  }   |   |   z    y wr  r<   r=   r6  Ar   rX   s     r.   r?   zdot.<locals>.<genexpr>W  "     :MqAaDGadNM   r   c              3   :   K   | ]  }|      |   z    y wr  r<   rJ  s     r.   r?   zdot.<locals>.<genexpr>Z  rL  rM  )rL   rd   rM   )rK  r   ry   rX   s   `` `r.   ro   ro   P  s     s1v(&A :E#a&M::&( 	( s1Q4y)+)A :E#a&M::)+ 	+(+s   /B)/B c                 b    t        t        |             D cg c]  }| |   ||   z    c}S c c}w )zadd vectors, return a + b r3  ar   rX   s      r.   rr   rr   ]  .    !&s1v/AAaD1Q4K///   ,c                 b    t        t        |             D cg c]  }| |   ||   z
   c}S c c}w )zsubtract vectors, return a - br3  rP  s      r.   r   r   a  rR  rS  c                 T    t        t        t        |             | j                        S )zWreturn index list to get `a` in order, ie
    ``a[argsort(a)[i]] == sorted(a)[i]``
    )key)r~   rL   rd   __getitem__)rQ  s    r.   r}   r}   e  s     %A-Q]]33r`   c           	      B   d}| t        |       k7  rt        |       S |si }| dd }| dd }t        |j                         t        d      D ],  }|j	                  |d      }|j	                  |d||   z        }. |D ]!  }||vst        d| dt        |      d	       |S )
a
  return ``s`` as `str` safe to `eval` or raise an exception.

    Strings in the `dict` `known_words` are replaced by their values
    surrounded with a space, which the caller considers safe to evaluate
    with `eval` afterwards.

    Known issues:

    >>> try: from cma import purecma
    ... except ImportError: import purecma
    >>> purecma.safe_str('int(p)', {'int': 'int', 'p': 3.1})  # fine
    ' int ( 3.1 )'
    >>> purecma.safe_str('int(n)', {'int': 'int', 'n': 3.1})  # unexpected
    ' i 3.1 t ( 3.1 )'

    z 0123456789.,+-*()[]e<>=NT)rV  reversez  z %s "z(" is not a safe string (known words are ))r   r~   keysrd   replacer%  )src   
safe_charsstestsretwordr   s          r.   rG   rG   k  s    " ,JCF{1vaDEQ4D{'')sDAdD)||D&;t+<"<= B J893{;KM N N  Kr`   c                    	 	 d		rddl 	fd}	fd}t        | d         }t        |      D cg c]
  }| |   dd  }}|dgz  }|dgz  } |||||        |||||       ||fS # t        $ r d	Y jw xY wc c}w )a  eigendecomposition of a symmetric matrix.

    Return the eigenvalues and an orthonormal basis
    of the corresponding eigenvectors, ``(EVals, Basis)``, where

    - ``Basis[i]``: `list`, is the i-th row of ``Basis``
    - the i-th column of ``Basis``, ie ``[Basis[j][i] for j in range(len(Basis))]``
      is the i-th eigenvector with eigenvalue ``EVals[i]``

    Details: much slower than `numpy.linalg.eigh`.
    Fr   Nc                 
   || dz
     d d  |d d  rj                  |t              }t        | dz
  dd      D ]  }d}s$d}t        |      D ]  }|t        ||         z   } nt	        j                  |d|             }|dk(  r;||dz
     ||<   t        |      D ]   }||dz
     |   ||<   d||   |<   d||   |<   " ns,t        |      D ]  }||xx   |z  cc<   |||   ||   z  z  } n&|d |xxx |z  ccc j                  |d | |d |       }||dz
     }	|dz  }
|	dkD  r|
 }
||
z  ||<   ||	|
z  z  }|	|
z
  ||dz
  <   st        |      D ]  }d||<   	 nd|d | t        |      D ]  }||   }	|	||   |<   ||   ||   |   |	z  z   }
sAt        |dz   |      D ])  }|
||   |   ||   z  z  }
||xx   ||   |   |	z  z  cc<   + |
||<   d||dz   |xxx |j                  |   |dz   | |	z  z  ccc |
j                  |j                  |   |dz   | ||dz   |       z   ||<    d}	s,t        |      D ]  }||xx   |z  cc<   |	||   ||   z  z  }	 n)|d |xxx |z  ccc |	j                  |d | |d |       z  }	|	||z   z  }s$t        |      D ]  }||xx   |||   z  z  cc<    n|d |xxx ||d | z  z  ccc t        |      D ]  }||   }	||   }
s1t        ||      D ]!  }||   |xx   |	||   z  |
||   z  z   z  cc<   # n*|j                  |   ||xxx |	||| z  |
||| z  z   z  ccc ||dz
     |   ||<   d||   |<    |||<   " t        | dz
        D ]y  }||   |   || dz
     |<   d||   |<   ||dz      }|dk7  rs%t        |dz         D ]  }||   |dz      |z  ||<    n!|j                  |dz      d |dz    |z  |d |dz    t        |dz         D ]  }sVd}
t        |dz         D ]  }|
||   |dz      ||   |   z  z  }
 t        |dz         D ]  }||   |xx   |
||   z  z  cc<    [j                  |j                  |dz      d|dz    |j                  |   d|dz          }
|j                  |   d |dz   xxx |
|d |dz    z  z  ccc  s t        |dz         D ]  }d||   |dz   <    bd|j                  |dz      d |dz    | s*t        |       D ]  }|| dz
     |   ||<   d|| dz
     |<    n|| dz
     d |  |d |  d|| dz
     d |  d|| dz
     | dz
  <   d|d<   y )Nr	   )dtyper   rC           r3   r4   )asarrayfloatrL   r   rM   ro   T)r  VderX   hscaler   r6  r!   r   hhnpnum_opts               r.   tred2zeig.<locals>.tred2  s}    1vay!

1E
*A qsAr"AAqA!C!I-E " BFF1Qq6N+|1v!qAQqS6!9AaD!AaDG!AaDG " "1X!QqTAaD[( & bqEUNEq!uae,AacFsFq5Aqy!QU
Q!A#"1X"! &  AbqE qA!AAaDG!qtAw{*A"!&qsAA1a1Q4/AaDAaDGaK/D "/  !!!A#aACCF1Q3qMA$55 266!##a&1Q-1Q3q#BB! " "1X!	QqTAaD[( & bqEQJE"1q!u--A!a%["1X!QqT	) & bqER!BQ%Z'EqA!A!A"!&q!AaDGAaD1qt8(;<G "- AqAaF
Q1QZ(?@QqS6!9AaD!AaDG " AaDi #r qsA!QAacF1IAaDG!A#ACx"1Q3Z tAaCy1}! (  cc!A#ht!nq0AdqsGqsA"!&qsA1acQqT!W!44A ",!&qsAaDGq1Q4x/G ", FF133qs8Aac?ACCF1QqSMBAt!AdqsG3 $ qsA #AaD1I $ "%AaC!A#5 8 1X1vay!!A#q	  acF2AJAbqEAacF2AJ!A#qs!r`   c           	         st        d|       D ]  }||   ||dz
  <    n|d|  |d| dz
   d|| dz
  <   d}d}d}t        |       D ]  }t        |t        ||         t        ||         z         }|}	|	| k  r t        ||	         ||z  k  rn|	dz  }	|	| k  r |	|kD  r*d}
	 |
dz  }
||   }||dz      |z
  d||   z  z  }|dz  dz   dz  }|dk  r| }||   ||z   z  ||<   ||   ||z   z  ||dz   <   ||dz      }|||   z
  }s"t        |dz   |       D ]  }||xx   |z  cc<    n||dz   | xxx |z  ccc ||z   }||	   }d}|}|}||dz      }d}d}t        |	dz
  |dz
  d	      D ]#  }|}|}|}|||   z  }||z  }|dz  ||   dz  z   dz  }||z  ||dz   <   ||   |z  }||z  }|||   z  ||z  z
  }||||z  |||   z  z   z  z   ||dz   <   sMt        |       D ]>  }||   |dz      }|||   |   z  ||z  z   ||   |dz   <   |||   |   z  ||z  z
  ||   |<   @ |j                  |dz      j	                         }||j                  |   z  ||z  z   |j                  |dz   <   ||j                  |   z  ||z  z
  |j                  |<   & | |z  |z  |z  ||   z  |z  }||z  ||<   ||z  ||<   t        ||         ||z  k  rn'||xx   |z  cc<   d||<    d
dk  rt        | dz
        D ]n  }|}||   }t        |dz   |       D ]  }||   |k  s|}||   } ||k7  s4||   ||<   |||<   t        |       D ]   }||   |   }||   |   ||   |<   |||   |<   " p y y )Nr	   r   rf  g      <r  r7   r3   r4   rC      r   )rL   r   r   ri  copy)r  rk  rl  rj  rX   r!   tst1epslr   iiterr   pr  dl1rm  r   c2c3el1r^  s2r   ro  r6  rq  s                            r.   tql2zeig.<locals>.tql2Z  s    1a[1!A# ! 1vAa!H!A#qA tS1YQqT23DAa%qt9D(Q a% 1uQJE !A1Q3!ad
3AACA1uBQ41q5>AaDqTQU^AacFAaC&CAaDA"!&qsAAaDAID "/ !A#aAAA !AABBAaC&CAB #1Q3!R0!HETAaD!G^c1!"Q!A#aD1HE!Hq1u,!"Q!a%!ad(*:%;!;!A#  '%*1X$%aD1I,-!QK!a%,?!QqS	*+ad1g+A*=!Q &.
 "#QqSB'(133q6zAF':ACC!H%&QZ!b&%8ACCF3 1: R"s*QqT1C7Aq5AaDq5AaD 1Q4yCH,K P aDAIDAaDs x 61Q3ZaDqsAAtaxaD '
 6Q4AaDAaD"1XaDG"#A$q'!Q"#!Q &   r`   )numpyImportErrorrd   rL   )
ri   rr  r  r9   rX   rj  rk  rl  rp  rq  s
           @@r.   r@  r@    s    P
Md}$~ 	AaD	A(#(Q1a(A#	QCA	QCA	!Q1Aq!a4Kw  l 	$s   A) A:)A76A7c                  Z    ddl } t        d       t        | j                  dd             y)a$  test of the `purecma` module, called ``if __name__ == "__main__"``.

    Currently only based on `doctest`:

    >>> try: from cma import purecma as pcma
    ... except ImportError: import purecma as pcma
    >>> import random
    >>> random.seed(8)
    >>> xmin, es = pcma.fmin(pcma.ff.rosenbrock, 4 * [0.5], 0.5,
    ...                      verb_disp=0, verb_log=1)
    >>> print(es.counteval)
    1712
    >>> print(es.best.evals)
    1704
    >>> assert es.best.f < 1e-12
    >>> random.seed(5)
    >>> es = pcma.CMAES(4 * [0.5], 0.5)
    >>> es.params = pcma.CMAESParameters(es.params.dimension,
    ...                                  es.params.lam,
    ...                                  pcma.RecombinationWeights)
    >>> while not es.stop():
    ...     X = es.ask()
    ...     es.tell(X, [pcma.ff.rosenbrock(x) for x in X])
    >>> print("%s, %s" % (pcma.ff.rosenbrock(es.result[0]) < 1e-13,
    ...                   es.result[2] < 1600))
    True, True

    Large population size:

    >>> random.seed(4)
    >>> es = pcma.CMAES(3 * [1], 1)
    >>> es.params = pcma.CMAESParameters(es.params.dimension, 300,
    ...                                  pcma.RecombinationWeights)
    >>> es.logger = pcma.CMAESDataLogger()
    >>> try:
    ...    es = es.optimize(pcma.ff.elli, verb_disp=0)
    ... except AttributeError:  # OOOptimizer.optimize is not available
    ...     while not es.stop():
    ...         X = es.ask()
    ...         es.tell(X, [pcma.ff.elli(x) for x in X])
    >>> assert es.result[1] < 1e13
    >>> print(es.result[2])
    9300

    r   Nzlaunching doctest...T)reportverbose)doctestr   testmod)r  s    r.   testr    s&    \ 	
 !	'//q/
12r`   __main__)r<   z
1e3 * N**2Nr$  r	   i  )Fr  )/r_   
__future__r   r   ___author____license__sysr   r   warningsr   mathr   r   randomr   r   
interfacesr
   r   _BaseDataLoggerr  r%  objectrecombination_weightsr   __version__
__author____docformat__r/   r1   r   r   r  rk   listr0  rh   r;  ro   rr   r   r}   rG   r@  r  r\   r<   r`   r.   <module>r     s@  -\   % !   82J ; n
" )-.2nb*Sf *SX}K }BLo Lb" "@*6 *(J4 J<< <|+004ZGR
03j zF u& 	Z  2#)6 K2 	Z    s"   B? C ?CC	CC