U
    Ãmœd  ã                   @   s¤   d Z ddlZe e¡jZG dd„ dƒZeƒ Zde_ G dd„ dƒZ	e	ƒ Z
de
_ e	d	d
�Zde_ e	dd
�Zde_ G dd„ dƒZeƒ Zde_ G dd„ dƒZeƒ Zde_ dS )zP
Variance functions for use with the link functions in statsmodels.family.links
é    Nc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚVarianceFunctiona–  
    Relates the variance of a random variable to its mean. Defaults to 1.

    Methods
    -------
    call
        Returns an array of ones that is the same shape as `mu`

    Notes
    -----
    After a variance function is initialized, its call method can be used.

    Alias for VarianceFunction:
    constant = VarianceFunction()

    See Also
    --------
    statsmodels.genmod.families.family
    c                 C   s   t  |¡}t  |jt j¡S )zÖ
        Default variance function

        Parameters
        ----------
        mu : array_like
            mean parameters

        Returns
        -------
        v : ndarray
            ones(mu.shape)
        )ÚnpZasarrayZonesÚshapeZfloat64©ÚselfÚmu© r   ú]/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/statsmodels/genmod/families/varfuncs.pyÚ__call__   s    
zVarianceFunction.__call__c                 C   s
   t  |¡S )ú<
        Derivative of the variance function v'(mu)
        )r   Z
zeros_liker   r   r   r	   Úderiv.   s    zVarianceFunction.derivN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r	   r      s   r   z~
The call method of constant returns a constant variance, i.e., a vector of
ones.

constant is an alias of VarianceFunction()
c                   @   s*   e Zd ZdZd
dd„Zdd„ Zdd„ Zd	S )ÚPowerav  
    Power variance function

    Parameters
    ----------
    power : float
        exponent used in power variance function

    Methods
    -------
    call
        Returns the power variance

    Notes
    -----
    Formulas
       V(mu) = numpy.fabs(mu)**power

    Aliases for Power:
    mu = Power()
    mu_squared = Power(power=2)
    mu_cubed = Power(power=3)
    ç      ð?c                 C   s
   || _ d S ©N©Úpower)r   r   r   r   r	   Ú__init__W   s    zPower.__init__c                 C   s   t  t  |¡| j¡S )zç
        Power variance function

        Parameters
        ----------
        mu : array_like
            mean parameters

        Returns
        -------
        variance : ndarray
            numpy.fabs(mu)**self.power
        )r   r   Úfabsr   r   r   r	   r
   Z   s    zPower.__call__c                 C   s<   | j t |¡| j d   }t |dk ¡}||  d9  < |S )z_
        Derivative of the variance function v'(mu)

        May be undefined at zero.
        é   r   éÿÿÿÿ)r   r   r   Zflatnonzero)r   r   ZderÚiir   r   r	   r   j   s    zPower.derivN)r   )r   r   r   r   r   r
   r   r   r   r   r	   r   >   s   
r   z>
Returns np.fabs(mu)

Notes
-----
This is an alias of Power()
é   r   za
Returns np.fabs(mu)**2

Notes
-----
This is an alias of statsmodels.family.links.Power(power=2)
é   za
Returns np.fabs(mu)**3

Notes
-----
This is an alias of statsmodels.family.links.Power(power=3)
c                   @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )ÚBinomialaä  
    Binomial variance function

    Parameters
    ----------
    n : int, optional
        The number of trials for a binomial variable.  The default is 1 for
        p in (0,1)

    Methods
    -------
    call
        Returns the binomial variance

    Notes
    -----
    Formulas :

       V(mu) = p * (1 - p) * n

    where p = mu / n

    Alias for Binomial:
    binary = Binomial()

    A private method _clean trims the data by machine epsilon so that p is
    in (0,1)
    r   c                 C   s
   || _ d S r   )Ún)r   r   r   r   r	   r   ¯   s    zBinomial.__init__c                 C   s   t  |tdt ¡S )Nr   )r   ÚclipÚ	FLOAT_EPS©r   Úpr   r   r	   Ú_clean²   s    zBinomial._cleanc                 C   s"   |   || j ¡}|d|  | j S )zô
        Binomial variance function

        Parameters
        ----------
        mu : array_like
            mean parameters

        Returns
        -------
        variance : ndarray
           variance = mu/n * (1 - mu/n) * self.n
        r   )r#   r   ©r   r   r"   r   r   r	   r
   µ   s    zBinomial.__call__c                 C   s   dd|  S )r   r   r   r   r   r   r   r	   r   Ç   s    zBinomial.derivN)r   ©r   r   r   r   r   r#   r
   r   r   r   r   r	   r   ‘   s
   
r   zY
The binomial variance function for n = 1

Notes
-----
This is an alias of Binomial(n=1)
c                   @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )ÚNegativeBinomiala   
    Negative binomial variance function

    Parameters
    ----------
    alpha : float
        The ancillary parameter for the negative binomial variance function.
        `alpha` is assumed to be nonstochastic.  The default is 1.

    Methods
    -------
    call
        Returns the negative binomial variance

    Notes
    -----
    Formulas :

       V(mu) = mu + alpha*mu**2

    Alias for NegativeBinomial:
    nbinom = NegativeBinomial()

    A private method _clean trims the data by machine epsilon so that p is
    in (0,inf)
    r   c                 C   s
   || _ d S r   )Úalpha)r   r'   r   r   r	   r   ô   s    zNegativeBinomial.__init__c                 C   s   t  |tt j¡S r   )r   r   r    Úinfr!   r   r   r	   r#   ÷   s    zNegativeBinomial._cleanc                 C   s   |   |¡}|| j|d   S )zô
        Negative binomial variance function

        Parameters
        ----------
        mu : array_like
            mean parameters

        Returns
        -------
        variance : ndarray
            variance = mu + alpha*mu**2
        r   ©r#   r'   r$   r   r   r	   r
   ú   s    
zNegativeBinomial.__call__c                 C   s   |   |¡}dd| j |  S )zH
        Derivative of the negative binomial variance function.
        r   r   r)   r$   r   r   r	   r     s    
zNegativeBinomial.derivN)r   r%   r   r   r   r	   r&   Ø   s
   
r&   zb
Negative Binomial variance function.

Notes
-----
This is an alias of NegativeBinomial(alpha=1.)
)r   Únumpyr   ZfinfoÚfloatZepsr    r   Zconstantr   r   Z
mu_squaredZmu_cubedr   Úbinaryr&   Znbinomr   r   r   r	   Ú<module>   s$   -9

	=	<