U
    Kvfp                     @   s6   d Z ddlZddlmZ d
ddZG dd	 d	eZdS )zc Extreme Value Copulas
Created on Fri Jan 29 19:19:45 2021

Author: Josef Perktold
License: BSD-3

    N   )Copula c              	   C   s>   | \} }t t | | |t | t | |  f|  S )z+generic bivariate extreme value copula
    )npexplog)u	transformargsvr   r   R/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/distributions/copula/extreme_value.pycopula_bv_ev   s    r   c                       sZ   e Zd ZdZd fdd	Zdd Zddd	Zdd
dZdddZdddZ	dd Z
  ZS )ExtremeValueCopulaaS  Extreme value copula constructed from Pickand's dependence function.

    Currently only bivariate copulas are available.

    Parameters
    ----------
    transform: instance of transformation class
        Pickand's dependence function with required methods including first
        and second derivatives
    args : tuple
        Optional copula parameters. Copula parameters can be either provided
        when creating the instance or as arguments when calling methods.
    k_dim : int
        Currently only bivariate extreme value copulas are supported.

    Notes
    -----
    currently the following dependence function and copulas are available

    - AsymLogistic
    - AsymNegLogistic
    - AsymMixed
    - HR

    TEV and AsymBiLogistic currently do not have required derivatives for pdf.

    See Also
    --------
    dep_func_ev

    r      c                    s6   t  j|d || _|j| _|| _|dkr2tdd S )N)k_dimr   z(Only bivariate EV copulas are available.)super__init__r	   Zk_argsr
   
ValueError)selfr	   r
   r   	__class__r   r   r   6   s    zExtremeValueCopula.__init__c                 C   s>   t |tjrt|}|dks$|d kr*| j}t |ts:|f}|S )Nr   )
isinstancer   Zndarraytupler
   )r   r
   r   r   r   _handle_args>   s    
zExtremeValueCopula._handle_argsc              	   C   sV   t |j\}}| |}t t || | jt |t ||  f|  }|S )aJ  Evaluate cdf of bivariate extreme value copula.

        Parameters
        ----------
        u : array_like
            Values of random bivariate random variable, each defined on [0, 1],
            for which cdf is computed.
            Can be two dimensional with multivariate components in columns and
            observation in rows.
        args : tuple
            Required parameters for the copula. The meaning and number of
            parameters in the tuple depends on the specific copula.

        Returns
        -------
        CDF values at evaluation points.
        )r   asarrayTr   r   r   r	   )r   r   r
   r   Zcdfvr   r   r   cdfJ   s    
"zExtremeValueCopula.cdfc                 C   s   | j }t|j\}}| |}t|| }t|| }| ||}||f| }	|j|f| }
|j|f| }|||  |	d| |
  |	||
   |d|  | |   }|S )aJ  Evaluate pdf of bivariate extreme value copula.

        Parameters
        ----------
        u : array_like
            Values of random bivariate random variable, each defined on [0, 1],
            for which cdf is computed.
            Can be two dimensional with multivariate components in columns and
            observation in rows.
        args : tuple
            Required parameters for the copula. The meaning and number of
            parameters in the tuple depends on the specific copula.

        Returns
        -------
        PDF values at evaluation points.
        r   )	r	   r   r   r   r   r   r   ZderivZderiv2)r   r   r
   tru1u2Zlog_u12tr   depd1Zd2Zpdf_r   r   r   pdfc   s    
$zExtremeValueCopula.pdfc                 C   s   t | j||dS )aR  Evaluate log-pdf of bivariate extreme value copula.

        Parameters
        ----------
        u : array_like
            Values of random bivariate random variable, each defined on [0, 1],
            for which cdf is computed.
            Can be two dimensional with multivariate components in columns and
            observation in rows.
        args : tuple
            Required parameters for the copula. The meaning and number of
            parameters in the tuple depends on the specific copula.

        Returns
        -------
        Log-pdf values at evaluation points.
        )r
   )r   r   r#   r   r   r
   r   r   r   logpdf   s    zExtremeValueCopula.logpdfc                 C   s   t dS )u   conditional distribution

        not yet implemented

        C2|1(u2|u1) := ∂C(u1, u2) / ∂u1 = C(u1, u2) / u1 * (A(t) − t A'(t))

        where t = np.log(v)/np.log(u*v)
        NNotImplementedErrorr$   r   r   r   conditional_2g1   s    	z"ExtremeValueCopula.conditional_2g1c                 C   s   t d S )Nr&   )r   datar   r   r   fit_corr_param   s    z!ExtremeValueCopula.fit_corr_param)r   r   )r   )r   )r   )r   )__name__
__module____qualname____doc__r   r   r   r#   r%   r(   r*   __classcell__r   r   r   r   r      s    

!

r   )r   )r.   Znumpyr   Zcopulasr   r   r   r   r   r   r   <module>   s   
