a
    –¥»a&  ã                   @   sh   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 d dlmZ G dd	„ d	eƒZdS )
é    N)Úconstraints)ÚExponential)ÚTransformedDistribution)ÚAffineTransformÚPowerTransform)Úbroadcast_all)Úeuler_constantc                       sd   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	e
dd	„ ƒZe
d
d„ ƒZdd„ Z‡  ZS )ÚWeibulla´  
    Samples from a two-parameter Weibull distribution.

    Example:

        >>> m = Weibull(torch.tensor([1.0]), torch.tensor([1.0]))
        >>> m.sample()  # sample from a Weibull distribution with scale=1, concentration=1
        tensor([ 0.4784])

    Args:
        scale (float or Tensor): Scale parameter of distribution (lambda).
        concentration (float or Tensor): Concentration parameter of distribution (k/shape).
    )ÚscaleÚconcentrationNc                    sf   t ||ƒ\| _| _| j ¡ | _tt | j¡|d�}t| jd�t	d| jd�g}t
t| ƒj|||d� d S )N©Úvalidate_args©Úexponentr   ©Úlocr
   )r   r
   r   Ú
reciprocalÚconcentration_reciprocalr   ÚtorchZ	ones_liker   r   Úsuperr	   Ú__init__)Úselfr
   r   r   Ú	base_distÚ
transforms©Ú	__class__© úU/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/torch/distributions/weibull.pyr      s    
ÿþzWeibull.__init__c                    s|   |   t|¡}| j |¡|_| j |¡|_|j ¡ |_| j |¡}t|jd�t	d|jd�g}t
t|ƒj||dd� | j|_|S )Nr   r   r   Fr   )Z_get_checked_instancer	   r
   Úexpandr   r   r   r   r   r   r   r   Z_validate_args)r   Zbatch_shapeZ	_instanceÚnewr   r   r   r   r   r   %   s    
ÿþzWeibull.expandc                 C   s   | j t t d| j ¡¡ S ©Né   )r
   r   ÚexpÚlgammar   ©r   r   r   r   Úmean3   s    zWeibull.meanc              	   C   s@   | j  d¡t t dd| j  ¡¡t dt d| j ¡ ¡  S )Né   r!   )r
   Úpowr   r"   r#   r   r$   r   r   r   Úvariance7   s    "ÿzWeibull.variancec                 C   s$   t d| j  t | j| j ¡ d S r    )r   r   r   Úlogr
   r$   r   r   r   Úentropy<   s
    ÿÿzWeibull.entropy)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZpositiveZarg_constraintsZsupportr   r   Úpropertyr%   r(   r*   Ú__classcell__r   r   r   r   r	   
   s   


r	   )r   Ztorch.distributionsr   Ztorch.distributions.exponentialr   Z,torch.distributions.transformed_distributionr   Ztorch.distributions.transformsr   r   Ztorch.distributions.utilsr   Ztorch.distributions.gumbelr   r	   r   r   r   r   Ú<module>   s   