
    tKgx                     ,   d Z ddlZddlmZ g dZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Z G d de      Z e       Zd Z G d de      Z e       Zd Zd Zd Zd Zd Zd Zd Zd Z G d de      Z e       Z G d d e      Z  e        Z!y)!zI Collection of Model instances for use with the odrpack fitting package.
    N)Model)r   exponentialmultilinear	unilinear	quadratic
polynomialc                 r    | d   | dd  }}|j                   d   df|_         |||z  j                  d      z   S Nr      axis)shapesum)Bxabs       U/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/scipy/odr/_models.py_lin_fcnr   
   sB    Q412qAwwqz1oAG!yyay       c                     t        j                  |j                  d   t              }t        j                  ||j                         f      }| j                  d   |j                  d   f|_        |S N)nponesr   floatconcatenateravel)r   r   r   ress       r   _lin_fjbr       sS    
U#A
..!QWWY
(Caggbk*CIJr   c                     | dd  }t        j                  ||j                  d   f|j                  d   z  d      }|j                  |_        |S )Nr   r   r   r   )r   repeatr   )r   r   r   s      r   _lin_fjdr#      sF    	!"A
		!aggbk^AGGBK/a8AggAGHr   c                     t        | j                  j                        dk(  r| j                  j                  d   }nd}t        j                  |dz   ft
              S N   r   r   )lenr   r   r   r   r   )datams     r   _lin_estr*      sF    
 466<<AFFLLO77AE8U##r   c                     | d   | dd  }}|j                   d   df|_         |t        j                  |t        j                  ||      z  d      z   S r
   r   r   r   power)r   r   powersr   r   s        r   	_poly_fcnr/   ,   sN    Q412qAwwqz1oAGrvva"((1f--A666r   c                     t        j                  t        j                  |j                  d   t              t        j
                  ||      j                  f      }| j                  d   |j                  d   f|_        |S r   )r   r   r   r   r   r-   flat)r   r   r.   r   s       r   _poly_fjacbr2   3   s_    
.."''!''"+u5((1f-224 5Caggbk*CIJr   c                     | dd  }|j                   d   df|_         ||z  }t        j                  |t        j                  ||dz
        z  d      S )Nr   r   r   r,   )r   r   r.   r   s       r   _poly_fjacdr4   :   sN    	!"Awwqz1oAG	F
