
    ^Mhx                     ^   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!dS )!zI Collection of Model instances for use with the odrpack fitting package.
    N)Model)r   exponentialmultilinear	unilinear	quadratic
polynomialc                     | d         | dd          }}|j         d         df|_         |||z                      d          z   S Nr      axis)shapesum)Bxabs       Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/odr/_models.py_lin_fcnr   
   sE    Q4122qAwqz1oAG!yyay        c                     t          j        |j        d         t                    }t          j        ||                                f          }| j        d         |j        d         f|_        |S N)nponesr   floatconcatenateravel)r   r   r   ress       r   _lin_fjbr       sQ    
U##A
.!QWWYY
(
(Cagbk*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
	!agbk^AGBK/a888AgAG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*      sG    
 46<AFLO7A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/   ,   sS    Q4122qAwqz1oAGrva"(1f---A66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5(1f--24 5 5Cagbk*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   :   sS    	!""Awqz1oAG	F
A6!bhq&(+++!4444r   c                 N    | d         t          j        | d         |z            z   S Nr   r   r   expr   r   s     r   _exp_fcnr:   C   #    Q4"&1""""r   c                 N    | 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   sV    
."'!'"+u55q26!A$(;K;K7KL
M
MCAGBK CIJr   c                 .    t          j        ddg          S )N      ?)r   arrayr(   s    r   _exp_estrD   Q   s    8R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           
          t                                          t          t          t          t
          dddd           d S )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   sQ    HHx8;EG G 	 	H 	H 	H 	H 	Hr   __name__
__module____qualname____doc__rQ   __classcell__rT   s   @r   rF   rF   V   sK         ,H H H H H H H H Hr   rF   c                 4   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    w{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 ZF|r1fqj))KK#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           
          t                                          t          t          t          t
          dddd           d S )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__   sQ    "*'4&=)GI I 	 	J 	J 	J 	J 	Jr   rU   r[   s   @r   rf   rf      K         *J J J J J J J J Jr   rf   c                 *    || d         z  | d         z   S r6   r]   r9   s     r   _unilinrl      s    QqT6AaD=r   c                 R    t          j        |j        t                    | d         z  S )Nr   )r   r   r   r   r9   s     r   _unilin_fjdrn      s    717E""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      s6    >1bgagu55677DDJKr   c                     dS )N)rA   rA   r]   rC   s    r   _unilin_estru      s    8r   c                 B    ||| d         z  | d         z   z  | d         z   S )Nr   r   r&   r]   r9   s     r   
_quadraticrw      s&    a!fqtmqt##r   c                 0    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2717E#:#:;<<DDJKr   c                     dS )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           
          t                                          t          t          t          t
          dddd           d S )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__  sQ    ;"-':&9)FH H 	 	I 	I 	I 	I 	Ir   rU   r[   s   @r   r   r      sK         *I I I I I I I 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           
          t                                          t          t          t          t
          dddd           d S )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  sQ    iy9%5GI I 	 	J 	J 	J 	J 	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      su        $ $ $ $ $ $  ! ! !    
$ 
$ 
$7 7 7  5 5 5# # ## # #    
H H H H H H H H>  !!:' :' :'zJ J J J J J J J<  !!  * * *    $ $ $      I I I I Ie I I I< O	J J J J Je J J J< O			r   