3
O4W^฿  ใ               @   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-normal 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__ฉ ๚@/tmp/pip-build-e66j97b2/torch/torch/distributions/half_cauchy.pyr      s    
zHalfCauchy.__init__c                s    | j t|}tt| j||dS )N)ฺ	_instance)Z_get_checked_instancer   r
   ฺexpand)r   Zbatch_shaper   ฺnew)r   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 )N)r   ฺmean)r   r   r   r   r   ,   s    zHalfCauchy.meanc             C   s   | j jS )N)r   ฺvariance)r   r   r   r   r   0   s    zHalfCauchy.variancec             C   sL   t j|| jjj| jjjd}| jj|tjd }t	 ||j
|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 j| d S )Nr   ้   )r   ฺcdf)r   r   r   r   r   r    ;   s    zHalfCauchy.cdfc             C   s   | j j|d d S )Nr   r   )r   ฺicdf)r   Zprobr   r   r   r!   >   s    zHalfCauchy.icdfc             C   s   | j j tj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   