Scale actor network output to the action space bounds in Keras Rl












0















I am trying to implement DDPG from Keras RL and have the following actor network.



actor = Sequential()
actor.add(Flatten(input_shape=(1,) + env.observation_space.shape))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(nb_actions))
actor.add(Activation('linear'))


However, I would prefer to have the output scaled to a custom gym environment action space bounds for my problem. env.action_space.



https://pemami4911.github.io/blog/2016/08/21/ddpg-rl.html shows this using the tflearn api where they use



def create_actor_network(self):
inputs = tflearn.input_data(shape=[None, self.s_dim])
net = tflearn.fully_connected(inputs, 400)
net = tflearn.layers.normalization.batch_normalization(net)
net = tflearn.activations.relu(net)
net = tflearn.fully_connected(net, 300)
net = tflearn.layers.normalization.batch_normalization(net)
net = tflearn.activations.relu(net)
# Final layer weights are init to Uniform[-3e-3, 3e-3]
w_init = tflearn.initializations.uniform(minval=-0.003, maxval=0.003)
out = tflearn.fully_connected(
net, self.a_dim, activation='tanh', weights_init=w_init)
# Scale output to -action_bound to action_bound
scaled_out = tf.multiply(out, self.action_bound)
return inputs, out, scaled_out


What is the equivalent command for scaling the output layer according to my requirements?










share|improve this question

























  • I do not want to write an answer but I realized I have to use a squashing function like tanh or sigmoid to map the network output to a range. Then define a function which will map the value from -1/+1 or 0/1 to the gym environment bounds. This is a more apt method for me since my custom gym environment bounds are not centered around 0

    – CS101
    Nov 21 '18 at 1:58













  • If my arguement is correct, can anyone tell me what kind of mapping should I define in my defined function. Shoulld I use proportional relationship between -1/+1 and my environment bounds or something more complex?

    – CS101
    Nov 21 '18 at 1:59
















0















I am trying to implement DDPG from Keras RL and have the following actor network.



actor = Sequential()
actor.add(Flatten(input_shape=(1,) + env.observation_space.shape))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(nb_actions))
actor.add(Activation('linear'))


However, I would prefer to have the output scaled to a custom gym environment action space bounds for my problem. env.action_space.



https://pemami4911.github.io/blog/2016/08/21/ddpg-rl.html shows this using the tflearn api where they use



def create_actor_network(self):
inputs = tflearn.input_data(shape=[None, self.s_dim])
net = tflearn.fully_connected(inputs, 400)
net = tflearn.layers.normalization.batch_normalization(net)
net = tflearn.activations.relu(net)
net = tflearn.fully_connected(net, 300)
net = tflearn.layers.normalization.batch_normalization(net)
net = tflearn.activations.relu(net)
# Final layer weights are init to Uniform[-3e-3, 3e-3]
w_init = tflearn.initializations.uniform(minval=-0.003, maxval=0.003)
out = tflearn.fully_connected(
net, self.a_dim, activation='tanh', weights_init=w_init)
# Scale output to -action_bound to action_bound
scaled_out = tf.multiply(out, self.action_bound)
return inputs, out, scaled_out


What is the equivalent command for scaling the output layer according to my requirements?










share|improve this question

























  • I do not want to write an answer but I realized I have to use a squashing function like tanh or sigmoid to map the network output to a range. Then define a function which will map the value from -1/+1 or 0/1 to the gym environment bounds. This is a more apt method for me since my custom gym environment bounds are not centered around 0

    – CS101
    Nov 21 '18 at 1:58













  • If my arguement is correct, can anyone tell me what kind of mapping should I define in my defined function. Shoulld I use proportional relationship between -1/+1 and my environment bounds or something more complex?

    – CS101
    Nov 21 '18 at 1:59














0












0








0








I am trying to implement DDPG from Keras RL and have the following actor network.



actor = Sequential()
actor.add(Flatten(input_shape=(1,) + env.observation_space.shape))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(nb_actions))
actor.add(Activation('linear'))


However, I would prefer to have the output scaled to a custom gym environment action space bounds for my problem. env.action_space.



https://pemami4911.github.io/blog/2016/08/21/ddpg-rl.html shows this using the tflearn api where they use



