ó
[™xTc           @   sš   d  Z  d d l m Z d d l m Z d d l m Z d d l Z d e j e j	 f d „  ƒ  YZ
 d e
 f d	 „  ƒ  YZ d
 e j e j	 f d „  ƒ  YZ d S(   s$    A collection of L.S. test problems iÿÿÿÿ(   t   division(   t   flex(   t   normal_eqnsNt   polynomial_fitc           B   sb   e  Z d  Z d Z d Z e j d ƒ Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z e d „ Z RS(   s·    Fit yc(t) = -t^3 + a t^2 + b t + c to synthetic data produced by
      yo(t) = 2 t^2 (1-t) + noise, with an overall scale factor on yc(t)
      whose optimal value is therefore 2.
  gñhãˆµøä>i
   g      à?g333333Ó?gš™™™™™É?c         K   sâ   t  t |  ƒ j d d d | ƒ t j |  | ƒ t j |  j ƒ |  j |  _ } |  j	 t j
 g  t |  j ƒ D] } d | ^ qk ƒ } d | d d | | |  _ t j
 |  j d ƒ |  _ | d |  _ | d |  _ |  j ƒ  d  S(   Nt   n_parametersi   t
   normalisediÿÿÿÿg       @i   i   (   t   superR   t   __init__t   libtbxt   adopt_optional_init_argsR   t   double_ranget   n_datat   tt   noiset   doublet   xranget   yot   onet   t2t   t3t   restart(   t   selfR   t   kwdsR   t   iR   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR      s     6c         C   s   |  j  j ƒ  |  _ d  |  _ d  S(   N(   t   x_0t	   deep_copyt   xt   Nonet   old_x(   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR      s    c         C   s+   |  j  j ƒ  |  _ |  j  |  j ƒ  7_  d  S(   N(   R   R   R   t   step(   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyt   step_forward#   s    c         C   s/   |  j  d  k	 s t ‚ |  j  d  |  _ |  _  d  S(   N(   R   R   t   AssertionErrorR   (   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyt   step_backward'   s    c         C   s   |  j  j ƒ  S(   N(   R   t   norm(   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyt   parameter_vector_norm+   s    c         C   sè   |  j  ƒ  |  j \ } } } |  j |  j |  j |  j f \ } } } } | | | | | | }	 | | | f }
 t j t j |  j	 |  j
 ƒ ƒ } x* t |
 ƒ D] \ } } | j | | ƒ qž W|  j |	 | |  j d d  ƒ|  j ƒ  d  S(   Nt   weights(   t   resetR   R   R   R   R   R   R   t   gridR   R   t	   enumeratet   matrix_paste_column_in_placet   add_equationsR   R   t   finalise(   R   t   objective_onlyt   at   bt   cR   R   R   R   t   yct   grad_yct   jacobian_yct   jt   der_r(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyt   build_up.   s    
*!(   g      à?g333333Ó?gš™™™™™É?(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R    R"   t   FalseR3   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR      s   					t   polynomial_fit_with_penaltyc           B   s   e  Z e d  „ Z RS(   c         C   si   t  t |  ƒ j | ƒ |  j \ } } } |  j ƒ  } | j d | | | d d t j d ƒ d d ƒ d  S(   Nt   residuali   t   grad_residuali   iÿÿÿÿt   weight(   i   iÿÿÿÿi   (   R   R8   R3   R   t   reduced_problemt   add_equationR   R   (   R   R*   R+   R,   R-   t   reduced(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR3   =   s    (   R4   R5   R7   R3   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR8   ;   s   t   exponential_fitc           B   sk   e  Z d  Z d Z e j d ƒ Z e j d ƒ Z d „  Z d	 „  Z	 d
 „  Z
 e d „ Z d „  Z d „  Z RS(   s½    Model M(x, t) = x3 e^{x1 t} + x4 e^{x2 t}

      Problem 18 from

      UCTP Test Problems for Unconstrained Optimization
      Hans Bruun Nielsen
      TECHNICAL REPORT IMM-REP-2000-17
  i-   iüÿÿÿiûÿÿÿi   iÿÿÿÿiþÿÿÿi   c      .   C   s}   t  t |  ƒ j d d ƒ d t j d |  j d ƒ |  _ t j d2 ƒ |  _ t	 |  j ƒ t	 |  j ƒ k so t
 ‚ |  j ƒ  d  S(3   NR   i   g{®Gáz”?i   g7ê°Â-·?gµmÁã¿?g¦}sõÆ?gXqªµ0É?g9% &áBÑ?g³x±0DNÒ?g_Ï×,—�Ò?gá“©‚QÔ?grúz¾f¹Ó?gá—úyS‘Õ?güü÷àµKÖ?gªÉ�Ô?g°ä*¿)Ó?gŸ��·±Õ?gjù�«<�Ó?gª×-c}Ò?gâä~‡¢@Ó?g=e5]OtÓ?gDN_Ï×,Ò?gÓÀÍâÅÐ?gðr¥žÒ?g¡¢êW:Ñ?gŠ>eÄÌ?gXr‹ßÌ?gªãn­É?gÝ$�•CÉ?g
º½¤1ZÇ?gú}ÿæÅ‰Ç?g ïU+~Ã?gMK¬ŒFÆ?gÂ‰è×ÖOÃ?g€ñú'À?gØaLú{)À?gnRÑXû;»?gX¾Û¼q¾?gŒ†ŒG©„·?gSÍ¬¥€À?gºKâ¬ˆ¾?g÷!o¹ú±½?go)ç‹½»?g®ªND³?g¢·xxÏ�±?gé¹-@·?gr§t°þÏµ?g7n1?74±?(-   g7ê°Â-·?gµmÁã¿?g¦}sõÆ?gXqªµ0É?g9% &áBÑ?g³x±0DNÒ?g_Ï×,—�Ò?gá“©‚QÔ?grúz¾f¹Ó?gá—úyS‘Õ?güü÷àµKÖ?gªÉ�Ô?g°ä*¿)Ó?gŸ��·±Õ?gjù�«<�Ó?gª×-c}Ò?gâä~‡¢@Ó?g=e5]OtÓ?gDN_Ï×,Ò?gÓÀÍâÅÐ?gðr¥žÒ?g¡¢êW:Ñ?gŠ>eÄÌ?gXr‹ßÌ?gªãn­É?gÝ$�•CÉ?g
º½¤1ZÇ?gú}ÿæÅ‰Ç?g ïU+~Ã?gMK¬ŒFÆ?gÂ‰è×ÖOÃ?g€ñú'À?gØaLú{)À?gnRÑXû;»?gX¾Û¼q¾?gŒ†ŒG©„·?gSÍ¬¥€À?gºKâ¬ˆ¾?g÷!o¹ú±½?go)ç‹½»?g®ªND³?g¢·xxÏ�±?gé¹-@·?gr§t°þÏµ?g7n1?74±?(   R   R?   R   R   R
   R   R   R   t   yt   lenR   R   (   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR   V   s           $c         C   s   |  j  j ƒ  |  _ d  |  _ d  S(   N(   R   R   R   R   R   (   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR   e   s    c         C   s   |  j  j ƒ  S(   N(   R   R!   (   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR"   i   s    c         C   s  |  j  \ } } } } t j | |  j ƒ } t j | |  j ƒ } | | | | } | |  j 8} |  j ƒ  | r† |  j | d d  ƒnŒ |  j | | |  j | | | | f }	 t j t j	 |  j
 |  j ƒ ƒ }
 x* t |	 ƒ D] \ } } |
 j | | ƒ qÜ W|  j | |
 d d  ƒd  S(   NR#   (   R   R   t   expR   R@   R$   t   add_residualsR   R   R%   R   R   R&   R'   R(   (   R   R*   t   x1t   x2t   x3t   x4t   exp_x1_tt   exp_x2_tt	   residualst   grad_rt   jacobianR1   R2   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR3   l   s     
	!c         C   s+   |  j  j ƒ  |  _ |  j  |  j ƒ  7_  d  S(   N(   R   R   R   R   (   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR   €   s    c         C   s/   |  j  d  k	 s t ‚ |  j  d  |  _ |  _  d  S(   N(   R   R   R   R   (   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR    „   s    (   iüÿÿÿiûÿÿÿi   iüÿÿÿ(   iÿÿÿÿiþÿÿÿi   iÿÿÿÿ(   R4   R5   R6   R   R   R   t   arg_minR   R   R   R"   R7   R3   R   R    (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyR?   E   s   				(   R6   t
   __future__R    t   scitbx.array_familyR   t   scitbx.lstbxR   R   t)   non_linear_ls_with_separable_scale_factort   non_linear_ls_mixinR   R8   t   non_linear_lsR?   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/lstbx/tests/test_problems.pyt   <module>   s   	2
