Comments (5)
First, this repository does NOT use Generalized Advantage Estimation; it uses monte-carlo estimate
for calculating rewards_to_go
(reward
variable in code) and advantages
= rewards_to_go
- V(s_t)
.
The only time we will get an unfinished trajectory is at the end. So an accurate version would be :
# Monte Carlo estimate of returns
rewards = []
if self.buffer.is_terminals[-1]:
discounted_reward = 0
else:
discounted_reward = self.policy_old.critic(self.buffer.states[-1]).item()
for reward, is_terminal in zip(reversed(self.buffer.rewards), reversed(self.buffer.is_terminals)):
if is_terminal:
discounted_reward = 0
discounted_reward = reward + (self.gamma * discounted_reward)
rewards.insert(0, discounted_reward)
Also, the rewards to go calculation introduced in issue #8 seems to be wrong. I am a little busy now and I will look into it later.
So the correct version, as other implementations use, might be just :
# Monte Carlo estimate of returns
rewards = []
if self.buffer.is_terminals[-1]:
discounted_reward = 0
else:
discounted_reward = self.policy_old.critic(self.buffer.states[-1]).item()
for reward in reversed(self.buffer.rewards):
discounted_reward = reward + (self.gamma * discounted_reward)
rewards.insert(0, discounted_reward)
from ppo-pytorch.
You are completely right. If the episode didn't end, you use the critic network (or the critic head of your twinheaded actor critic network) to approximate V(final_state)
from ppo-pytorch.
Your adjusted implementation is fine. I use the same semantic for my A2C rollouts where unfinished episodes are processed by calling critic(last_state). Else, the code just works with finished episodes.
from ppo-pytorch.
This inaccuracy (maybe I should call it a bug) troubles me a lot! Thanks @nikhilbarhate99
Also, I guess there is another issue.
if the loop exit with t >= max_ep_len
, A False
will be added into buffer.is_terminals
([False, False, ..., False]
). When the next episode begins, the buffer continues appending steps in the next episode without clearing the buffer if it did not call update
([False, False, ... False] (first episode) + [False, False, ..., True] (next episode)
). So when we calculated the accumulated rewards, the rewards will be accumulated through the two episodes, which is not what we expect.
from ppo-pytorch.
This inaccuracy (maybe I should call it a bug) troubles me a lot! Thanks @nikhilbarhate99 Also, I guess there is another issue.
if the loop exit with
t >= max_ep_len
, AFalse
will be added intobuffer.is_terminals
([False, False, ..., False]
). When the next episode begins, the buffer continues appending steps in the next episode without clearing the buffer if it did not callupdate
([False, False, ... False] (first episode) + [False, False, ..., True] (next episode)
). So when we calculated the accumulated rewards, the rewards will be accumulated through the two episodes, which is not what we expect.
I think we can follow the practice of the latest version of gym: add a variable truncated (bool)
: indicates whether the game is still incomplete when t=max_ep_len
. Then in the discounted_reward
loop add:
if truncated : discounted_reward = self.policy_old.critic(self.buffer.states[-1]).item()
elif is_terminal: discounted_reward = 0
from ppo-pytorch.
Related Issues (20)
- How to improve the performance based on your code? HOT 1
- how can I use this code for a problem with 3 different actions? HOT 1
- About environment configuration HOT 2
- Convolutional? HOT 1
- Confusion about the loss function HOT 1
- roboschool is deprecated HOT 1
- error HOT 5
- Setting Model to eval() mode in test.py
- Would a shared network work ?
- Test results are not good
- Continuous action space should use Independent Normal instead of MultivariateNormal HOT 1
- optimize the existing Chinese generation model
- question
- ValueError: expected sequence of length 8 at dim 1 (got 0) HOT 1
- policy_old完全看不出作用 HOT 6
- the version problem about gym and roboschool HOT 2
- (Solved) No env.reset() at the end of each training epoch. HOT 2
- 为什么新的版本在k epochs更新时不重新计算advantages?
- If I run test.py, there are these problems, how to solve them?
- Environment setting about python version, gym and roboschool
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ppo-pytorch.