def create_actor_network(self):
inputs = tflearn.input_data(shape=[None, self.s_dim])
net = tflearn.fully_connected(inputs, 400)
net = tflearn.layers.normalization.batch_normalization(net)
net = tflearn.activations.relu(net)
net = tflearn.fully_connected(net, 300)
net = tflearn.layers.normalization.batch_normalization(net)
net = tflearn.activations.relu(net)
# Final layer weights are init to Uniform[-3e-3, 3e-3]
w_init = tflearn.initializations.uniform(minval=-0.003, maxval=0.003)
out = tflearn.fully_connected(
net, self.a_dim, activation='tanh', weights_init=w_init)
# Scale output to -action_bound to action_bound
scaled_out = tf.multiply(out, self.action_bound)
return inputs, out, scaled_out


What is the equivalent command for scaling the output layer according to my requirements?










share|improve this question
















I am trying to implement DDPG from Keras RL and have the following actor network.



actor = Sequential()
actor.add(Flatten(input_shape=(1,) + env.observation_space.shape))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(16))
actor.add(Activation('relu'))
actor.add(Dense(nb_actions))
actor.add(Activation('linear'))


However, I would prefer to have the output scaled to a custom gym environment action space bounds for my problem. env.action_space.



https://pemami4911.github.io/blog/2016/08/21/ddpg-rl.html shows this using the tflearn api where they use



def create_actor_network(self):
inputs = tflearn.input_data(shape=[None, self.s_dim])
net = tflearn.fully_connected(inputs, 400)
net = tflearn.layers.normalization.batch_normalization(net)
net = tflearn.activations.relu(net)
net = tflearn.fully_connected(net, 300)
net = tflearn.layers.normalization.batch_normalization(net)
net = tflearn.activations.relu(net)
# Final layer weights are init to Uniform[-3e-3, 3e-3]
w_init = tflearn.initializations.uniform(minval=-0.003, maxval=0.003)
out = tflearn.fully_connected(
net, self.a_dim, activation='tanh', weights_init=w_init)
# Scale output to -action_bound to action_bound
scaled_out = tf.multiply(out, self.action_bound)
return inputs, out, scaled_out


What is the equivalent command for scaling the output layer according to my requirements?







python tensorflow keras deep-learning keras-rl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 1:19









Milo Lu

1,61511427




1,61511427










asked Nov 21 '18 at 0:39









CS101CS101

366




366













  • I do not want to write an answer but I realized I have to use a squashing function like tanh or sigmoid to map the network output to a range. Then define a function which will map the value from -1/+1 or 0/1 to the gym environment bounds. This is a more apt method for me since my custom gym environment bounds are not centered around 0

    – CS101
    Nov 21 '18 at 1:58













  • If my arguement is correct, can anyone tell me what kind of mapping should I define in my defined function. Shoulld I use proportional relationship between -1/+1 and my environment bounds or something more complex?

    – CS101
    Nov 21 '18 at 1:59



















  • I do not want to write an answer but I realized I have to use a squashing function like tanh or sigmoid to map the network output to a range. Then define a function which will map the value from -1/+1 or 0/1 to the gym environment bounds. This is a more apt method for me since my custom gym environment bounds are not centered around 0

    – CS101
    Nov 21 '18 at 1:58













  • If my arguement is correct, can anyone tell me what kind of mapping should I define in my defined function. Shoulld I use proportional relationship between -1/+1 and my environment bounds or something more complex?

    – CS101
    Nov 21 '18 at 1:59

















I do not want to write an answer but I realized I have to use a squashing function like tanh or sigmoid to map the network output to a range. Then define a function which will map the value from -1/+1 or 0/1 to the gym environment bounds. This is a more apt method for me since my custom gym environment bounds are not centered around 0

– CS101
Nov 21 '18 at 1:58







I do not want to write an answer but I realized I have to use a squashing function like tanh or sigmoid to map the network output to a range. Then define a function which will map the value from -1/+1 or 0/1 to the gym environment bounds. This is a more apt method for me since my custom gym environment bounds are not centered around 0

– CS101
Nov 21 '18 at 1:58















If my arguement is correct, can anyone tell me what kind of mapping should I define in my defined function. Shoulld I use proportional relationship between -1/+1 and my environment bounds or something more complex?

– CS101
Nov 21 '18 at 1:59





If my arguement is correct, can anyone tell me what kind of mapping should I define in my defined function. Shoulld I use proportional relationship between -1/+1 and my environment bounds or something more complex?

– CS101
Nov 21 '18 at 1:59












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fstackoverflow.com%2fquestions%2f53403722%2fscale-actor-network-output-to-the-action-space-bounds-in-keras-rl%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 Stack Overflow!


  • 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.


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%2fstackoverflow.com%2fquestions%2f53403722%2fscale-actor-network-output-to-the-action-space-bounds-in-keras-rl%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

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]