U
    yh
                     @   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-deterministic")
        >>> 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rLt|trLt|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finfoZdtype
isinstancer   r   ZtinyepsZ	full_liker   invr   Z	ones_likesuper__init__)selfr   r   r   r   Z	base_distZ
transforms	__class__ L/var/www/html/venv/lib/python3.8/site-packages/torch/distributions/gumbel.pyr   !   s    zGumbel.__init__c                    s8   |  t|}| j||_| j||_t j||dS )N)	_instance)Z_get_checked_instancer
   r   expandr   r   )r   Zbatch_shaper   newr   r   r   r   4   s    zGumbel.expandc                 C   s6   | j r| | | j| | j }||  | j  S N)Z_validate_argsZ_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   meanA   s    zGumbel.meanc                 C   s   | j S r   )r   r%   r   r   r   modeE   s    zGumbel.modec                 C   s   t jt d | j S )N   )mathpisqrtr   r%   r   r   r   stddevI   s    zGumbel.stddevc                 C   s   | j dS )N   )r,   powr%   r   r   r   varianceM   s    zGumbel.variancec                 C   s   | j  dt  S )Nr   )r   r!   r	   r%   r   r   r   entropyQ   s    zGumbel.entropy)N)N)__name__
__module____qualname____doc__r   realZpositiveZarg_constraintsZsupportr   r   r$   propertyr&   r'   r,   r/   r0   __classcell__r   r   r   r   r
      s   



)r)   numbersr   r   Ztorch.distributionsr   Z,torch.distributions.transformed_distributionr   Ztorch.distributions.transformsr   r   Ztorch.distributions.uniformr   Ztorch.distributions.utilsr   r	   __all__r
   r   r   r   r   <module>   s   