U
    ©Ê¹jü  ã                   @   sn   d dl Z d dlm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gZG d	d„ deƒZdS )
é    N)Úconstraints)ÚExponential)Úeuler_constant)ÚTransformedDistribution)ÚAffineTransformÚPowerTransform)Úbroadcast_allÚWeibullc                       sp   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e
dd„ ƒZdd„ Z‡  ZS )r	   aí  
    Samples from a two-parameter Weibull distribution.

    Example:

        >>> # xdoctest: +IGNORE_WANT("non-deterinistic")
        >>> 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 ¡ | _tt | j¡|d�}t| jd�t	d| jd�g}t
ƒ j|||d� d S )N©Úvalidate_args©Úexponentr   ©Úlocr
   )r   r
   r   Ú
reciprocalÚconcentration_reciprocalr   ÚtorchZ	ones_liker   r   ÚsuperÚ__init__)Úselfr
   r   r   Ú	base_distÚ
transforms©Ú	__class__© úZ/var/www/html/bwave/python/venv/lib/python3.8/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   Úmean;   s    zWeibull.meanc                 C   s    | j | jd | j | j ¡   S r    )r
   r   r   r$   r   r   r   Úmode?   s    ÿÿÿzWeibull.modec              	   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   ÚvarianceG   s
    
ÿÿzWeibull.variancec                 C   s$   t d| j  t | j| j ¡ d S r    )r   r   r   Úlogr
   r$   r   r   r   ÚentropyN   s    ÿþÿzWeibull.entropy)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZpositiveZarg_constraintsZsupportr   r   Úpropertyr%   r&   r)   r+   Ú__classcell__r   r   r   r   r	      s   þ


)r   Ztorch.distributionsr   Ztorch.distributions.exponentialr   Ztorch.distributions.gumbelr   Z,torch.distributions.transformed_distributionr   Ztorch.distributions.transformsr   r   Ztorch.distributions.utilsr   Ú__all__r	   r   r   r   r   Ú<module>   s   