o
    eiN
                     @   sj   d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ dgZG dd de	ZdS )	    N)infTensor)constraints)Cauchy)TransformedDistribution)AbsTransform
HalfCauchyc                       s   e Zd ZU dZdejiZejZdZ	e
ed< 	ddeeB dedB ddf fdd	Zd fd
d	ZedefddZedefddZedefddZedefddZdd Zdd Zdd Zdd Z  ZS )r   a  
    Creates a half-Cauchy distribution parameterized by `scale` where::

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

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> 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
    scaleT	base_distNvalidate_argsreturnc                    s&   t d|dd}t j|t |d d S )Nr   F)r   )r   super__init__r   )selfr	   r   r
   	__class__ i/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/distributions/half_cauchy.pyr   (   s   zHalfCauchy.__init__c                    s   |  t|}t j||dS )N)	_instance)_get_checked_instancer   r   expand)r   batch_shaper   newr   r   r   r   0   s   zHalfCauchy.expandc                 C      | j jS N)r
   r	   r   r   r   r   r	   4      zHalfCauchy.scalec                 C   s    t j|  tj| jj| jjdS )Ndtypedevice)torchfull_extended_shapemathr   r	   r   r   r   r   r   r   mean8   s   zHalfCauchy.meanc                 C   s   t | jS r   )r    
zeros_liker	   r   r   r   r   modeA   s   zHalfCauchy.modec                 C   r   r   )r
   variancer   r   r   r   r'   E   r   zHalfCauchy.variancec                 C   sZ   | j r| | tj|| jjj| jjjd}| j|t	
d }t|dk|t }|S )Nr      r   )_validate_args_validate_sampler    	as_tensorr
   r	   r   r   log_probr#   logwherer   )r   valuer,   r   r   r   r,   I   s   
zHalfCauchy.log_probc                 C   s$   | j r| | d| j| d S )Nr(      )r)   r*   r
   cdf)r   r/   r   r   r   r1   S   s   
zHalfCauchy.cdfc                 C   s   | j |d d S )Nr0   r(   )r
   icdf)r   probr   r   r   r2   X      zHalfCauchy.icdfc                 C   s   | j  td S )Nr(   )r
   entropyr#   r-   r   r   r   r   r5   [   r4   zHalfCauchy.entropyr   )__name__
__module____qualname____doc__r   positivearg_constraintsnonnegativesupporthas_rsampler   __annotations__r   floatboolr   r   propertyr	   r$   r&   r'   r,   r1   r2   r5   __classcell__r   r   r   r   r      s6   
 

)r#   r    r   r   torch.distributionsr   torch.distributions.cauchyr   ,torch.distributions.transformed_distributionr   torch.distributions.transformsr   __all__r   r   r   r   r   <module>   s   