my brittle PPO implementation for Cartpole, how can I make it more resilient?












1












$begingroup$


I implemented the clipped objective PPO-clip as explained here: https://spinningup.openai.com/en/latest/algorithms/ppo.html



Basically I used a dummy actor network to find the new action probability without training the local actor network.



"""use temp_actor to get new prob so we don't update the actual actor until
we do the clip op"""
curr_weights = self.actor.get_weights()
self.temp_actor.set_weights(curr_weights)
self.temp_actor.fit(state, advantages, epochs=1, verbose=0)
new_policy = self.temp_actor.predict(state, batch_size=1).flatten()
new_aprob = new_policy[action]


Then I worked out the ratio of action probabilities and implemented the PPO clipping parts of the algorithm:



ratio = new_aprob / old_aprob
# scale = min(ratio * advantages, K.clip(ratio, 1 - self.epsilon, 1 + self.epsilon) * advantages)
no_clip = ratio * advantages
clipped = np.clip(ratio, 1 - self.epsilon, 1 + self.epsilon) * advantages

self.actor.fit(state, np.minimum(no_clip, clipped), epochs=1, verbose=0)


The full code is here (please excuse some coarse language in the comments): https://github.com/nyck33/openai_my_implements/blob/master/cartpole/my_ppo_cartpole.py



It seems to work but for Cartpole, slightly slower than my DQN and VPG implementations here: https://github.com/nyck33/openai_my_implements/tree/master/cartpole



The std deviation of returns seems a bit lower than with VPG or DQN so I'm guessing the clipping is stabilizing the learning somewhat. However, once I change the learning rates to anything else than what I currently have, it stops learning, ie. it's very brittle.



Thus, I'm looking for any advice here to make it more resilient.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    Your question is not about code review by itself but about learning, you can remove that from your title and the last phrase as well since that is a second question (and a meta question) inside the question.
    $endgroup$
    – Pedro Henrique Monforte
    11 hours ago










  • $begingroup$
    @PedroHenriqueMonforte, sounds good! Had no idea what a meta question was until now but it makes sense.
    $endgroup$
    – mLstudent33
    3 mins ago
















1












$begingroup$


I implemented the clipped objective PPO-clip as explained here: https://spinningup.openai.com/en/latest/algorithms/ppo.html



Basically I used a dummy actor network to find the new action probability without training the local actor network.



"""use temp_actor to get new prob so we don't update the actual actor until
we do the clip op"""
curr_weights = self.actor.get_weights()
self.temp_actor.set_weights(curr_weights)
self.temp_actor.fit(state, advantages, epochs=1, verbose=0)
new_policy = self.temp_actor.predict(state, batch_size=1).flatten()
new_aprob = new_policy[action]


Then I worked out the ratio of action probabilities and implemented the PPO clipping parts of the algorithm:



ratio = new_aprob / old_aprob
# scale = min(ratio * advantages, K.clip(ratio, 1 - self.epsilon, 1 + self.epsilon) * advantages)
no_clip = ratio * advantages
clipped = np.clip(ratio, 1 - self.epsilon, 1 + self.epsilon) * advantages

self.actor.fit(state, np.minimum(no_clip, clipped), epochs=1, verbose=0)


The full code is here (please excuse some coarse language in the comments): https://github.com/nyck33/openai_my_implements/blob/master/cartpole/my_ppo_cartpole.py



It seems to work but for Cartpole, slightly slower than my DQN and VPG implementations here: https://github.com/nyck33/openai_my_implements/tree/master/cartpole



The std deviation of returns seems a bit lower than with VPG or DQN so I'm guessing the clipping is stabilizing the learning somewhat. However, once I change the learning rates to anything else than what I currently have, it stops learning, ie. it's very brittle.



Thus, I'm looking for any advice here to make it more resilient.










share|improve this question











$endgroup$








  • 1




    $begingroup$
    Your question is not about code review by itself but about learning, you can remove that from your title and the last phrase as well since that is a second question (and a meta question) inside the question.
    $endgroup$
    – Pedro Henrique Monforte
    11 hours ago










  • $begingroup$
    @PedroHenriqueMonforte, sounds good! Had no idea what a meta question was until now but it makes sense.
    $endgroup$
    – mLstudent33
    3 mins ago














1












1








1





$begingroup$


I implemented the clipped objective PPO-clip as explained here: https://spinningup.openai.com/en/latest/algorithms/ppo.html



Basically I used a dummy actor network to find the new action probability without training the local actor network.



"""use temp_actor to get new prob so we don't update the actual actor until
we do the clip op"""
curr_weights = self.actor.get_weights()
self.temp_actor.set_weights(curr_weights)
self.temp_actor.fit(state, advantages, epochs=1, verbose=0)
new_policy = self.temp_actor.predict(state, batch_size=1).flatten()
new_aprob = new_policy[action]


