has_analytic_entropy#
- torchrl.modules.distributions.utils.has_analytic_entropy(dist: Distribution) bool[source]#
Return whether
distimplements a closed-formentropy().The check is class-level:
type(dist).entropy is not torch.distributions.Distribution.entropy.Independentis resolved through its base distribution becauseIndependent.entropyalways exists and only works when the base distribution implements entropy.CompositeDistributionis treated as not having a closed-form entropy: itsentropy()may return a TensorDict and still relies ontry/exceptinternally. Usecomposite_entropy()for composites.- Parameters:
dist (torch.distributions.Distribution) – distribution to inspect.
- Returns:
Trueif a closed-form entropy method is available.- Return type:
bool
Examples
>>> import torch >>> from torch import distributions as d >>> from torchrl.modules.distributions.utils import has_analytic_entropy >>> has_analytic_entropy(d.Normal(torch.zeros(2), torch.ones(2))) True >>> has_analytic_entropy(d.Independent(d.Normal(torch.zeros(2), torch.ones(2)), 1)) True