a
    h	                     @   sr   d dl mZmZ 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gZG d	d deZdS )
    )OptionalUnionN)Tensor)constraints)ExponentialFamily)broadcast_all)_NumberNumberPoissonc                       s   e Zd ZdZdejiZejZe	e
dddZe	e
dddZe	e
ddd	Zdee
ef ee d
d fddZd fdd	Ze fddZdd Ze	ee
 dddZdd Z  ZS )r
   a  
    Creates a Poisson distribution parameterized by :attr:`rate`, the rate parameter.

    Samples are nonnegative integers, with a pmf given by

    .. math::
      \mathrm{rate}^k \frac{e^{-\mathrm{rate}}}{k!}

    Example::

        >>> # xdoctest: +SKIP("poisson_cpu not implemented for 'Long'")
        >>> m = Poisson(torch.tensor([4]))
        >>> m.sample()
        tensor([ 3.])

    Args:
        rate (Number, Tensor): the rate parameter
    rate)returnc                 C   s   | j S Nr   self r   I/var/www/auris/lib/python3.9/site-packages/torch/distributions/poisson.pymean&   s    zPoisson.meanc                 C   s
   | j  S r   )r   floorr   r   r   r   mode*   s    zPoisson.modec                 C   s   | j S r   r   r   r   r   r   variance.   s    zPoisson.varianceN)r   validate_argsr   c                    s>   t |\| _t|tr t }n
| j }t j||d d S )Nr   )	r   r   
isinstancer   torchSizesizesuper__init__)r   r   r   batch_shape	__class__r   r   r   2   s
    


zPoisson.__init__c                    sD   |  t|}t|}| j||_tt|j|dd | j|_|S )NFr   )	Z_get_checked_instancer
   r   r   r   expandr   r   _validate_args)r   r   Z	_instancenewr    r   r   r"   >   s    
zPoisson.expandc                 C   sH   |  |}t " t| j|W  d    S 1 s:0    Y  d S r   )Z_extended_shaper   Zno_gradZpoissonr   r"   )r   Zsample_shapeshaper   r   r   sampleF   s    

zPoisson.samplec                 C   s:   | j r| | t| j|\}}||| |d   S )N   )r#   Z_validate_sampler   r   Zxlogylgamma)r   valuer   r   r   r   log_probK   s    
zPoisson.log_probc                 C   s   t | jfS r   )r   logr   r   r   r   r   _natural_paramsQ   s    zPoisson._natural_paramsc                 C   s
   t |S r   )r   exp)r   xr   r   r   _log_normalizerU   s    zPoisson._log_normalizer)N)N)__name__
__module____qualname____doc__r   ZnonnegativeZarg_constraintsZnonnegative_integerZsupportpropertyr   r   r   r   r   r	   r   boolr   r"   r   r   r&   r*   tupler,   r/   __classcell__r   r   r    r   r
      s*   
 
)typingr   r   r   r   Ztorch.distributionsr   Ztorch.distributions.exp_familyr   Ztorch.distributions.utilsr   Ztorch.typesr   r	   __all__r
   r   r   r   r   <module>   s   