Ë
    ¢�DjY  ã                   ól   — d Z ddlZddlmZ dd„Z G d„ d«      Z G d„ de«      Z G d	„ d
e«      Zdd„Z	y)z
Empirical CDF Functions
é    N)Úinterp1dc                 óê   — t        | «      }t        j                  t        j                  d|z  «      d|z  z  «      }t        j                  | |z
  dd«      }t        j                  | |z   dd«      }||fS )aü  
    Constructs a Dvoretzky-Kiefer-Wolfowitz confidence band for the eCDF.

    Parameters
    ----------
    F : array_like
        The empirical distributions
    alpha : float
        Set alpha for a (1 - alpha) % confidence band.

    Notes
    -----
    Based on the DKW inequality.

    .. math:: P \left( \sup_x \left| F(x) - \hat(F)_n(X) \right| >
       \epsilon \right) \leq 2e^{-2n\epsilon^2}

    References
    ----------
    Wasserman, L. 2006. `All of Nonparametric Statistics`. Springer.
    g       @é   r   é   )ÚlenÚnpÚsqrtÚlogÚclip)ÚFÚalphaÚnobsÚepsilonÚlowerÚuppers         útC:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\statsmodels/distributions/empirical_distribution.pyÚ	_conf_setr      sg   € ô, ˆq‹6€DÜ�g‰g”b—f‘f˜R ™XÓ&¨!¨d©(Ñ3Ó4€GÜ�G‰G�A˜‘K  AÓ&€EÜ�G‰G�A˜‘K  AÓ&€EØ�%ˆ<Ðó    c                   ó   — e Zd ZdZdd„Zd„ Zy)ÚStepFunctiona>  
    A basic step function.

    Values at the ends are handled in the simplest way possible:
    everything to the left of x[0] is set to ival; everything
    to the right of x[-1] is set to y[-1].

    Parameters
    ----------
    x : array_like
    y : array_like
    ival : float
        ival is the value given to the values to the left of x[0]. Default
        is 0.
    sorted : bool
        Default is False.
    side : {'left', 'right'}, optional
        Default is 'left'. Defines the shape of the intervals constituting the
        steps. 'right' correspond to [a, b) intervals and 'left' to (a, b].

    Examples
    --------
    >>> import numpy as np
    >>> from statsmodels.distributions.empirical_distribution import (
    >>>     StepFunction)
    >>>
    >>> x = np.arange(20)
    >>> y = np.arange(20)
    >>> f = StepFunction(x, y)
    >>>
    >>> print(f(3.2))
    3.0
    >>> print(f([[3.2,4.5],[24,-3.1]]))
    [[  3.   4.]
     [ 19.   0.]]
    >>> f2 = StepFunction(x, y, side='right')
    >>>
    >>> print(f(3.0))
    2.0
    >>> print(f2(3.0))
    3.0
    c                 óÖ  — |j                  «       dvrd}t        |«      ‚|| _        t        j                  |«      }t        j                  |«      }|j
                  |j
                  k7  rd}t        |«      ‚t        |j
                  «      dk7  rd}t        |«      ‚t        j                  t        j                   |f   | _	        t        j                  ||f   | _
        |skt        j                  | j                  «      }	t        j                  | j                  |	d«      | _	        t        j                  | j                  |	d«      | _
        | j                  j
                  d   | _        y )N)ÚrightÚleftz*side can take the values 'right' or 'left'z"x and y do not have the same shaper   zx and y must be 1-dimensionalr   )r   Ú
