Ë
    ©sgM	  ã                   ó4   — d dl Z d dlmZ dgZ G d„ de«      Zy)é    N)ÚDistributionÚExponentialFamilyc                   ó<   — e Zd ZdZed„ «       Zd„ Zed„ «       Zd„ Zy)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).
    c                 ó   — t         ‚)zv
        Abstract method for natural parameters. Returns a tuple of Tensors based
        on the distribution
        ©ÚNotImplementedError©Úselfs    úQ/var/www/html/venv/lib/python3.12/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                 óª  — | j                    }| j                  D cg c]   }|j                  «       j                  «       ‘Œ" }} | j                  |Ž }t
        j                  j                  |j                  «       |d¬«      }||z  }t        ||«      D ]8  \  }}|||z  j                  | j                  dz   «      j                  d«      z  }Œ: |S c c}w )z_
        Method to compute the entropy using Bregman divergence of the log normalizer.
        T)Úcreate_graph)éÿÿÿÿr   )r   r   ÚdetachÚrequires_grad_r   ÚtorchÚautogradÚgradÚsumÚzipÚreshapeÚ_batch_shape)r
   ÚresultÚpÚnparamsÚ	lg_normalÚ	gradientsÚnpÚgs           r   ÚentropyzExponentialFamily.entropy5   sÍ   € ð ×,Ñ,Ð,ˆØ8<×8LÑ8LÖM°11—8‘8“:×,Ñ,Õ.ÐMˆÐMØ(D×(Ñ(¨'Ð2ˆ	Ü—N‘N×'Ñ'¨	¯©«¸ÈtÐ'ÓTˆ	Ø)ÑˆÜ˜ )Ó,ò 	J‰EˆBØr˜A‘v×&Ñ& t×'8Ñ'8¸5Ñ'@ÓA×EÑEÀbÓIÑI‰Fð	Jàˆùò Ns   œ%CN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   r   r'   © r   r   r   r   	   s9   „ ñð( ñ"ó ð"ò"ð ñ"ó ð"ór   )r   Ú torch.distributions.distributionr   Ú__all__r   r-   r   r   ú<module>r0      s!   ðã Ý 9ð Ð
€ô7˜õ 7r   