ó
Z™xTc           @   s_  d  d l  m Z d  d l Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d „  ƒ  YZ e d k r[d d d d d d g Z e d d ƒ Z e d d ƒ Z xr e D]g Z x] e D]U Z e d e d g Z e d Ge d Gx' e D] Z e e ƒ d ƒ j e ƒ Gq+WHqú WHqí Wn  d S(   iÿÿÿÿ(   t   divisionNc         C   s8   i t  d 6t d 6t d 6t d 6t d 6t d 6} | |  S(   sF    Easy way to get a function constructor
        based on its name
    t   spheret   ackleyt   michalewiczt
   rosenbrockt	   rastrigint   easom(   t   Spheret   Ackleyt   Michalewiczt
   Rosenbrockt	   Rastrigint   Easom(   t   namet   funcs(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyt   Function   s    

c         C   s(   t  t d g |  d g |  d g |  ƒ S(   sN    returns the sphere objective function with
        mins and maxs defined
    g�Âõ(\�Àg�Âõ(\�@g        (   t   ObjFunct   _sphere(   t   dim(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR      s    c         C   s(   t  t d g |  d g |  d g |  ƒ S(   sN    returns the ackley objective function with
        mins and maxs defined
    g      >Àg      >@g        (   R   t   _ackley(   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR      s    c         C   s+   t  t d g |  t j g |  d g |  ƒ S(   sS    returns the michalewicz objective function with
        mins and maxs defined
    g        (   R   t   _michalewiczt   mt   pi(   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR	       s    c         C   s(   t  t d g |  d g |  d g |  ƒ S(   sQ    returns the Rastrigin objective function with
        mins and maxs defined
    g      Àg      @g        (   R   t
   _rastrigin(   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR   '   s    c         C   s(   t  t d g |  d g |  d g |  ƒ S(   sR    returns the Rosenbrock objective function with
        mins and maxs defined
    g      Àg      $@g      ð?(   R   t   _rosenbrock(   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR
   .   s    c         C   s=   |  d k r ‚  n  t  t d d g d d g t j t j g ƒ S(   sM    returns the Easom objective function with
        mins and maxs defined
    i   g      >Àg      >@(   R   t   _easomR   R   (   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR   5   s    c         C   s!   t  g  |  D] } | d ^ q
 ƒ S(   s"    the sphere (sphere) function
    g       @(   t   sum(   t   coordst   x(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR   >   s    c         C   s­   t  |  ƒ } d } d } d t j } d } } x3 |  D]+ } | | d 7} | t j | | ƒ 7} q6 W| t j | t j d | | ƒ ƒ t j d | | ƒ | t j S(   s    the ackley function
    g      4@gš™™™™™É?g       @g        g      ð?(   t   lenR   R   t   cost   expt   sqrtt   e(   R   t   nt   at   bt   ct   s1t   s2t   i(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR   D   s    
c      	   C   sA   d t  g  |  D], } | d d t j d t j | ƒ ^ q ƒ S(   s    rastrigin function
    i   g       @g      $@(   R   R   R   R   (   R   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR   U   s    c         C   s}   t  |  ƒ } | d } |  d | !} |  | } d } xC t | | ƒ D]2 \ } } | d | | | d | d d 7} qC W| S(   s    rosenbrock function
    i   i    id   g       @g      ð?(   R   t   zip(   R   R   t   pR   t   yt   resultt   xxt   yy(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR   [   s    

*c         C   s]   d } t  g  t |  ƒ D]? \ } } t j | ƒ t j | | d t j ƒ d | ^ q ƒ S(   s    michalewicz function
    g      $@g       @(   R   t	   enumerateR   t   sinR   (   R   t   rR(   t   coord(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR   g   s    c         C   sW   |  d } |  d } t  j | ƒ t  j | ƒ t  j | t  j d | t  j d ƒ S(   s    easom function
    i    i   g       @(   R   R   R   R   (   R   t   x1t   x2(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR   n   s    

R   c           B   s    e  Z d  Z d „  Z d „  Z RS(   s\    This is our objective function.
        It contains the function as well as its bounds
    c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   t   funct   minst   maxst   xstar(   t   selfR5   R6   R7   R8   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyt   __init__z   s    			c         C   s   |  j  | ƒ S(   s     Evaluates the function
        (   R5   (   R9   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyt   eval€   s    (   t   __name__t
   __module__t   __doc__R:   R;   (    (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyR   u   s   	t   __main__R   R   R   R   R   R   iØÿÿÿi)   g      $@i   (    (   t
   __future__R    t   mathR   R   R   R   R	   R   R
   R   R   R   R   R   R   R   R   R<   R   t   rangeR   R+   R-   R.   t   tmpR   R;   (    (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/functions.pyt   <module>   s@   															