From 5ddda44a747c8c07c607493c06024f1cae6f89b0 Mon Sep 17 00:00:00 2001 From: thisray Date: Mon, 16 Nov 2020 23:27:46 +0800 Subject: [PATCH] Fix arguments order of `explained_variance()` (#227) * Fix for arguments order in explained_variance() Fix for arguments order in explained_variance() in PPO * Fix for arguments order in explained_variance() Fix for arguments order in explained_variance() in a2c * Fix for arguments order in explained_variance() update changelog.rst --- docs/misc/changelog.rst | 3 ++- stable_baselines3/a2c/a2c.py | 2 +- stable_baselines3/ppo/ppo.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/misc/changelog.rst b/docs/misc/changelog.rst index 6c4efa9..6f572a7 100644 --- a/docs/misc/changelog.rst +++ b/docs/misc/changelog.rst @@ -27,6 +27,7 @@ New Features: Bug Fixes: ^^^^^^^^^^ - Fixed bug where code added VecTranspose on channel-first image environments (thanks @qxcv) +- Fixed bug that the arguments order of ``explained_variance()`` in ``ppo.py`` and ``a2c.py`` is not correct (@thisray) Deprecations: ^^^^^^^^^^^^^ @@ -515,4 +516,4 @@ And all the contributors: @MarvineGothic @jdossgollin @stheid @SyllogismRXS @rusu24edward @jbulow @Antymon @seheevic @justinkterry @edbeeching @flodorner @KuKuXia @NeoExtended @PartiallyTyped @mmcenta @richardwu @kinalmehta @rolandgvc @tkelestemur @mloo3 @tirafesi @blurLake @koulakis @joeljosephjin @shwang @rk37 @andyshih12 @RaphaelWag @xicocaio -@diditforlulz273 @liorcohen5 @ManifoldFR @mloo3 @SwamyDev @wmmc88 @megan-klaiber +@diditforlulz273 @liorcohen5 @ManifoldFR @mloo3 @SwamyDev @wmmc88 @megan-klaiber @thisray diff --git a/stable_baselines3/a2c/a2c.py b/stable_baselines3/a2c/a2c.py index 42400c5..4720526 100644 --- a/stable_baselines3/a2c/a2c.py +++ b/stable_baselines3/a2c/a2c.py @@ -156,7 +156,7 @@ class A2C(OnPolicyAlgorithm): th.nn.utils.clip_grad_norm_(self.policy.parameters(), self.max_grad_norm) self.policy.optimizer.step() - explained_var = explained_variance(self.rollout_buffer.returns.flatten(), self.rollout_buffer.values.flatten()) + explained_var = explained_variance(self.rollout_buffer.values.flatten(), self.rollout_buffer.returns.flatten()) self._n_updates += 1 logger.record("train/n_updates", self._n_updates, exclude="tensorboard") diff --git a/stable_baselines3/ppo/ppo.py b/stable_baselines3/ppo/ppo.py index b9ae9fb..0f75c26 100644 --- a/stable_baselines3/ppo/ppo.py +++ b/stable_baselines3/ppo/ppo.py @@ -220,7 +220,7 @@ class PPO(OnPolicyAlgorithm): break self._n_updates += self.n_epochs - explained_var = explained_variance(self.rollout_buffer.returns.flatten(), self.rollout_buffer.values.flatten()) + explained_var = explained_variance(self.rollout_buffer.values.flatten(), self.rollout_buffer.returns.flatten()) # Logs logger.record("train/entropy_loss", np.mean(entropy_losses))