L i LddlmZddlZddlmZddlmZdgZGddeZy))UnionN)Tensor) DistributionExponentialFamilycReZdZdZedeedffdZdZede fdZ dZ y) ra 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.ct)zv Abstract method for natural parameters. Returns a tuple of Tensors based on the distribution NotImplementedErrorselfs d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/distributions/exp_family.py_natural_paramsz!ExponentialFamily._natural_params! "!ct)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 "!rct)zp Abstract method for expected carrier measure, which is required for computing entropy. r r s r_mean_carrier_measurez'ExponentialFamily._mean_carrier_measure0rrc|j }|jDcgc] }|jj"}}|j|}t j j|j|d}||z }t||D]8\}}|||zj|jdzjdz}:|Scc}w)z_ Method to compute the entropy using Bregman divergence of the log normalizer. T) create_graph)r) rrdetachrequires_grad_rtorchautogradgradsumzipreshape _batch_shape)r resultpnparams lg_normal gradientsnpgs rentropyzExponentialFamily.entropy8s)-(B(B'B8<8L8LM1188:,,.MM(D(('2 NN'' t'T )), JEB rAv&&t'8'85'@AEEbI IF J Ns%CN) __name__ __module__ __qualname____doc__propertytuplerrrfloatrr*rrrr sP("vs{!3""""u"" r)typingrrr torch.distributions.distributionr__all__rr2rrr6s' 9  7 7r