U
    Ãmœdµ  ã                   @   s^   d Z ddlZddlmZ ddlmZ ddlmZ G dd„ deƒZ	dd
d„Z
dd„ Zdd„ ZdS )zM
Created on Fri Jan 29 19:19:45 2021

Author: Josef Perktold
License: BSD-3

é    N)Ústats)Úcheck_random_state)ÚCopulac                       sX   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„ Z	dd„ Z
‡  ZS )ÚIndependenceCopulaaà  Independence copula.

    Copula with independent random variables.

    .. math::

        C_	heta(u,v) = uv

    Parameters
    ----------
    k_dim : int
        Dimension, number of components in the multivariate random variable.

    Notes
    -----
    IndependenceCopula does not have copula parameters.
    If non-empty ``args`` are provided in methods, then a ValueError is raised.
    The ``args`` keyword is provided for a consistent interface across
    copulas.

    é   c                    s   t ƒ j|d� d S )N)Úk_dim)ÚsuperÚ__init__)Úselfr   ©Ú	__class__© úg/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/statsmodels/distributions/copula/other_copulas.pyr	   &   s    zIndependenceCopula.__init__c                 C   s&   |dkr|d k	rd}t |ƒ‚n|S d S )Nr   z3Independence copula does not use copula parameters.)Ú
ValueError)r
   ÚargsÚmsgr   r   r   Ú_handle_args)   s    
zIndependenceCopula._handle_argsé   r   Nc                 C   s&   |   |¡ t|ƒ}| || jf¡}|S )N)r   r   Úrandomr   )r
   Znobsr   Zrandom_stateÚrngÚxr   r   r   Úrvs0   s    
zIndependenceCopula.rvsc                 C   s   t  |¡}t  |jd d… ¡S )Néÿÿÿÿ)ÚnpZasarrayZonesÚshape©r
   Úur   r   r   r   Úpdf6   s    
zIndependenceCopula.pdfc                 C   s   t j|dd�S )Nr   )Zaxis)r   Úprodr   r   r   r   Úcdf:   s    zIndependenceCopula.cdfc                 C   s   dS )Nr   r   )r
   r   r   r   Útau=   s    zIndependenceCopula.tauc                 G   s   t dƒ‚d S )Nz PDF is constant over the domain.)ÚNotImplementedError)r
   r   r   r   r   Úplot_pdf@   s    zIndependenceCopula.plot_pdf)r   )r   r   N)r   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r    r"   Ú__classcell__r   r   r   r   r      s   


r   r   Fc           	         sb   | j d }|dkrt‰tjjd||d�}| | }t ‡ ‡fdd„|jD ƒ¡}|rZ|||fS |S dS )a…  Random sampling from empirical copula using Beta distribution

    Parameters
    ----------
    sample : ndarray
        Sample of multivariate observations in (o, 1) interval.
    size : int
        Number of observations to simulate.
    bw : float
        Bandwidth for Beta sampling. The beta copula corresponds to a kernel
        estimate of the distribution. bw=1 corresponds to the empirical beta
        copula. A small bandwidth like bw=0.001 corresponds to small noise
        added to the empirical distribution. Larger bw, e.g. bw=10 corresponds
        to kernel estimate with more smoothing.
    k_func : None or callable
        The default kernel function is currently a beta function with 1 added
        to the first beta parameter.
    return_extras : bool
        If this is False, then only the random sample will be returned.
        If true, then extra information is returned that is mainly of interest
        for verification.

    Returns
    -------
    rvs : ndarray
        Multivariate sample with ``size`` observations drawn from the Beta
        Copula.

    Notes
    -----
    Status: experimental, API will change.
    r   N©Úsizec                    s   g | ]}ˆ|ˆ ƒ‘qS r   r   )Ú.0Zxii©ÚbwZkfuncr   r   Ú
<listcomp>k   s     zrvs_kernel.<locals>.<listcomp>)r   Ú_kernel_rvs_beta1r   r   ÚrandintZcolumn_stackÚT)	Úsampler)   r,   Zk_funcZreturn_extrasÚnÚidxÚxiZkrvsr   r+   r   Ú
rvs_kernelD   s    "

r5   c                 C   s(   t jj| | d d|  | d | jd�S )Nr   r(   )r   Úbetar   r   ©r   r,   r   r   r   Ú_kernel_rvs_betas   s    r8   c                 C   s   t j | | d|  | d ¡S )Nr   )r   r6   r   r7   r   r   r   r.   x   s    r.   )r   NF)r&   Únumpyr   Zscipyr   Zstatsmodels.tools.rng_qrngr   Z(statsmodels.distributions.copula.copulasr   r   r5   r8   r.   r   r   r   r   Ú<module>   s   4
/