ó
6™xTc           @   sí   d  d l  m Z d  d l m Z m Z m Z m Z d  d l m Z d  d l	 m
 Z
 d  d l Z d  d l Z d  d l Z d  d l m Z d  d l Z e j d ƒ d d	 „ Z d d
 „ Z d „  Z d „  Z e d k ré e e j d ƒ n  d S(   iÿÿÿÿ(   t   division(   t
   parameterst	   gradientst   pack_gradientst   g_exp_i_alpha_sum(   t   least_squares(   t   approx_equalN(   t   StringIOi    g:Œ0âŽyE>c         C   s   g  } t  j | ƒ } xt t | ƒ ƒ D]ð } g  } xÀ t d ƒ D]² } g  } x‚ | | g D]s }	 | | j ƒ  }
 |
 | c |	 7<t |
 Œ  | | <t d | ƒ } t d |  d | j ƒ  ƒ } | j	 | j ƒ  ƒ q[ W| j	 | d | d d | ƒ qA W| j	 t
 | Œ  ƒ | | | | <q( W| S(   Ni   t   paramst   obst   calci    i   i   (   t   copyt   deepcopyt   xranget   lent   as_listR   R   R   t   ft   appendR   (   R	   R   t   epst   resultt
   params_epst   i_paramt   dxt   ixt   tst
   signed_epst   pi_epst   exp_sumt   target(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/tst_g_exp_i_alpha_derivatives.pyt   d_target_d_params_finite   s"    %c         C   s;  g  } t  j | ƒ } xt t | ƒ ƒ D]} xô t d ƒ D]æ } g  } x” | | g D]… } | | j ƒ  }	 |	 | c | 7<t |	 Œ  | | <t d | ƒ }
 t d |  d |
 j ƒ  ƒ } |
 j	 d | ƒ } | j
 t | ƒ ƒ qU W| j
 g  t | d | d ƒ D] \ } } | | d | ^ qü ƒ q; W| | | | <q( W| S(	   Ni   R   R	   R
   R   i    i   i   (   R   R   R   R   R   R   R   R   R   t   d_target_d_paramsR   R   t   zip(   R	   R   R   R   R   R   R   t   gsR   R   R   R   t   dpt   gpt   gm(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/tst_g_exp_i_alpha_derivatives.pyt   d2_target_d_params_finite!   s     Gc   	      C   s  t  d |  d | ƒ } | d It | ƒ IJt d | ƒ } t d |  d | j ƒ  ƒ } | j d | ƒ } | d It | ƒ IJt t | ƒ t | ƒ ƒ sž t ‚ t d |  d | ƒ } | d I| IJt	 | j
 d | ƒ ƒ } | d I| IJt | | ƒ s t ‚ | Jd  S(	   NR	   R   s
   grads_fin:R
   R   s
   grads_ana:s
   curvs_fin:s
   curvs_ana:(   R   R   R   R   R   R   R   t   AssertionErrorR$   t   listt   d2_target_d_params(	   R	   R   t   outt	   grads_finR   R   t	   grads_anat	   curvs_fint	   curvs_ana(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/tst_g_exp_i_alpha_derivatives.pyt   compare_analytical_and_finite3   s    !c   	      C   sB  d |  k } | s t  ƒ  } n	 t j } xt d d ƒ D]þ } xõ t d ƒ D]ç } g  } xw t | ƒ D]i } | j t d t j ƒ  d d d t j ƒ  d d d t j ƒ  d d d d t j t j ƒ  ƒ ƒ qc Wt	 d	 | ƒ } t
 | j ƒ  ƒ } t d
 | d	 | d | ƒ t d
 | t j ƒ  d d	 | d | ƒ qJ Wq7 Wd GHd  S(   Ns	   --verbosei   i   t   gg      à?t   ffpt   fdpt   alphaR   R	   R(   t   OK(   R   t   syst   stdoutR   R   R   t   randomt   matht   piR   t   absR   R-   (	   t   argst   verboseR(   t   n_paramst   i_trialR   t   iR   R	   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/tst_g_exp_i_alpha_derivatives.pyt   exerciseB   s0    	t   __main__i   (   t
   __future__R    t(   cctbx.examples.g_exp_i_alpha_derivativesR   R   R   R   t&   cctbx.examples.exp_i_alpha_derivativesR   t   libtbx.test_utilsR   R5   R6   R   t	   cStringIOR   R3   t   seedR   R$   R-   R>   t   __name__t   argv(    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/tst_g_exp_i_alpha_derivatives.pyt   <module>   s   "		