o
    h
                     @   sz   d dl Z d dlmZ d dlZd dlmZ d dlmZ d dlm	Z	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)constraints)TransformedDistribution)AffineTransformExpTransform)Uniform)broadcast_alleuler_constantGumbelc                       s   e Zd ZdZejejdZejZd fdd	Z	d fdd	Z
dd	 Zed
d Zedd Zedd Zedd Zdd Z  ZS )r
   a  
    Samples from a Gumbel Distribution.

    Examples::

        >>> # xdoctest: +IGNORE_WANT("non-deterinistic")
        >>> m = Gumbel(torch.tensor([1.0]), torch.tensor([2.0]))
        >>> m.sample()  # sample from Gumbel distribution with loc=1, scale=2
        tensor([ 1.0124])

    Args:
        loc (float or Tensor): Location parameter of the distribution
        scale (float or Tensor): Scale parameter of the distribution
    locscaleNc                    s   t ||\| _| _t| jj}t|tr&t|tr&t|j	d|j
 |d}ntt| j|j	t| jd|j
 |d}t jtdt| j dt jt|| j dg}t j|||d d S )N   )validate_argsr   r   )r   r   r   torchfinfodtype
isinstancer   r   tinyeps	full_liker   invr   	ones_likesuper__init__)selfr   r   r   r   	base_dist
transforms	__class__ P/var/www/html/ai/venv/lib/python3.10/site-packages/torch/distributions/gumbel.pyr       s   zGumbel.__init__c                    s8   |  t|}| j||_| j||_t j||dS )N)	_instance)_get_checked_instancer
   r   expandr   r   )r   batch_shaper"   newr   r    r!   r$   3   s   zGumbel.expandc                 C   s6   | j r| | | j| | j }||  | j  S N)_validate_args_validate_sampler   r   explog)r   valueyr    r    r!   log_prob:   s   
zGumbel.log_probc                 C   s   | j | jt  S r'   )r   r   r	   r   r    r    r!   mean@   s   zGumbel.meanc                 C   s   | j S r'   )r   r/   r    r    r!   modeD   s   zGumbel.modec                 C   s   t jt d | j S )N   )mathpisqrtr   r/   r    r    r!   stddevH   s   zGumbel.stddevc                 C   s   | j dS )N   )r6   powr/   r    r    r!   varianceL   s   zGumbel.variancec                 C   s   | j  dt  S )Nr   )r   r+   r	   r/   r    r    r!   entropyP   s   zGumbel.entropyr'   )__name__
__module____qualname____doc__r   realpositivearg_constraintssupportr   r$   r.   propertyr0   r1   r6   r9   r:   __classcell__r    r    r   r!   r
      s     



)r3   numbersr   r   torch.distributionsr   ,torch.distributions.transformed_distributionr   torch.distributions.transformsr   r   torch.distributions.uniformr   torch.distributions.utilsr   r	   __all__r
   r    r    r    r!   <module>   s    