Then I worked out the ratio of action probabilities and implemented the PPO clipping parts of the algorithm:



ratio = new_aprob / old_aprob
# scale = min(ratio * advantages, K.clip(ratio, 1 - self.epsilon, 1 + self.epsilon) * advantages)
no_clip = ratio * advantages
clipped = np.clip(ratio, 1 - self.epsilon, 1 + self.epsilon) * advantages

self.actor.fit(state, np.minimum(no_clip, clipped), epochs=1, verbose=0)


The full code is here (please excuse some coarse language in the comments): https://github.com/nyck33/openai_my_implements/blob/master/cartpole/my_ppo_cartpole.py



It seems to work but for Cartpole, slightly slower than my DQN and VPG implementations here: https://github.com/nyck33/openai_my_implements/tree/master/cartpole



The std deviation of returns seems a bit lower than with VPG or DQN so I'm guessing the clipping is stabilizing the learning somewhat. However, once I change the learning rates to anything else than what I currently have, it stops learning, ie. it's very brittle.



Thus, I'm looking for any advice here to make it more resilient.










share|improve this question











$endgroup$




I implemented the clipped objective PPO-clip as explained here: https://spinningup.openai.com/en/latest/algorithms/ppo.html



Basically I used a dummy actor network to find the new action probability without training the local actor network.



"""use temp_actor to get new prob so we don't update the actual actor until
we do the clip op"""
curr_weights = self.actor.get_weights()
self.temp_actor.set_weights(curr_weights)
self.temp_actor.fit(state, advantages, epochs=1, verbose=0)
new_policy = self.temp_actor.predict(state, batch_size=1).flatten()
new_aprob = new_policy[action]


Then I worked out the ratio of action probabilities and implemented the PPO clipping parts of the algorithm:



ratio = new_aprob / old_aprob
# scale = min(ratio * advantages, K.clip(ratio, 1 - self.epsilon, 1 + self.epsilon) * advantages)
no_clip = ratio * advantages
clipped = np.clip(ratio, 1 - self.epsilon, 1 + self.epsilon) * advantages

self.actor.fit(state, np.minimum(no_clip, clipped), epochs=1, verbose=0)


The full code is here (please excuse some coarse language in the comments): https://github.com/nyck33/openai_my_implements/blob/master/cartpole/my_ppo_cartpole.py



It seems to work but for Cartpole, slightly slower than my DQN and VPG implementations here: https://github.com/nyck33/openai_my_implements/tree/master/cartpole



The std deviation of returns seems a bit lower than with VPG or DQN so I'm guessing the clipping is stabilizing the learning somewhat. However, once I change the learning rates to anything else than what I currently have, it stops learning, ie. it's very brittle.



Thus, I'm looking for any advice here to make it more resilient.







deep-learning reinforcement-learning openai-gym






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 mins ago







mLstudent33

















asked 21 hours ago









mLstudent33mLstudent33

507




507








  • 1




    $begingroup$
    Your question is not about code review by itself but about learning, you can remove that from your title and the last phrase as well since that is a second question (and a meta question) inside the question.
    $endgroup$
    – Pedro Henrique Monforte
    11 hours ago










  • $begingroup$
    @PedroHenriqueMonforte, sounds good! Had no idea what a meta question was until now but it makes sense.
    $endgroup$
    – mLstudent33
    3 mins ago














  • 1




    $begingroup$
    Your question is not about code review by itself but about learning, you can remove that from your title and the last phrase as well since that is a second question (and a meta question) inside the question.
    $endgroup$
    – Pedro Henrique Monforte
    11 hours ago










  • $begingroup$
    @PedroHenriqueMonforte, sounds good! Had no idea what a meta question was until now but it makes sense.
    $endgroup$
    – mLstudent33
    3 mins ago








1




1




$begingroup$
Your question is not about code review by itself but about learning, you can remove that from your title and the last phrase as well since that is a second question (and a meta question) inside the question.
$endgroup$
– Pedro Henrique Monforte
11 hours ago




$begingroup$
Your question is not about code review by itself but about learning, you can remove that from your title and the last phrase as well since that is a second question (and a meta question) inside the question.
$endgroup$
– Pedro Henrique Monforte
11 hours ago












$begingroup$
@PedroHenriqueMonforte, sounds good! Had no idea what a meta question was until now but it makes sense.
$endgroup$
– mLstudent33
3 mins ago




$begingroup$
@PedroHenriqueMonforte, sounds good! Had no idea what a meta question was until now but it makes sense.
$endgroup$
– mLstudent33
3 mins ago










0






active

oldest

votes












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "557"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f49625%2fmy-brittle-ppo-implementation-for-cartpole-how-can-i-make-it-more-resilient%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Data Science Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f49625%2fmy-brittle-ppo-implementation-for-cartpole-how-can-i-make-it-more-resilient%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to label and detect the document text images

Vallis Paradisi

Tabula Rosettana