a
    ßñhß  ã                   @   s`   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ G dd„ deƒZdS )	é    N)Úinf)Úconstraints)ÚAbsTransform)ÚCauchy)ÚTransformedDistributionc                       sˆ   e Zd ZdZdejiZejZdZd‡ fdd„	Z	d‡ fdd„	Z
ed	d
„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )Ú
HalfCauchyaz  
    Creates a half-Cauchy distribution parameterized by `scale` where::

        X ~ Cauchy(0, scale)
        Y = |X| ~ HalfCauchy(scale)

    Example::

        >>> m = HalfCauchy(torch.tensor([1.0]))
        >>> m.sample()  # half-cauchy distributed with scale=1
        tensor([ 2.3214])

    Args:
        scale (float or Tensor): scale of the full Cauchy distribution
    ÚscaleTNc                    s&   t d|ƒ}tt| ƒj|tƒ |d� d S )Nr   )Úvalidate_args)r   Úsuperr   Ú__init__r   )Úselfr   r	   Ú	base_dist©Ú	__class__© ú_/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torch/distributions/half_cauchy.pyr      s    
ÿzHalfCauchy.__init__c                    s    |   t|¡}tt| ƒj||d�S )N)Ú	_instance)Z_get_checked_instancer   r
   Úexpand)r   Zbatch_shaper   Únewr   r   r   r   $   s    zHalfCauchy.expandc                 C   s   | j jS ©N)r   r   ©r   r   r   r   r   (   s    zHalfCauchy.scalec                 C   s   | j jS r   )r   Úmeanr   r   r   r   r   ,   s    zHalfCauchy.meanc                 C   s   | j jS r   )r   Úvariancer   r   r   r   r   0   s    zHalfCauchy.variancec                 C   sL   t j|| jjj| jjjd�}| j |¡t d¡ }t	 || 
|j¡dk < |S )N)ÚdtypeÚdeviceé   r   )ÚtorchZ	as_tensorr   r   r   r   Úlog_probÚmathÚlogr   r   Úshape)r   Úvaluer   r   r   r   r   4   s    ÿzHalfCauchy.log_probc                 C   s   d| j  |¡ d S )Nr   é   )r   Úcdf)r   r!   r   r   r   r#   ;   s    zHalfCauchy.cdfc                 C   s   | j  |d d ¡S )Nr"   r   )r   Úicdf)r   Zprobr   r   r   r$   >   s    zHalfCauchy.icdfc                 C   s   | j  ¡ t d¡ S )Nr   )r   Úentropyr   r   r   r   r   r   r%   A   s    zHalfCauchy.entropy)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZpositiveZarg_constraintsZsupportZhas_rsampler   r   Úpropertyr   r   r   r   r#   r$   r%   Ú__classcell__r   r   r   r   r      s    



r   )r   r   Z
torch._sixr   Ztorch.distributionsr   Ztorch.distributions.transformsr   Ztorch.distributions.cauchyr   Z,torch.distributions.transformed_distributionr   r   r   r   r   r   Ú<module>   s   