mirror of
https://github.com/saymrwulf/stable-baselines3.git
synced 2026-07-30 20:18:15 +00:00
Entropy can't be None
This commit is contained in:
parent
838165c265
commit
6da012f9ab
1 changed files with 5 additions and 9 deletions
|
|
@ -54,7 +54,7 @@ class Distribution(ABC):
|
|||
"""
|
||||
|
||||
@abstractmethod
|
||||
def entropy(self) -> Optional[th.Tensor]:
|
||||
def entropy(self) -> th.Tensor:
|
||||
"""
|
||||
Returns Shannon's entropy of the probability
|
||||
|
||||
|
|
@ -240,10 +240,8 @@ class SquashedDiagGaussianDistribution(DiagGaussianDistribution):
|
|||
log_prob -= th.sum(th.log(1 - actions**2 + self.epsilon), dim=1)
|
||||
return log_prob
|
||||
|
||||
def entropy(self) -> Optional[th.Tensor]:
|
||||
# No analytical form,
|
||||
# entropy needs to be estimated using -log_prob.mean()
|
||||
return None
|
||||
def entropy(self) -> th.Tensor:
|
||||
raise NotImplementedError("No analytical form, entropy needs to be estimated using -log_prob.mean()")
|
||||
|
||||
def sample(self) -> th.Tensor:
|
||||
# Reparametrization trick to pass gradients
|
||||
|
|
@ -567,11 +565,9 @@ class StateDependentNoiseDistribution(Distribution):
|
|||
log_prob -= th.sum(self.bijector.log_prob_correction(gaussian_actions), dim=1)
|
||||
return log_prob
|
||||
|
||||
def entropy(self) -> Optional[th.Tensor]:
|
||||
def entropy(self) -> th.Tensor:
|
||||
if self.bijector is not None:
|
||||
# No analytical form,
|
||||
# entropy needs to be estimated using -log_prob.mean()
|
||||
return None
|
||||
raise NotImplementedError("No analytical form, entropy needs to be estimated using -log_prob.mean()")
|
||||
return sum_independent_dims(self.distribution.entropy())
|
||||
|
||||
def sample(self) -> th.Tensor:
|
||||
|
|
|
|||
Loading…
Reference in a new issue