o
    h                     @   sn   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m	Z	 d dl
mZmZ dgZG dd deZdS )	    N)Tensor)constraints)ExponentialFamily)_standard_normalbroadcast_all)_Number_sizeNormalc                       s   e Zd ZdZejejdZejZdZ	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$ fdd	Zd$ fdd	Ze fddZe fdedefddZdd Zdd Zdd Zdd Zedeeef fd d!Zd"d# Z  ZS )%r	   a+  
    Creates a normal (also called Gaussian) distribution parameterized by
    :attr:`loc` and :attr:`scale`.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = Normal(torch.tensor([0.0]), torch.tensor([1.0]))
        >>> m.sample()  # normally distributed with loc=0 and scale=1
        tensor([ 0.1046])

    Args:
        loc (float or Tensor): mean of the distribution (often referred to as mu)
        scale (float or Tensor): standard deviation of the distribution
            (often referred to as sigma)
    )locscaleTr   returnc                 C      | j S Nr
   self r   n/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torch/distributions/normal.pymean&      zNormal.meanc                 C   r   r   r   r   r   r   r   mode*   r   zNormal.modec                 C   r   r   )r   r   r   r   r   stddev.   r   zNormal.stddevc                 C   s   | j dS N   )r   powr   r   r   r   variance2   s   zNormal.varianceNc                    sN   t ||\| _| _t|trt|trt }n| j }t j	||d d S )Nvalidate_args)
r   r
   r   
isinstancer   torchSizesizesuper__init__)r   r
   r   r   batch_shape	__class__r   r   r#   6   s
   

zNormal.__init__c                    sR   |  t|}t|}| j||_| j||_tt|j|dd | j	|_	|S )NFr   )
_get_checked_instancer	   r   r    r
   expandr   r"   r#   _validate_args)r   r$   	_instancenewr%   r   r   r(   >   s   
zNormal.expandc                 C   sR   |  |}t  t| j|| j|W  d    S 1 s"w   Y  d S r   )_extended_shaper   no_gradnormalr
   r(   r   )r   sample_shapeshaper   r   r   sampleG   s   

$zNormal.sampler/   c                 C   s0   |  |}t|| jj| jjd}| j|| j  S )N)dtypedevice)r,   r   r
   r2   r3   r   )r   r/   r0   epsr   r   r   rsampleL   s   
zNormal.rsamplec                 C   sn   | j r| | | jd }t| jtrt| jn| j }|| j d  d|  | ttdtj	  S r   )
r)   _validate_sampler   r   r   mathlogr
   sqrtpi)r   valuevar	log_scaler   r   r   log_probQ   s   


zNormal.log_probc                 C   s<   | j r| | ddt|| j | j  td   S )N      ?   r   )	r)   r6   r   erfr
   r   
reciprocalr7   r9   r   r;   r   r   r   cdfa   s
   
&z
Normal.cdfc                 C   s(   | j | jtd| d  td  S )Nr   r@   )r
   r   r   erfinvr7   r9   rC   r   r   r   icdfh      (zNormal.icdfc                 C   s$   ddt dt j   t| j S )Nr?   r   )r7   r8   r:   r   r   r   r   r   r   entropyk   s   $zNormal.entropyc                 C   s&   | j | jd d| jd  fS )Nr   g      )r
   r   r   rB   r   r   r   r   _natural_paramsn   s   &zNormal._natural_paramsc                 C   s(   d| d | dttj |   S )Ng      пr   r?   )r   r   r8   r7   r:   )r   xyr   r   r   _log_normalizerr   rG   zNormal._log_normalizerr   ) __name__
__module____qualname____doc__r   realpositivearg_constraintssupporthas_rsample_mean_carrier_measurepropertyr   r   r   r   r   r#   r(   r   r    r1   r   r5   r>   rD   rF   rH   tuplerI   rL   __classcell__r   r   r%   r   r	      s2    	)r7   r   r   torch.distributionsr   torch.distributions.exp_familyr   torch.distributions.utilsr   r   torch.typesr   r   __all__r	   r   r   r   r   <module>   s   