
    #h                     `    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e          Z
dS )    )DictN)constraints)Distribution)_sum_rightmostIndependentc                   L    e Zd ZU dZi Zeeej        f         e	d<   	 d fd	Z
d fd	Zed             Zed             Zej        d             Zed	             Zed
             Zed             Z ej                    fdZ ej                    fdZd Zd ZddZd Z xZS )r   a  
    Reinterprets some of the batch dims of a distribution as event dims.

    This is mainly useful for changing the shape of the result of
    :meth:`log_prob`. For example to create a diagonal Normal distribution with
    the same shape as a Multivariate Normal distribution (so they are
    interchangeable), you can::

        >>> from torch.distributions.multivariate_normal import MultivariateNormal
        >>> from torch.distributions.normal import Normal
        >>> loc = torch.zeros(3)
        >>> scale = torch.ones(3)
        >>> mvn = MultivariateNormal(loc, scale_tril=torch.diag(scale))
        >>> [mvn.batch_shape, mvn.event_shape]
        [torch.Size([]), torch.Size([3])]
        >>> normal = Normal(loc, scale)
        >>> [normal.batch_shape, normal.event_shape]
        [torch.Size([3]), torch.Size([])]
        >>> diagn = Independent(normal, 1)
        >>> [diagn.batch_shape, diagn.event_shape]
        [torch.Size([]), torch.Size([3])]

    Args:
        base_distribution (torch.distributions.distribution.Distribution): a
            base distribution
        reinterpreted_batch_ndims (int): the number of batch dims to
            reinterpret as event dims
    arg_constraintsNc                    |t          |j                  k    r't          d| dt          |j                             |j        |j        z   }|t          |j                  z   }|d t          |          |z
           }|t          |          |z
  d          }|| _        || _        t                                          |||           d S )NzQExpected reinterpreted_batch_ndims <= len(base_distribution.batch_shape), actual z vs validate_args)lenbatch_shape
ValueErrorevent_shape	base_distreinterpreted_batch_ndimssuper__init__)	selfbase_distributionr   r   shape	event_dimr   r   	__class__s	           _/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/torch/distributions/independent.pyr   zIndependent.__init__*   s     %s+<+H'I'III^3^ ^9<=N=Z9[9[^ ^   "-0A0MM-4E4Q0R0RR	4c%jj9445CJJ2445*)B&kOOOOO    c                 ^   |                      t          |          }t          j        |          }| j                            || j        d | j                 z             |_        | j        |_        t          t          |          	                    || j        d           | j
        |_
        |S )NFr   )_get_checked_instancer   torchSizer   expandr   r   r   r   _validate_args)r   r   	_instancenewr   s       r   r    zIndependent.expand:   s    ((i@@j----$*+KT-K+KLL
 
 )-(F%k3(() 	) 	
 	
 	
 "0
r   c                     | j         j        S N)r   has_rsampler   s    r   r&   zIndependent.has_rsampleG   s    ~))r   c                 4    | j         dk    rdS | j        j        S )Nr   F)r   r   has_enumerate_supportr'   s    r   r)   z!Independent.has_enumerate_supportK   s     )A--5~33r   c                 `    | j         j        }| j        rt          j        || j                  }|S r%   )r   supportr   r   independent)r   results     r   r+   zIndependent.supportQ   s2    ') 	U ,VT5STTFr   c                     | j         j        S r%   )r   meanr'   s    r   r/   zIndependent.meanX       ~""r   c                     | j         j        S r%   )r   moder'   s    r   r2   zIndependent.mode\   r0   r   c                     | j         j        S r%   )r   variancer'   s    r   r4   zIndependent.variance`   s    ~&&r   c                 6    | j                             |          S r%   )r   sampler   sample_shapes     r   r6   zIndependent.sampled   s    ~$$\222r   c                 6    | j                             |          S r%   )r   rsampler7   s     r   r:   zIndependent.rsampleg   s    ~%%l333r   c                 `    | j                             |          }t          || j                  S r%   )r   log_probr   r   )r   valuer<   s      r   r<   zIndependent.log_probj   s*    >**511h(FGGGr   c                 ^    | j                                         }t          || j                  S r%   )r   entropyr   r   )r   r?   s     r   r?   zIndependent.entropyn   s(    .((**gt'EFFFr   Tc                 l    | j         dk    rt          d          | j                            |          S )Nr   z5Enumeration over cartesian product is not implemented)r    )r   NotImplementedErrorr   enumerate_support)r   r    s     r   rB   zIndependent.enumerate_supportr   s@    )A--%G   ~//v/>>>r   c                 B    | j         j        d| j         d| j         dz   S )N(z, ))r   __name__r   r   r'   s    r   __repr__zIndependent.__repr__y   s0    N#E$.EED$BEEEF	
r   r%   )T)rF   
__module____qualname____doc__r	   r   strr   
Constraint__annotations__r   r    propertyr&   r)   dependent_propertyr+   r/   r2   r4   r   r   r6   r:   r<   r?   rB   rG   __classcell__)r   s   @r   r   r      s         8 :<OT#{556;;; KOP P P P P P       * * X* 4 4 X4
 #  $# # # X# # # X# ' ' X' #-%*,, 3 3 3 3 $.5:<< 4 4 4 4H H HG G G? ? ? ?
 
 
 
 
 
 
r   )typingr   r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   __all__r    r   r   <module>rW      s           + + + + + + 9 9 9 9 9 9 4 4 4 4 4 4/r
 r
 r
 r
 r
, r
 r
 r
 r
 r
r   