
    Vh	                     d    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e      Zy)	    N)Tensor)constraints)ExponentialFamily)broadcast_all)_NumberPoissonc                        e Zd ZdZdej
                  iZej                  Ze	de
fd       Ze	de
fd       Ze	de
fd       Zd fd	Zd fd	Z ej"                         fd	Zd
 Ze	dee
   fd       Zd Z x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                     | j                   S Nr
   selfs    K/home/dcms/DCMS/lib/python3.12/site-packages/torch/distributions/poisson.pymeanzPoisson.mean$       yy    c                 6    | j                   j                         S r   )r
   floorr   s    r   modezPoisson.mode(   s    yy  r   c                     | j                   S r   r   r   s    r   variancezPoisson.variance,   r   r   c                     t        |      \  | _        t        |t              rt	        j
                         }n| j                  j                         }t        | !  ||       y )Nvalidate_args)	r   r
   
isinstancer   torchSizesizesuper__init__)r   r
   r   batch_shape	__class__s       r   r"   zPoisson.__init__0   sH    $T*dG$**,K))..*KMBr   c                     | j                  t        |      }t        j                  |      }| j                  j                  |      |_        t        t        |  |d       | j                  |_        |S )NFr   )	_get_checked_instancer   r   r   r
   expandr!   r"   _validate_args)r   r#   	_instancenewr$   s       r   r'   zPoisson.expand8   s`    (()<jj-99##K0gs$[$F!00
r   c                     | j                  |      }t        j                         5  t        j                  | j                  j                  |            cd d d        S # 1 sw Y   y xY wr   )_extended_shaper   no_gradpoissonr
   r'   )r   sample_shapeshapes      r   samplezPoisson.sample@   sK    $$\2]]_ 	:==!1!1%!89	: 	: 	:s   .AA'c                     | j                   r| j                  |       t        | j                  |      \  }}|j	                  |      |z
  |dz   j                         z
  S )N   )r(   _validate_sampler   r
   xlogylgamma)r   valuer
   s      r   log_probzPoisson.log_probE   sS    !!%(#DIIu5e{{4 4'519*<*<*>>>r   c                 B    t        j                  | j                        fS r   )r   logr
   r   s    r   _natural_paramszPoisson._natural_paramsK   s    		$))$&&r   c                 ,    t        j                  |      S r   )r   exp)r   xs     r   _log_normalizerzPoisson._log_normalizerO   s    yy|r   r   )__name__
__module____qualname____doc__r   nonnegativearg_constraintsnonnegative_integersupportpropertyr   r   r   r   r"   r'   r   r   r1   r8   tupler;   r?   __classcell__)r$   s   @r   r   r      s    & {667O--Gf   !f ! ! &  C #-%**, :
? 'v ' 'r   )r   r   torch.distributionsr   torch.distributions.exp_familyr   torch.distributions.utilsr   torch.typesr   __all__r    r   r   <module>rQ      s/      + < 3  +C Cr   