/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
torch
/
distributions
/
/usr/local/lib64/python3.6/site-packages/torch/distributions
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
bernoulli.py
3904
0644
edit
dl
rm
beta.py
3406
0644
edit
dl
rm
binomial.py
5179
0644
edit
dl
rm
categorical.py
5488
0644
edit
dl
rm
cauchy.py
2714
0644
edit
dl
rm
chi2.py
909
0644
edit
dl
rm
constraints.py
17288
0644
edit
dl
rm
constraint_registry.py
10234
0644
edit
dl
rm
continuous_bernoulli.py
8532
0644
edit
dl
rm
dirichlet.py
3584
0644
edit
dl
rm
distribution.py
11735
0644
edit
dl
rm
exponential.py
2525
0644
edit
dl
rm
exp_family.py
2275
0644
edit
dl
rm
fishersnedecor.py
3152
0644
edit
dl
rm
gamma.py
3121
0644
edit
dl
rm
geometric.py
4266
0644
edit
dl
rm
gumbel.py
2528
0644
edit
dl
rm
half_cauchy.py
2257
0644
edit
dl
rm
half_normal.py
2058
0644
edit
dl
rm
independent.py
4361
0644
edit
dl
rm
kl.py
29998
0644
edit
dl
rm
kumaraswamy.py
2927
0644
edit
dl
rm
laplace.py
3054
0644
edit
dl
rm
lkj_cholesky.py
6124
0644
edit
dl
rm
logistic_normal.py
1983
0644
edit
dl
rm
log_normal.py
1772
0644
edit
dl
rm
lowrank_multivariate_normal.py
9930
0644
edit
dl
rm
mixture_same_family.py
8636
0644
edit
dl
rm
multinomial.py
4776
0644
edit
dl
rm
multivariate_normal.py
10548
0644
edit
dl
rm
negative_binomial.py
4091
0644
edit
dl
rm
normal.py
3351
0644
edit
dl
rm
one_hot_categorical.py
4375
0644
edit
dl
rm
pareto.py
2057
0644
edit
dl
rm
poisson.py
2066
0644
edit
dl
rm
relaxed_bernoulli.py
5360
0644
edit
dl
rm
relaxed_categorical.py
5202
0644
edit
dl
rm
studentT.py
3550
0644
edit
dl
rm
transformed_distribution.py
8270
0644
edit
dl
rm
transforms.py
38408
0644
edit
dl
rm
uniform.py
3112
0644
edit
dl
rm
utils.py
6196
0644
edit
dl
rm
von_mises.py
5091
0644
edit
dl
rm
weibull.py
2854
0644
edit
dl
rm
__init__.py
5884
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/torch/distributions/exp_family.py
(2275B)
import torch from torch.distributions.distribution import Distribution class ExponentialFamily(Distribution): r""" 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). """ @property def _natural_params(self): """ Abstract method for natural parameters. Returns a tuple of Tensors based on the distribution """ raise NotImplementedError def _log_normalizer(self, *natural_params): """ Abstract method for log normalizer function. Returns a log normalizer based on the distribution and input """ raise NotImplementedError @property def _mean_carrier_measure(self): """ Abstract method for expected carrier measure, which is required for computing entropy. """ raise NotImplementedError def entropy(self): """ Method to compute the entropy using Bregman divergence of the log normalizer. """ result = -self._mean_carrier_measure nparams = [p.detach().requires_grad_() for p in self._natural_params] lg_normal = self._log_normalizer(*nparams) gradients = torch.autograd.grad(lg_normal.sum(), nparams, create_graph=True) result += lg_normal for np, g in zip(nparams, gradients): result -= np * g return result
Save
cmd:
run