o
    Ö­jx  ã                   @   s  d Z ddlZddlmZ g d¢Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZG dd„ deƒZeƒ Zdd„ ZG dd „ d eƒZeƒ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ ZG d1d2„ d2eƒZeƒ ZG d3d4„ d4eƒZ e ƒ Z!dS )5zI Collection of Model instances for use with the odrpack fitting package.
é    N)ÚModel)r   ÚexponentialÚmultilinearÚ	unilinearÚ	quadraticÚ
polynomialc                 C   s:   | d | dd … }}|j d df|_ ||| jdd� S ©Nr   é   ©Úaxis)ÚshapeÚsum)ÚBÚxÚaÚb© r   úN/var/www/html/CropPilot/venv/lib/python3.10/site-packages/scipy/odr/_models.pyÚ_lin_fcn
   s   r   c                 C   s>   t  |jd t¡}t  || ¡ f¡}| jd |jd f|_|S ©Néÿÿÿÿ)ÚnpÚonesr   ÚfloatÚconcatenateÚravel)r   r   r   Úresr   r   r   Ú_lin_fjb   s   r   c                 C   s:   | dd … }t j||jd f|jd  dd�}|j|_|S )Nr	   r   r   r
   )r   Úrepeatr   )r   r   r   r   r   r   Ú_lin_fjd   s   "r   c                 C   s4   t | jjƒdkr| jjd }nd}t |d ft¡S ©Né   r   r	   )Úlenr   r   r   r   r   )ÚdataÚmr   r   r   Ú_lin_est   s   r%   c                 C   sD   | d | dd … }}|j d df|_ |tj|t ||¡ dd� S r   ©r   r   r   Úpower)r   r   Úpowersr   r   r   r   r   Ú	_poly_fcn,   s   r)   c                 C   s@   t  t  |jd t¡t  ||¡jf¡}| jd |jd f|_|S r   )r   r   r   r   r   r'   Úflat)r   r   r(   r   r   r   r   Ú_poly_fjacb3   s
   ÿr+   c                 C   sB   | dd … }|j d df|_ || }tj|t ||d ¡ dd�S )Nr	   r   r
   r&   )r   r   r(   r   r   r   r   Ú_poly_fjacd:   s   r,   c                 C   s   | d t  | d | ¡ S ©Nr   r	   ©r   Úexp©r   r   r   r   r   Ú_exp_fcnC   ó   r1   c                 C   s   | d t  | d | ¡ S )Nr	   r.   r0   r   r   r   Ú_exp_fjdG   r2   r3   c                 C   sB   t  t  |jd t¡|t  | d | ¡ f¡}d|jd f|_|S )Nr   r	   r!   )r   r   r   r   r   r/   )r   r   r   r   r   r   Ú_exp_fjbK   s   .r4   c                 C   s   t  ddg¡S )Nç      ð?)r   Úarray©r#   r   r   r   Ú_exp_estQ   ó   r8   c                       ó    e Zd ZdZ‡ fdd„Z‡  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 ƒ jttttd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__r   r   rF   m   ó   þ
þz_MultilinearModel.__init__©Ú__name__Ú
__module__Ú__qualname__Ú__doc__rF   Ú__classcell__r   r   rI   r   r;   V   s    r;   c                 C   sx   t  | ¡}|jdkrt  d|d ¡}t|ƒdf|_t|ƒd }|fdd„}tttt||fdd|d  d|d  dœ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   r	   c                 S   s   t  |ft¡S )N)r   r   r   )r#   Úlen_betar   r   r   Ú	_poly_est©   r9   zpolynomial.<locals>._poly_estz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$r=   )rB   rA   rC   Ú
extra_argsrD   )	r   Úasarrayr   Úaranger"   r   r)   r,   r+   )Úorderr(   rR   rS   r   r   r   r   x   s   
)

ÿþþr   c                       r:   )Ú_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              	      r<   )NÚExponentialzy= B_0 + exp(B_1 * x)z$y=\beta_0 + e^{\beta_1 x}$r=   ©rB   rA   rC   rD   )rE   rF   r1   r3   r4   r8   rG   rI   r   r   rF   Ë   ó   þ
þz_ExponentialModel.__init__rL   r   r   rI   r   rX   µ   ó    rX   c                 C   s   || d  | d  S r-   r   r0   r   r   r   Ú_unilinÖ   s   r]   c                 C   s   t  |jt¡| d  S )Nr   )r   r   r   r   r0   r   r   r   Ú_unilin_fjdÚ   s   r^   c                 C   s(   t  |t  |jt¡f¡}d|j |_|S )N)r!   ©r   r   r   r   r   ©r   r   Ú_retr   r   r   Ú_unilin_fjbÞ   s   rb   c                 C   ó   dS )N)r5   r5   r   r7   r   r   r   Ú_unilin_estå   ó   rd   c                 C   s    ||| d  | d   | d  S )Nr   r	   r!   r   r0   r   r   r   Ú
_quadraticé   s    rf   c                 C   s   d| | d  | d  S r    r   r0   r   r   r   Ú	_quad_fjdí   s   rg   c                 C   s.   t  || |t  |jt¡f¡}d|j |_|S )N)é   r_   r`   r   r   r   Ú	_quad_fjbñ   s   ri   c                 C   rc   )N)r5   r5   r5   r   r7   r   r   r   Ú	_quad_estø   re   rj   c                       r:   )Ú_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              	      r<   )NzUnivariate Linearzy = B_0 * x + B_1z$y = \beta_0 x + \beta_1$r=   rZ   )rE   rF   r]   r^   rb   rd   rG   rI   r   r   rF     r[   z_UnilinearModel.__init__rL   r   r   rI   r   rk   ü   r\   rk   c                       r:   )Ú_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              	      r<   )NÚ	Quadraticzy = B_0*x**2 + B_1*x + B_2z&$y = \beta_0 x^2 + \beta_1 x + \beta_2r=   rZ   )rE   rF   rf   rg   ri   rj   rG   rI   r   r   rF   3  rK   z_QuadraticModel.__init__rL   r   r   rI   r   rl     r\   rl   )"rP   Únumpyr   Úscipy.odr._odrpackr   Ú__all__r   r   r   r%   r)   r+   r,   r1   r3   r4   r8   r;   r   r   rX   r   r]   r^   rb   rd   rf   rg   ri   rj   rk   r   rl   r   r   r   r   r   Ú<module>   s@    	=
