o
    !i                     @   sb   d dl Z d dlmZmZ d dlZd dlmZ d dlmZ d dl	m
Z
mZ dgZG dd deZdS )    N)NumberReal)constraints)ExponentialFamily)_standard_normalbroadcast_allNormalc                       s   e Zd ZdZejejdZejZdZ	dZ
edd Zedd Zed	d
 Zedd Zd" fdd	Zd" fdd	Ze fddZe fddZdd Zdd Zdd Zdd Ze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-deterinistic")
        >>> 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   c                 C      | j S Nr	   self r   i/var/www/html/eduruby.in/lip-sync/lip-sync-env/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   variance.   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!   2   s
   

zNormal.__init__c                    sR   |  t|}t|}| j||_| j||_tt|j|dd | j	|_	|S )NFr   )
Z_get_checked_instancer   r   r   r	   expandr
   r    r!   _validate_args)r   r"   Z	_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   Zno_gradnormalr	   r%   r
   )r   sample_shapeshaper   r   r   sampleC   s   

$zNormal.samplec                 C   s0   |  |}t|| jj| jjd}| j|| j  S )N)dtypedevice)r(   r   r	   r-   r.   r
   )r   r*   r+   Zepsr   r   r   rsampleH   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varZ	log_scaler   r   r   log_probM   s   

 zNormal.log_probc                 C   s<   | j r| | ddt|| j | j  td   S )N      ?   r   )	r&   r0   r   erfr	   r
   
reciprocalr1   r3   r   r5   r   r   r   cdf[   s
   
&z
Normal.cdfc                 C   s(   | j | jtd| d  td  S )Nr   r9   )r	   r
   r   Zerfinvr1   r3   r<   r   r   r   icdfb      (zNormal.icdfc                 C   s$   ddt dt j   t| j S )Nr8   r   )r1   r2   r4   r   r
   r   r   r   r   entropye   s   $zNormal.entropyc                 C   s&   | j | jd d| jd  fS )Nr   g      )r	   r
   r   r;   r   r   r   r   _natural_paramsh   s   &zNormal._natural_paramsc                 C   s(   d| d | dttj |   S )Ng      пr   r8   )r   r   r2   r1   r4   )r   xyr   r   r   _log_normalizerl   r?   zNormal._log_normalizerr   )__name__
__module____qualname____doc__r   realZpositiveZarg_constraintsZsupportZhas_rsampleZ_mean_carrier_measurepropertyr   r   r   r   r!   r%   r   r   r,   r/   r7   r=   r>   r@   rA   rD   __classcell__r   r   r#   r   r      s2    



	
)r1   numbersr   r   r   Ztorch.distributionsr   Ztorch.distributions.exp_familyr   Ztorch.distributions.utilsr   r   __all__r   r   r   r   r   <module>   s    