o
    h	                     @   s^   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	 dgZ
G dd deZdS )	    N)Tensor)constraints)ExponentialFamily)broadcast_all)_NumberPoissonc                       s   e Zd ZdZdejiZejZe	de
fddZe	de
fddZe	de
fdd	Zd fdd	Zd fdd	Ze fddZdd Ze	dee
 f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      | j S Nr   self r   o/var/www/html/construction_image-detection-poc/venv/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   0   s
   


zPoisson.__init__c                    sD   |  t|}t|}| j||_tt|j|dd | j|_|S )NFr   )	_get_checked_instancer   r   r   r   expandr   r   _validate_args)r   r   	_instancenewr   r   r   r"   8   s   
zPoisson.expandc                 C   sH   |  |}t  t| j|W  d    S 1 sw   Y  d S r   )_extended_shaper   no_gradpoissonr   r"   )r   sample_shapeshaper   r   r   sample@   s   

$zPoisson.samplec                 C   s:   | j r| | t| j|\}}||| |d   S )N   )r#   _validate_sampler   r   xlogylgamma)r   valuer   r   r   r   log_probE   s   
zPoisson.log_probc                 C   s   t | jfS r   )r   logr   r   r   r   r   _natural_paramsK   s   zPoisson._natural_paramsc                 C   s
   t |S r   )r   exp)r   xr   r   r   _log_normalizerO   s   
zPoisson._log_normalizerr   )__name__
__module____qualname____doc__r   nonnegativearg_constraintsnonnegative_integersupportpropertyr   r   r   r   r   r"   r   r   r+   r1   tupler3   r6   __classcell__r   r   r   r   r      s"    
)r   r   torch.distributionsr   torch.distributions.exp_familyr   torch.distributions.utilsr   torch.typesr   __all__r   r   r   r   r   <module>   s   