B
    Zk                 @   s   d Z dZddlZeejZG dd deZ	e	 Z
de
_ G dd deZe Zd	e_ ed
dZde_ eddZde_ G dd deZe Zde_ G dd deZe Zde_ dS )zP
Variance functions for use with the link functions in statsmodels.family.links
Zrestructuredtext    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 : array
            ones(mu.shape)
        )npZasarrayZonesshapeZfloat64)selfmu r   Clib/python3.7/site-packages/statsmodels/genmod/families/varfuncs.py__call__   s    
zVarianceFunction.__call__c             C   s
   t |S )z<
        Derivative of the variance function v'(mu)
        )r   Z
zeros_like)r   r   r   r   r   deriv0   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 )Powera  
    Power variance function

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

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

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

    Notes
    -----
    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__X   s    zPower.__init__c             C   s   t t || jS )z
        Power variance function

        Parameters
        ----------
        mu : array-like
            mean parameters

        Returns
        -------
        variance : array
            numpy.fabs(mu)**self.power
        )r   r   fabs)r   r   r   r   r   r	   [   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derZiir   r   r   r
   k   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

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

    where p = mu / n

    Notes
    -----
    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 )N)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 : array
           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 )z<
        Derivative of the variance function v'(mu)
        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

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

    Notes
    -----
    Alias for NegativeBinomial:
    nbinom = NegativeBinomial()

    A private method _clean trims the data by machine epsilon so that p is
    in (0,inf)
          ?c             C   s
   || _ d S )N)alpha)r   r    r   r   r   r      s    zNegativeBinomial.__init__c             C   s   t |tt jS )N)r   r   r   inf)r   r   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 : array
            variance = mu + alpha*mu**2
        r   )r   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   r   r   r
   
  s    
zNegativeBinomial.derivN)r   )r   r   r   r   r   r   r	   r
   r   r   r   r   r      s
   
r   zb
Negative Binomial variance function.

Notes
-----
This is an alias of NegativeBinomial(alpha=1.)
)r   Z__docformat__Znumpyr   ZfinfofloatZepsr   objectr   Zconstantr   r   Z
mu_squaredZmu_cubedr   Zbinaryr   Znbinomr   r   r   r   <module>   s&   -:

=;