A66!bhhq&(++!44r   c                 D    | d   t        j                  | d   |z        z   S Nr   r   r   expr   r   s     r   _exp_fcnr:   C   "    Q4"&&1"""r   c                 D    | d   t        j                  | d   |z        z  S )Nr   r7   r9   s     r   _exp_fjdr=   G   r;   r   c                     t        j                  t        j                  |j                  d   t              |t        j
                  | d   |z        z  f      }d|j                  d   f|_        |S )Nr   r   r&   )r   r   r   r   r   r8   )r   r   r   s      r   _exp_fjbr?   K   sW    
.."''!''"+u5q266!A$(;K7KL
MCAGGBK CIJr   c                 0    t        j                  ddg      S )N      ?)r   arrayr(   s    r   _exp_estrD   Q   s    88RHr   c                   "     e Zd ZdZ fdZ xZS )_MultilinearModela  
    Arbitrary-dimensional linear model

    This model is defined by :math:`y=\beta_0 + \sum_{i=1}^m \beta_i x_i`

    Examples
    --------
    We can calculate orthogonal distance regression with an arbitrary
    dimensional linear model:

    >>> from scipy import odr
    >>> import numpy as np
    >>> x = np.linspace(0.0, 5.0)
    >>> y = 10.0 + 5.0 * x
    >>> data = odr.Data(x, y)
    >>> odr_obj = odr.ODR(data, odr.multilinear)
    >>> output = odr_obj.run()
    >>> print(output.beta)
    [10.  5.]

    c           
      V    t         |   t        t        t        t
        dddd       y )NzArbitrary-dimensional Linearz y = B_0 + Sum[i=1..m, B_i * x_i]z&$y=\beta_0 + \sum_{i=1}^m \beta_i x_i$nameequTeXequ)fjacbfjacdestimatemeta)super__init__r   r    r#   r*   self	__class__s    r   rQ   z_MultilinearModel.__init__m   s.    HHx8;EG 	 	Hr   __name__
__module____qualname____doc__rQ   __classcell__rT   s   @r   rF   rF   V   s    ,H Hr   rF   c                 "   t        j                  |       }|j                  dk(  rt        j                  d|dz         }t	        |      df|_        t	        |      dz   }|fd}t        t        t        t        ||fdd|dz
  z  d|dz
  z  d      S )	a  
    Factory function for a general polynomial model.

    Parameters
    ----------
    order : int or sequence
        If an integer, it becomes the order of the polynomial to fit. If
        a sequence of numbers, then these are the explicit powers in the
        polynomial.
        A constant term (power 0) is always included, so don't include 0.
        Thus, polynomial(n) is equivalent to polynomial(range(1, n+1)).

    Returns
    -------
    polynomial : Model instance
        Model instance.

    Examples
    --------
    We can fit an input data using orthogonal distance regression (ODR) with
    a polynomial model:

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from scipy import odr
    >>> x = np.linspace(0.0, 5.0)
    >>> y = np.sin(x)
    >>> poly_model = odr.polynomial(3)  # using third order polynomial model
    >>> data = odr.Data(x, y)
    >>> odr_obj = odr.ODR(data, poly_model)
    >>> output = odr_obj.run()  # running ODR fitting
    >>> poly = np.poly1d(output.beta[::-1])
    >>> poly_y = poly(x)
    >>> plt.plot(x, y, label="input data")
    >>> plt.plot(x, poly_y, label="polynomial ODR")
    >>> plt.legend()
    >>> plt.show()

     r   c                 8    t        j                  |ft              S )N)r   r   r   )r(   len_betas     r   	_poly_estzpolynomial.<locals>._poly_est   s    ww{E**r   zSorta-general Polynomialz$y = B_0 + Sum[i=1..%s, B_i * (x**i)]z)$y=\beta_0 + \sum_{i=1}^{%s} \beta_i x^i$rH   )rM   rL   rN   
extra_argsrO   )	r   asarrayr   aranger'   r   r/   r4   r2   )orderr.   r_   r`   s       r   r   r   x   s    R ZZF||r1fqj)K#FL6{QH!) + +[#	9>(1*MG!!%&' 'r   c                   "     e Zd ZdZ fdZ xZS )_ExponentialModela  
    Exponential model

    This model is defined by :math:`y=\beta_0 + e^{\beta_1 x}`

    Examples
    --------
    We can calculate orthogonal distance regression with an exponential model:

    >>> from scipy import odr
    >>> import numpy as np
    >>> x = np.linspace(0.0, 5.0)
    >>> y = -10.0 + np.exp(0.5*x)
    >>> data = odr.Data(x, y)
    >>> odr_obj = odr.ODR(data, odr.exponential)
    >>> output = odr_obj.run()
    >>> print(output.beta)
    [-10.    0.5]

    c           
      V    t         |   t        t        t        t
        dddd       y )NExponentialzy= B_0 + exp(B_1 * x)z$y=\beta_0 + e^{\beta_1 x}$rH   rM   rL   rN   rO   )rP   rQ   r:   r=   r?   rD   rR   s    r   rQ   z_ExponentialModel.__init__   s.    "*'4&=)GI 	 	Jr   rU   r[   s   @r   rf   rf          *J Jr   rf   c                     || d   z  | d   z   S r6   r]   r9   s     r   _unilinrl      s    QqT6AaD=r   c                 V    t        j                  |j                  t              | d   z  S )Nr   )r   r   r   r   r9   s     r   _unilin_fjdrn      s     77177E"QqT))r   c                     t        j                  |t        j                  |j                  t              f      }d|j                  z   |_        |S )N)r&   r   r   r   r   r   r   r   _rets      r   _unilin_fjbrs      s8    >>1bggaggu567DDJKr   c                      y)N)rA   rA   r]   rC   s    r   _unilin_estru      s    r   c                 0    ||| d   z  | d   z   z  | d   z   S )Nr   r   r&   r]   r9   s     r   
_quadraticrw      s&    a!fqtmqt##r   c                 $    d|z  | d   z  | d   z   S r%   r]   r9   s     r   	_quad_fjdry      s    Q3qt8ad?r   c                     t        j                  ||z  |t        j                  |j                  t              f      }d|j                  z   |_        |S )N)   rp   rq   s      r   	_quad_fjbr|      s>    >>1Q3277177E#:;<DDJKr   c                      y)N)rA   rA   rA   r]   rC   s    r   	_quad_estr~      s    r   c                   "     e Zd ZdZ fdZ xZS )_UnilinearModela  
    Univariate linear model

    This model is defined by :math:`y = \beta_0 x + \beta_1`

    Examples
    --------
    We can calculate orthogonal distance regression with an unilinear model:

    >>> from scipy import odr
    >>> import numpy as np
    >>> x = np.linspace(0.0, 5.0)
    >>> y = 1.0 * x + 2.0
    >>> data = odr.Data(x, y)
    >>> odr_obj = odr.ODR(data, odr.unilinear)
    >>> output = odr_obj.run()
    >>> print(output.beta)
    [1. 2.]

    c           
      V    t         |   t        t        t        t
        dddd       y )NzUnivariate Linearzy = B_0 * x + B_1z$y = \beta_0 x + \beta_1$rH   ri   )rP   rQ   rl   rn   rs   ru   rR   s    r   rQ   z_UnilinearModel.__init__  s.    ;"-':&9)FH 	 	Ir   rU   r[   s   @r   r   r      s    *I Ir   r   c                   "     e Zd ZdZ fdZ xZS )_QuadraticModela  
    Quadratic model

    This model is defined by :math:`y = \beta_0 x^2 + \beta_1 x + \beta_2`

    Examples
    --------
    We can calculate orthogonal distance regression with a quadratic model:

    >>> from scipy import odr
    >>> import numpy as np
    >>> x = np.linspace(0.0, 5.0)
    >>> y = 1.0 * x ** 2 + 2.0 * x + 3.0
    >>> data = odr.Data(x, y)
    >>> odr_obj = odr.ODR(data, odr.quadratic)
    >>> output = odr_obj.run()
    >>> print(output.beta)
    [1. 2. 3.]

    c           
      V    t         |   t        t        t        t
        dddd       y )N	Quadraticzy = B_0*x**2 + B_1*x + B_2z&$y = \beta_0 x^2 + \beta_1 x + \beta_2rH   ri   )rP   rQ   rw   ry   r|   r~   rR   s    r   rQ   z_QuadraticModel.__init__3  s.    iy9%5GI 	 	Jr   rU   r[   s   @r   r   r     rj   r   r   )"rY   numpyr   scipy.odr._odrpackr   __all__r   r    r#   r*   r/   r2   r4   r:   r=   r?   rD   rF   r   r   rf   r   rl   rn   rs   ru   rw   ry   r|   r~   r   r   r   r   r]   r   r   <module>r      s     $!
$75##
H H>  !:'zJ J<  !*$Ie I< 	Je J< 	r   