I am working on a robotic arm controlled by a DQN + a python script I wrote. The DQN receives the 5 joint states, the coordinates of a target, the coordinates of the obstacle and outputs the best action to take (in terms of joint rotations). The python script checks if the action suggested by the DQN is safe. If it is, it performs it. Otherwise, it performs the second highest-ranking action from the DQN; and so on. If no action is possible, collision: we fail.

During training, this python functionality wasn't present: the arm learned how to behave without anything else to correct his behaviour. With this addition on the already-trained network, the performance raised from 78 to 95%. Now my advisor (bachelor's thesis) asked me to leave the external controller on during training to check whether this improves learning.


Here's what happens during training; at each step:

  1. the ANN selects an action
  2. if it is legal, the python script executes it, otherwise it chooses another one.

Now... On which action should I perform backprop? The one proposed by the arm or the one which was really executed? (So, which action should I perform backprop on?)

I am really confused. On the one hand, the arm did choose an action so my idea was that we should, in fact, learn on THAT action. On the other hand, during the exploration phase ($\epsilon$ greedy), we backprop on the action which was randomly selected and executed, with no interest on what was the output of the arm. So, it would be rational too, in this case, to perform backprop on the action really executed; so the one chosen by the script.

What is the right thing to do here?. (Bonus question: is it reasonable to train with this functionality on? Wouldn't it be better to train the Network by itself, and then later, enhance its performance with this functionality?)


Q-learning - which DQN is based on - is an off-policy reinforcement learning (RL) method. That means it can learn a target policy of optimal control whilst acting using a different behaviour policy. In addition, provided you use single step learning (as opposed to n-step or Q($\lambda$) variants), you don't need to worry much about the details of the behaviour policy. It is more efficient to learn from behaviour policies closer to the current best guess at optimal, but possible to learn from almost anything, including random behaviour.

So it doesn't really matter too much if you change the behaviour during training.

In your case, the script is actually doing more than just changing the behaviour. It is consistently filtering out state/action pairs that you have decided should never be taken, as a domain expert. This has two major consequences:

  • It reduces the search space by whatever fraction of state/actions are now denied by your safety script.

  • It prevents the agent from ever learning about certain state/action pairs, as they are never experienced.

The first point means that your learning should in theory be more efficient. As for how much, you will have to try and see. It might only be a small amount if the problem states and actions are unlikely to be reached during exploration from near-optimal behaviour.

The second point means that your agent will never learn by itself to avoid the problem state/action combinations. So you will always need to use the safety script.

In fact you can view the safety script as a modification to the environment (as opposed to a modification to the agent), if its decisions are strict and consistent. Filtering available actions is a standard mechanism in RL when action space may vary depending on state.

On which action should I perform backprop?

In DQN, you don't "perform backprop" on an action. Instead you either use directly or store some observed data about the step: $s, a, r, s'$ where $s$ is the start state, $a$ the action taken, $r$ the immediate reward, and $s'$ the resulting state. You then update the the current action value estimate(s) based on a TD target $\delta = r + \gamma \text{max}_{a'} Q(s,a')$ either online or from the experience table.

When Q-learning learns, it updates the estimate for the action value $Q(s, a)$ - and $a$ is taken from the actual behaviour (otherwise the agent will update its estimate of an action that it didn't take). So your answer here is to use - or more likely store in the experience table - the action actually taken. If the action recommended as optimal at that time is different, ignore the difference, what matters is the observed experience.

| improve this answer | |
  • $\begingroup$ I don't know if it is appropriate to ask about this here in the comments, but what do you think about using Duelling architecture in this situation? I thought that maybe decoupling state-evaluation and action-evaluation may help, since we have an external controller. what do you think? $\endgroup$ – olinarr May 11 '19 at 14:36
  • 1
    $\begingroup$ @NetHacker: I don't know about the dueling architecture, so cannot answer here. I think anyway that it is a different enough topic that you should ask a new question. The general rule is that comments are for clarifying posts or suggesting corrections to them. Follow-up questions with significant new details should ideally be new questions on the site $\endgroup$ – Neil Slater May 11 '19 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.