mirror of
https://github.com/saymrwulf/stable-baselines3.git
synced 2026-09-16 22:20:26 +00:00
Fix return type of evaluate_actions (#1118)
* Fix return type of ActorCriticPolicy.evaluate_actions to optional entropy tensor * Update changelog.rst
This commit is contained in:
parent
b77a0667b2
commit
cdcdd32c51
3 changed files with 6 additions and 2 deletions
|
|
@ -22,6 +22,7 @@ SB3-Contrib
|
|||
|
||||
Bug Fixes:
|
||||
^^^^^^^^^^
|
||||
- Fix return type of ``evaluate_actions`` in ``ActorCritcPolicy`` to reflect that entropy is an optional tensor (@Rocamonde)
|
||||
|
||||
Deprecations:
|
||||
^^^^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -613,7 +613,7 @@ class ActorCriticPolicy(BasePolicy):
|
|||
"""
|
||||
return self.get_distribution(observation).get_actions(deterministic=deterministic)
|
||||
|
||||
def evaluate_actions(self, obs: th.Tensor, actions: th.Tensor) -> Tuple[th.Tensor, th.Tensor, th.Tensor]:
|
||||
def evaluate_actions(self, obs: th.Tensor, actions: th.Tensor) -> Tuple[th.Tensor, th.Tensor, Optional[th.Tensor]]:
|
||||
"""
|
||||
Evaluate actions according to the current policy,
|
||||
given the observations.
|
||||
|
|
@ -629,7 +629,8 @@ class ActorCriticPolicy(BasePolicy):
|
|||
distribution = self._get_action_dist_from_latent(latent_pi)
|
||||
log_prob = distribution.log_prob(actions)
|
||||
values = self.value_net(latent_vf)
|
||||
return values, log_prob, distribution.entropy()
|
||||
entropy = distribution.entropy()
|
||||
return values, log_prob, entropy
|
||||
|
||||
def get_distribution(self, obs: th.Tensor) -> Distribution:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ def test_get_distribution(dummy_model_distribution_obs_and_actions):
|
|||
distribution = model.policy.get_distribution(observations)
|
||||
log_prob_2 = distribution.log_prob(actions)
|
||||
entropy_2 = distribution.entropy()
|
||||
assert entropy_1 is not None
|
||||
assert entropy_2 is not None
|
||||
assert th.allclose(log_prob_1, log_prob_2)
|
||||
assert th.allclose(entropy_1, entropy_2)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue