;ò
tt@c           @   s  d  k  Z  d  k Z e Z d k l Z d k l Z d „  Z e d d „ Z	 d „  Z
 d „  Z e d j o¢ d	 k  l Z d
 „  Z d d f d d f d d f d d f g Z d d f d d f d d f d d f g Z e	 e d d f e ƒ GHd „  Z e	 e d f e ƒ GHn d  S(   N(   s   DerivVar(   s   IterationCountExceededErrorc   
      C   sÒ   t  | ƒ } d } t i | | f ƒ } xš | D]’ } d } t  | ƒ d j o | d } n |  | | d ƒ } | | | d | d } t i | d ƒ | }	 | |	 d  d  … t i f |	 } q. W| | f Sd  S(   Nf0.0i   i   i   i    (   s   lens
   parameterss   n_params   chi_sqs   Numerics   zeross   alphas   datas   points   sigmas   models   fs   arrays   ds   NewAxis(
   s   models
   parameterss   datas   n_params   fs   chi_sqs   sigmas   points   alphas   d(    (    sL   /mit/python/lib/python2.3/site-packages/Scientific/Functions/LeastSquares.pys
   _chiSquare   s     %f0.0050000000000000001c         C   s’  t  | ƒ } f  } d } x. | D]& }
 | t |
 | ƒ f } | d } q Wt i | ƒ } d } t |  | | ƒ \ } } d } xõ n oí t i | | t i | ƒ | d t i | d ƒ ƒ } t d „  | | ƒ }	 t |  |	 | ƒ \ } } | | j o d | } n; d | } | d | d | j  o Pn |	 } | } | } | d } | t j	 o
 | | j o
 t ‚ q q† Wt d „  |	 ƒ | d f Sd	 S(
   s   General non-linear least-squares fit using the
    Levenberg-Marquardt algorithm and automatic derivatives.

    The parameter |model| specifies the function to be fitted. It will be
    called with two parameters: the first is a tuple containing all fit
    parameters, and the second is the first element of a data point (see
    below). The return value must be a number.  Since automatic
    differentiation is used to obtain the derivatives with respect to the
    parameters, the function may only use the mathematical functions known
    to the module FirstDerivatives.

    The parameter |parameter| is a tuple of initial values for the
    fit parameters.

    The parameter |data| is a list of data points to which the model
    is to be fitted. Each data point is a tuple of length two or
    three. Its first element specifies the independent variables
    of the model. It is passed to the model function as its first
    parameter, but not used in any other way. The second element
    of each data point tuple is the number that the return value
    of the model function is supposed to match as well as possible.
    The third element (which defaults to 1.) is the statistical
    variance of the data point, i.e. the inverse of its statistical
    weight in the fitting procedure.

    The function returns a list containing the optimal parameter values
    and the chi-squared value describing the quality of the fit.
    i    i   f0.001f0.5c         C   s   |  | S(   N(   s   as   b(   s   as   b(    (    sL   /mit/python/lib/python2.3/site-packages/Scientific/Functions/LeastSquares.pys   <lambda>F   s    f10.0f0.10000000000000001c         C   s   |  d S(   Ni    (   s   p(   s   p(    (    sL   /mit/python/lib/python2.3/site-packages/Scientific/Functions/LeastSquares.pys   <lambda>S   s    N(   s   lens
   parameterss   n_params   ps   is   params   DerivVars   Numerics   identitys   ids   ls
   _chiSquares   models   datas   chi_sqs   alphas   niters   LAs   solve_linear_equationss   diagonals   arrays   deltas   maps   next_ps   next_chi_sqs
   next_alphas   stopping_limits   max_iterationss   Nones   IterationCountExceededError(   s   models
   parameterss   datas   max_iterationss   stopping_limits   n_params   chi_sqs   ids   next_chi_sqs   next_ps   params   deltas   alphas   niters   is   ls   ps
   next_alpha(    (    sL   /mit/python/lib/python2.3/site-packages/Scientific/Functions/LeastSquares.pys   leastSquaresFit   s<       
 
c         C   sI   d } x8 t t |  ƒ ƒ D]$ } | |  | t i | | ƒ } q W| Sd  S(   Nf0.0(   s   rs   ranges   lens   paramss   is   Numerics   powers   t(   s   paramss   ts   is   r(    (    sL   /mit/python/lib/python2.3/site-packages/Scientific/Functions/LeastSquares.pys   polynomialModelY   s
     "c         C   s   t  t |  | ƒ Sd S(   s_   Least-squares fit to a polynomial whose order is defined by
    the number of parameter values.N(   s   leastSquaresFits   polynomialModels
   parameterss   data(   s
   parameterss   data(    (    sL   /mit/python/lib/python2.3/site-packages/Scientific/Functions/LeastSquares.pys   polynomialLeastSquaresFit_   s     s   __main__(   s   expc         C   s   |  d t |  d | ƒ Sd  S(   Ni    i   (   s   params   exps   t(   s   params   t(    (    sL   /mit/python/lib/python2.3/site-packages/Scientific/Functions/LeastSquares.pys   fk   s    id   f	3445000.0iÈ   f
27440000.0i,  f259200000.0i�  f1600000000.0f	4.999e-08f530.70000000000005f	1289000.0f
65590000.0f10000000000000.0i\  c         C   s   d t  |  d | ƒ Sd  S(   Nf10000000000000.0i    (   s   exps   params   t(   s   params   t(    (    sL   /mit/python/lib/python2.3/site-packages/Scientific/Functions/LeastSquares.pys   f2u   s    f3000.0(   s   Numerics   LinearAlgebras   LAs   FirstDerivativess   DerivVars
   Scientifics   IterationCountExceededErrors
   _chiSquares   Nones   leastSquaresFits   polynomialModels   polynomialLeastSquaresFits   __name__s   exps   fs   data_quantums   data_classicals   f2(   s   data_classicals   LAs   fs   f2s   Numerics
   _chiSquares   polynomialLeastSquaresFits   DerivVars   LinearAlgebras   polynomialModels   exps   leastSquaresFits   data_quantums   IterationCountExceededError(    (    sL   /mit/python/lib/python2.3/site-packages/Scientific/Functions/LeastSquares.pys   ?   s   	>			**	