Skip to content

Commit 193ab59

Browse files
committed
guard continuous action range in policy
1 parent 96cfcbf commit 193ab59

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

rl/policy/actor_critic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def select_action(self, state):
8282
a_mean = agent.actor.predict(state)[0] # extract from batch predict
8383
action = a_mean + np.random.normal(
8484
loc=0.0, scale=self.variance, size=a_mean.shape)
85+
action = np.clip(action,
86+
self.env_spec['action_bound_low'],
87+
self.env_spec['action_bound_high'])
8588
return action
8689

8790
def update(self, sys_vars):

rl/policy/noise.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def select_action(self, state):
2525
state = np.expand_dims(state, axis=0)
2626
if self.env_spec['actions'] == 'continuous':
2727
action = agent.actor.predict(state)[0] + self.sample()
28+
action = np.clip(action,
29+
self.env_spec['action_bound_low'],
30+
self.env_spec['action_bound_high'])
2831
else:
2932
Q_state = agent.actor.predict(state)[0]
3033
assert Q_state.ndim == 1

0 commit comments

Comments
 (0)