o
    ‡ZŽh½  ã                   @   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)ÚNormal)ÚTransformedDistribution)ÚAbsTransformÚ
HalfNormalc                       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	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-normal distribution parameterized by `scale` where::

        X ~ Normal(0, scale)
        Y = |X| ~ HalfNormal(scale)

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = HalfNormal(torch.tensor([1.0]))
        >>> m.sample()  # half-normal distributed with scale=1
        tensor([ 0.1046])

    Args:
        scale (float or Tensor): scale of the full Normal distribution
    ÚscaleTNc                    s&   t d|dd}tƒ j|tƒ |d d S )Nr   F)Úvalidate_args)r   ÚsuperÚ__init__r   )Úselfr	   r
   Ú	base_dist©Ú	__class__© úN/var/www/auris/lib/python3.10/site-packages/torch/distributions/half_normal.pyr   %   s   zHalfNormal.__init__c                    s   |   t|¡}tƒ j||dS )N)Ú	_instance)Z_get_checked_instancer   r   Úexpand)r   Zbatch_shaper   Únewr   r   r   r   )   s   zHalfNormal.expandÚreturnc                 C   s   | j jS ©N)r   r	   ©r   r   r   r   r	   -   s   zHalfNormal.scalec                 C   s   | j t dtj ¡ S ©Né   )r	   ÚmathÚsqrtÚpir   r   r   r   Úmean1   s   zHalfNormal.meanc                 C   s   t  | j¡S r   )ÚtorchZ
zeros_liker	   r   r   r   r   Úmode5   s   zHalfNormal.modec                 C   s   | j  d¡ddtj   S ©Nr   é   )r	   Úpowr   r   r   r   r   r   Úvariance9   s   zHalfNormal.variancec                 C   s>   | j r|  |¡ | j |¡t d¡ }t |dk|t ¡}|S )Nr   r   )	Ú_validate_argsÚ_validate_sampler   Úlog_probr   Úlogr   Úwherer   )r   Úvaluer'   r   r   r   r'   =   s
   
zHalfNormal.log_probc                 C   s$   | j r|  |¡ d| j |¡ d S r!   )r%   r&   r   Úcdf)r   r*   r   r   r   r+   D   s   
zHalfNormal.cdfc                 C   s   | j  |d d ¡S )Nr"   r   )r   Úicdf)r   Zprobr   r   r   r,   I   ó   zHalfNormal.icdfc                 C   s   | j  ¡ t d¡ S r   )r   Úentropyr   r(   r   r   r   r   r.   L   r-   zHalfNormal.entropyr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZpositiveZarg_constraintsZnonnegativeZsupportZhas_rsampler   r   Úpropertyr   r	   r   r    r$   r'   r+   r,   r.   Ú__classcell__r   r   r   r   r      s&    
)r   r   r   r   Ztorch.distributionsr   Ztorch.distributions.normalr   Z,torch.distributions.transformed_distributionr   Ztorch.distributions.transformsr   Ú__all__r   r   r   r   r   Ú<module>   s   