§
    ™/j–	  ã                   óH   — d dl Z d dl mZ d dlmZ dgZ G d„ de¦  «        ZdS )é    N)ÚTensor)ÚDistributionÚExponentialFamilyc                   óf   — e Zd ZdZedeedf         fd„¦   «         Zd„ Zede	fd„¦   «         Z
d„ ZdS )	r   aÒ  
    ExponentialFamily is the abstract base class for probability distributions belonging to an
    exponential family, whose probability mass/density function has the form is defined below

    .. math::

        p_{F}(x; \theta) = \exp(\langle t(x), \theta\rangle - F(\theta) + k(x))

    where :math:`\theta` denotes the natural parameters, :math:`t(x)` denotes the sufficient statistic,
    :math:`F(\theta)` is the log normalizer function for a given family and :math:`k(x)` is the carrier
    measure.

    Note:
        This class is an intermediary between the `Distribution` class and distributions which belong
        to an exponential family mainly to check the correctness of the `.entropy()` and analytic KL
        divergence methods. We use this class to compute the entropy and KL divergence using the AD
        framework and Bregman divergences (courtesy of: Frank Nielsen and Richard Nock, Entropies and
        Cross-entropies of Exponential Families).
    Úreturn.c                 ó   — t           ‚)zv
        Abstract method for natural parameters. Returns a tuple of Tensors based
        on the distribution
        ©ÚNotImplementedError©Úselfs    úc/home/longshao/multi-rider-rag/.venv/lib/python3.11/site-packages/torch/distributions/exp_family.pyÚ_natural_paramsz!ExponentialFamily._natural_params    ó
   € õ "Ð!ó    c                 ó   — t           ‚)zƒ
        Abstract method for log normalizer function. Returns a log normalizer based on
        the distribution and input
        r	   )r   Únatural_paramss     r   Ú_log_normalizerz!ExponentialFamily._log_normalizer(   s
   € õ
 "Ð!r   c                 ó   — t           ‚)zp
        Abstract method for expected carrier measure, which is required for computing
        entropy.
        r	   r   s    r   Ú_mean_carrier_measurez'ExponentialFamily._mean_carrier_measure/   r   r   c                 óV  — | j          }d„ | j        D ¦   «         } | j        |Ž }t          j                             |                     ¦   «         |d¬¦  «        }||z  }t          ||¦  «        D ];\  }}|||z                       | j	        dz   ¦  «                             d¦  «        z  }Œ<|S )z_
        Method to compute the entropy using Bregman divergence of the log normalizer.
        c                 óZ   — g | ](}|                      ¦   «                              ¦   «         ‘Œ)S © )ÚdetachÚrequires_grad_)Ú.0Úps     r   ú
<listcomp>z-ExponentialFamily.entropy.<locals>.<listcomp><   s,   € ÐMÐMÐM°11—8’8‘:”:×,Ò,Ñ.Ô.ÐMÐMÐMr   T)Úcreate_graph)éÿÿÿÿr   )
r   r   r   ÚtorchÚautogradÚgradÚsumÚzipÚreshapeÚ_batch_shape)r   ÚresultÚnparamsÚ	lg_normalÚ	gradientsÚnpÚgs          r   ÚentropyzExponentialFamily.entropy7   sº   € ð #'Ô"<Ð!<ˆØMÐM¸Ô8LÐMÑMÔMˆØ(DÔ(¨'Ð2ˆ	Ý”N×'Ò'¨	¯ª©¬¸ÈtÐ'ÑTÔTˆ	Ø)ÑˆÝ˜ )Ñ,Ô,ð 	Jð 	J‰EˆBØr˜A‘v×&Ò& tÔ'8¸5Ñ'@ÑAÔA×EÒEÀbÑIÔIÑIˆFˆFØˆr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚpropertyÚtupler   r   r   Úfloatr   r-   r   r   r   r   r      s“   € € € € € ðð ð( ð"  v¨s {Ô!3ð "ð "ð "ñ „Xð"ð"ð "ð "ð ð" uð "ð "ð "ñ „Xð"ðð ð ð ð r   )r    r   Ú torch.distributions.distributionr   Ú__all__r   r   r   r   ú<module>r7      sr   ðð €€€Ø Ð Ð Ð Ð Ð Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9ð Ð
€ð7ð 7ð 7ð 7ð 7˜ñ 7ô 7ð 7ð 7ð 7r   