U
    md                     @   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

	=	<