
    Αi                    x    S SK Jr  S SKJr  S SKJr  \(       a  S SKJr  S SKJ	r	   " S S\R                  5      rg)	    )annotations)TYPE_CHECKING)distribution)Sequence)Tensorc                     ^  \ rS rSrSr      SU 4S jjr\SS j5       r\SS j5       r/ 4SS jjr	SS jr
SS jrSS	 jrSS
 jrSrU =r$ )Independent   a  
Reinterprets some of the batch dimensions of a distribution as event dimensions.

This is mainly useful for changing the shape of the result of
:meth:`log_prob`.

Args:
    base (Distribution): The base distribution.
    reinterpreted_batch_rank (int): The number of batch dimensions to
        reinterpret as event dimensions.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import independent

        >>> beta = paddle.distribution.Beta(paddle.to_tensor([0.5, 0.5]), paddle.to_tensor([0.5, 0.5]))
        >>> print(beta.batch_shape, beta.event_shape)
        (2,) ()
        >>> print(beta.log_prob(paddle.to_tensor(0.2)))
        Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
                [-0.22843921, -0.22843921])
        >>> reinterpreted_beta = independent.Independent(beta, 1)
        >>> print(reinterpreted_beta.batch_shape, reinterpreted_beta.event_shape)
        () (2,)
        >>> print(reinterpreted_beta.log_prob(paddle.to_tensor([0.2,  0.2])))
        Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
                -0.45687842)
c                  > [        U[        R                  5      (       d  [        S[	        U5       35      eSUs=:  a  [        UR                  5      ::  d&  O  [        S[        UR                  5       SU 35      eXl        X l	        UR                  UR                  -   n[        TU ]1  US [        UR                  5      U-
   U[        UR                  5      U-
  S  S9  g )Nz1Expected type of 'base' is Distribution, but got r   z)Expected 0 < reinterpreted_batch_rank <= z
, but got )batch_shapeevent_shape)
isinstancer   Distribution	TypeErrortypelenr   
ValueError_base_reinterpreted_batch_rankr   super__init__)selfbasereinterpreted_batch_rankshape	__class__s       _/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distribution/independent.pyr   Independent.__init__<   s     $ 9 9::CDJ<P  ,ED4D4D0EE;C@P@P<Q;RR\]u\vw  
)A&  4#3#33B#d&&'*BB D$$%(@@B	 	 	
    c                .    U R                   R                  $ N)r   meanr   s    r   r"   Independent.meanT   s    zzr   c                .    U R                   R                  $ r!   )r   variancer#   s    r   r&   Independent.varianceX   s    zz"""r   c                8    U R                   R                  U5      $ r!   )r   sample)r   r   s     r   r)   Independent.sample\   s    zz  ''r   c                l    U R                  U R                  R                  U5      U R                  5      $ r!   )_sum_rightmostr   log_probr   r   values     r   r-   Independent.log_prob_   s/    ""JJ&(F(F
 	
r   c                @    U R                  U5      R                  5       $ r!   )r-   expr.   s     r   probIndependent.probd   s    }}U#''))r   c                j    U R                  U R                  R                  5       U R                  5      $ r!   )r,   r   entropyr   r#   s    r   r6   Independent.entropyg   s-    ""JJ $"@"@
 	
r   c                \    US:  a%  UR                  [        [        U* S5      5      5      $ U$ )Nr   )sumlistrange)r   r/   ns      r   r,   Independent._sum_rightmostl   s)    01AuyyeQBl+,@5@r   )r   r   )r   zdistribution.Distributionr   intreturnNone)r?   r   )r   zSequence[int]r?   r   )r/   r   r?   r   )r/   r   r<   r>   r?   r   )__name__
__module____qualname____firstlineno____doc__r   propertyr"   r&   r)   r-   r3   r6   r,   __static_attributes____classcell__)r   s   @r   r	   r	      ss    @
-
IL
	
0   # # -/ (

*

A Ar   r	   N)
__future__r   typingr   paddle.distributionr   collections.abcr   paddler   r   r	    r   r   <module>rO      s/    #   ,(RA,++ RAr   