U
    ‰d¿  ã                   @   sD   d dl mZ d dlmZ d dlmZ d dlmZ G dd„ deƒZdS )é    )Úconstraints)ÚNormal)ÚTransformedDistribution)ÚStickBreakingTransformc                       s`   e Zd ZdZejejdœZejZ	dZ
d‡ fdd„	Zd‡ fdd„	Zed	d
„ ƒZedd„ ƒZ‡  ZS )ÚLogisticNormala  
    Creates a logistic-normal distribution parameterized by :attr:`loc` and :attr:`scale`
    that define the base `Normal` distribution transformed with the
    `StickBreakingTransform` such that::

        X ~ LogisticNormal(loc, scale)
        Y = log(X / (1 - X.cumsum(-1)))[..., :-1] ~ Normal(loc, scale)

    Args:
        loc (float or Tensor): mean of the base distribution
        scale (float or Tensor): standard deviation of the base distribution

    Example::

        >>> # logistic-normal distributed with mean=(0, 0, 0) and stddev=(1, 1, 1)
        >>> # of the base Normal distribution
        >>> m = distributions.LogisticNormal(torch.tensor([0.0] * 3), torch.tensor([1.0] * 3))
        >>> m.sample()
        tensor([ 0.7653,  0.0341,  0.0579,  0.1427])

    )ÚlocÚscaleTNc                    s<   t |||d}|js | dg¡}tt| ƒj|tƒ |d d S )N)Úvalidate_argsé   )r   Úbatch_shapeÚexpandÚsuperr   Ú__init__r   )Úselfr   r   r	   Ú	base_dist©Ú	__class__© úG/tmp/pip-unpacked-wheel-ua33x9lu/torch/distributions/logistic_normal.pyr   !   s    þzLogisticNormal.__init__c                    s    |   t|¡}tt| ƒj||dS )N)Ú	_instance)Z_get_checked_instancer   r   r   )r   r   r   Únewr   r   r   r   )   s    zLogisticNormal.expandc                 C   s
   | j j jS ©N)r   r   ©r   r   r   r   r   -   s    zLogisticNormal.locc                 C   s
   | j j jS r   )r   r   r   r   r   r   r   1   s    zLogisticNormal.scale)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚrealZpositiveZarg_constraintsZsimplexZsupportZhas_rsampler   r   Úpropertyr   r   Ú__classcell__r   r   r   r   r      s   
r   N)	Ztorch.distributionsr   Ztorch.distributions.normalr   Z,torch.distributions.transformed_distributionr   Ztorch.distributions.transformsr   r   r   r   r   r   Ú<module>   s   