3
O4W^	  ã               @   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                sb   t ||ƒ\| _| _| jjƒ | _ttj| jƒƒ}t| jd�t	d| jd�g}t
t| ƒj|||d� d S )N)Úexponentr   )Úlocr
   )Úvalidate_args)r   r
   r   Ú
reciprocalÚconcentration_reciprocalr   ÚtorchZ	ones_liker   r   Úsuperr	   Ú__init__)Úselfr
   r   r   Ú	base_distÚ
transforms)Ú	__class__© ú</tmp/pip-build-e66j97b2/torch/torch/distributions/weibull.pyr      s    
zWeibull.__init__c                s|   | j t|ƒ}| jj|ƒ|_| jj|ƒ|_|jjƒ |_| jj|ƒ}t|jd�t	d|jd�g}t
t|ƒj||dd� | j|_|S )N)r   r   )r   r
   F)r   )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jtjd| j ƒƒ S )Né   )r
   r   ÚexpÚlgammar   )r   r   r   r   Úmean3   s    zWeibull.meanc             C   s@   | j jdƒtjtjdd| j  ƒƒtjdtj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| j ƒ d S )Nr   )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   