o
    !i                     @   sR   d dl mZ d dlZd dlmZ d dlmZ d dlmZ dgZ	G dd deZ
dS )    )NumberN)constraints)ExponentialFamily)broadcast_allPoissonc                       s   e Zd ZdZdejiZejZe	dd Z
e	dd Ze	dd Zd fd
d	Zd fdd	Ze fddZdd Ze	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
    ratec                 C      | j S Nr   self r   j/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/torch/distributions/poisson.pymean!      zPoisson.meanc                 C   s
   | j  S r	   )r   floorr   r   r   r   mode%   s   
zPoisson.modec                 C   r   r	   r
   r   r   r   r   variance)   r   zPoisson.varianceNc                    s>   t |\| _t|trt }n| j }t j||d d S )Nvalidate_args)	r   r   
isinstancer   torchSizesizesuper__init__)r   r   r   batch_shape	__class__r   r   r   -   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   5   s   
zPoisson.expandc                 C   sH   |  |}t  t| j|W  d    S 1 sw   Y  d S r	   )Z_extended_shaper   Zno_gradZpoissonr   r   )r   Zsample_shapeshaper   r   r   sample=   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_probB   s   
zPoisson.log_probc                 C   s   t | jfS r	   )r   logr   r   r   r   r   _natural_paramsH   s   zPoisson._natural_paramsc                 C   s
   t |S r	   )r   exp)r   xr   r   r   _log_normalizerL   s   
zPoisson._log_normalizerr	   )__name__
__module____qualname____doc__r   ZnonnegativeZarg_constraintsZnonnegative_integerZsupportpropertyr   r   r   r   r   r   r   r#   r'   r)   r,   __classcell__r   r   r   r   r      s"    




)numbersr   r   Ztorch.distributionsr   Ztorch.distributions.exp_familyr   Ztorch.distributions.utilsr   __all__r   r   r   r   r   <module>   s    