U
    Kvf                     @   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__ R/tmp/pip-unpacked-wheel-2v6byqio/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&   Znumpyr   Zscipyr   Zstatsmodels.tools.rng_qrngr   Z(statsmodels.distributions.copula.copulasr   r   r5   r8   r.   r   r   r   r   <module>   s   4
/