ValueErrorÚsider   ÚasarrayÚshaper   Úr_ÚinfÚxÚyÚargsortÚtakeÚn)
Úselfr    r!   ÚivalÚsortedr   ÚmsgÚ_xÚ_yÚasorts
             r   Ú__init__zStepFunction.__init__Q   s  € à�:‰:‹<Ð0Ñ0Ø>ˆCÜ˜S“/Ð!ØˆŒ	ä�Z‰Z˜‹]ˆÜ�Z‰Z˜‹]ˆà�8‰8�r—x‘xÒØ6ˆCÜ˜S“/Ð!Üˆr�x‰x‹=˜AÒØ1ˆCÜ˜S“/Ð!ä—‘œŸ™�w �{Ñ#ˆŒÜ—‘�t˜R�x‘ˆŒáÜ—J‘J˜tŸv™vÓ&ˆEÜ—W‘W˜TŸV™V U¨AÓ.ˆDŒFÜ—W‘W˜TŸV™V U¨AÓ.ˆDŒFØ—‘—‘˜a‘ˆ�r   c                 ó|   — t        j                  | j                  || j                  «      dz
  }| j                  |   S )Nr   )r   Úsearchsortedr    r   r!   )r%   ÚtimeÚtinds      r   Ú__call__zStepFunction.__call__k   s/   € ä�‰˜tŸv™v t¨T¯Y©YÓ7¸!Ñ;ˆØ�v‰v�d‰|Ðr   N)g        Fr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r,   r1   © r   r   r   r   %   s   „ ñ)óV!ó4r   r   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚECDFa…  
    Return the Empirical CDF of an array as a step function.

    Parameters
    ----------
    x : array_like
        Observations
    side : {'left', 'right'}, optional
        Default is 'right'. Defines the shape of the intervals constituting the
        steps. 'right' correspond to [a, b) intervals and 'left' to (a, b].

    Returns
    -------
    Empirical CDF as a step function.

    Examples
    --------
    >>> import numpy as np
    >>> from statsmodels.distributions.empirical_distribution import ECDF
    >>>
    >>> ecdf = ECDF([3, 3, 1, 4])
    >>>
    >>> ecdf([3, 55, 0.5, 1.5])
    array([ 0.75,  1.  ,  0.  ,  0.25])
    c                 óÄ   •— t        j                  |d¬«      }|j                  «        t        |«      }t        j                  d|z  d|«      }t
        ‰| �  |||d¬«       y )NT)Úcopyg      ð?r   ©r   r'   )r   ÚarrayÚsortr   ÚlinspaceÚsuperr,   )r%   r    r   r   r!   Ú	__class__s        €r   r,   zECDF.__init__‹   sQ   ø€ Ü�H‰H�Q˜TÔ"ˆØ	�‰ŒÜ�1‹vˆÜ�K‰K˜˜4™  DÓ)ˆÜ‰Ñ˜˜A D°ÐÕ6r   )r   ©r2   r3   r4   r5   r,   Ú__classcell__©r@   s   @r   r8   r8   q   s   ø„ ñ÷27ñ 7r   r8   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚECDFDiscreteaZ  
    Return the Empirical Weighted CDF of an array as a step function.

    Parameters
    ----------
    x : array_like
        Data values. If freq_weights is None, then x is treated as observations
        and the ecdf is computed from the frequency counts of unique values
        using nunpy.unique.
        If freq_weights is not None, then x will be taken as the support of the
        mass point distribution with freq_weights as counts for x values.
        The x values can be arbitrary sortable values and need not be integers.
    freq_weights : array_like
        Weights of the observations.  sum(freq_weights) is interpreted as nobs
        for confint.
        If freq_weights is None, then the frequency counts for unique values
        will be computed from the data x.
    side : {'left', 'right'}, optional
        Default is 'right'. Defines the shape of the intervals constituting the
        steps. 'right' correspond to [a, b) intervals and 'left' to (a, b].

    Returns
    -------
    Weighted ECDF as a step function.

    Examples
    --------
    >>> import numpy as np
    >>> from statsmodels.distributions.empirical_distribution import (
    >>>     ECDFDiscrete)
    >>>
    >>> ewcdf = ECDFDiscrete([3, 3, 1, 4])
    >>> ewcdf([3, 55, 0.5, 1.5])
    array([0.75, 1.  , 0.  , 0.25])
    >>>
    >>> ewcdf = ECDFDiscrete([3, 1, 4], [1.25, 2.5, 5])
    >>>
    >>> ewcdf([3, 55, 0.5, 1.5])
    array([0.42857143, 1., 0. , 0.28571429])
    >>> print('e1 and e2 are equivalent ways of defining the same ECDF')
    e1 and e2 are equivalent ways of defining the same ECDF
    >>> e1 = ECDFDiscrete([3.5, 3.5, 1.5, 1, 4])
    >>> e2 = ECDFDiscrete([3.5, 1.5, 1, 4], freq_weights=[2, 1, 1, 1])
    >>> print(e1.x, e2.x)
    [-inf  1.   1.5  3.5  4. ] [-inf  1.   1.5  3.5  4. ]
    >>> print(e1.y, e2.y)
    [0.  0.2 0.4 0.8 1. ] [0.  0.2 0.4 0.8 1. ]
    c                 óˆ  •— |€t        j                  |d¬«      \  }}nt        j                  |«      }t        |«      t        |«      k(  sJ ‚t        j                  |«      }t        j                  |«      }|dkD  sJ ‚|j                  «       }||   }t        j                  ||   «      }||z  }t        ‰| �!  |||d¬«       y )NT)Úreturn_countsr   r;   )	r   Úuniquer   r   Úsumr"   Úcumsumr?   r,   )	r%   r    Úfreq_weightsr   ÚwÚswÚaxr!   r@   s	           €r   r,   zECDFDiscrete.__init__Ê   s§   ø€ ØÐÜ Ÿi™i¨¸Ô>‰OˆA‰|ä—
‘
˜1“ˆAÜ�<Ó ¤C¨£FÒ*Ñ*Ü�J‰J�|Ó$ˆÜ�V‰V�A‹YˆØ�AŠv‰Ø�Y‰Y‹[ˆØˆb‰EˆÜ�I‰I�a˜‘eÓˆØ�‰FˆÜ‰Ñ˜˜A D°ÐÕ6r   )Nr   rA   rC   s   @r   rE   rE   ™   s   ø„ ñ/÷`7ñ 7r   rE   c                 óþ   — t        j                  |«      }|r
 | |fi |¤Ž}n6g }|D ]  }|j                   | |fi |¤Ž«       Œ t        j                  |«      }t        j                  |«      }t        ||   ||   «      S )zÅ
    Given a monotone function fn (no checking is done to verify monotonicity)
    and a set of x values, return an linearly interpolated approximation
    to its inverse from its values on x.
    )r   r   Úappendr<   r"   r   )Úfnr    Ú
vectorizedÚkeywordsr!   r)   Úas          r   Úmonotone_fn_inverterrU   Ú   s|   € ô 	�
‰
�1‹€AÙÙˆqÑ�HÑ‰àˆØò 	)ˆBØ�H‰H‘R˜Ñ'˜hÑ'Õ(ð	)ä�H‰H�Q‹Kˆä
�
‰
�1‹€Aä�A�a‘D˜!˜A™$ÓÐr   )gš™™™™™©?)T)
r5   Únumpyr   Úscipy.interpolater   r   r   r8   rE   rU   r6   r   r   ú<module>rX      sC   ðñó Ý &ó÷:Iñ IôX7ˆ<ô 7ôP>7�<ô >7ôB r   