Skip to main content
Open In Colab The tabular agent of the previous section saw the room through 216 coarse states and could choose among five commands. In this section the agent receives all 28 numbers of the navigation MDP and outputs any forward speed and turn rate within the TurtleBot3 Waffle’s limits. The method is deep deterministic policy gradient (DDPG) (Lillicrap et al., 2015), built on the deterministic policy gradient theorem (Silver et al., 2014). It is one of the algorithms the turtlebot3_drlnav project trains in Gazebo and runs on the real robot. The simulator, reward and episode rules are unchanged.

A deterministic actor and a critic

With a continuous action, the greedy step of Q-learning, max⁡aQ(s,a)\max_a Q(s, a), becomes an optimization problem over (v,ω)(v, \omega) at every time step. DDPG avoids solving it by training a second network to do it. It keeps two networks:
  • The actor μθ(s)\mu_\theta(s) maps the 28-number state to an action. Its output layer is a tanh⁡\tanh, so each output lies in [−1,1][-1, 1], and it is rescaled to v∈[0,0.26]v \in [0, 0.26] m/s and ω∈[−1.82,1.82]\omega \in [-1.82, 1.82] rad/s.
  • The critic Qw(s,a)Q_w(s, a) maps a state and an action to an estimate of the action value qμ(s,a)q^\mu(s, a) of the actor’s policy.
A method that learns a policy and a value function together is an actor-critic method. The REINFORCE section reached the same structure from the policy side, when it subtracted a learned baseline vπ(st)v_\pi(s_t) from the return. The actor is deterministic: the same state always gives the same command. That suits a velocity controller, which must send one command every 0.2 s and should send smooth ones. The REINFORCE and PPO sections instead use stochastic policies πθ(a∣s)\pi_\theta(a \mid s) and sample from them.

The deterministic policy gradient

The actor should maximize the expected return from the start states, J(θ)=Es0∼p0[vμ(s0)],J(\theta) = \mathbb E_{s_0 \sim p_0}\big[ v^\mu(s_0) \big], where p0p_0 is the distribution of start states and vμv^\mu is the value of following μθ\mu_\theta. The deterministic policy gradient theorem (Silver et al., 2014) gives its gradient as an expectation over ρμ\rho^\mu, the discounted distribution of states visited under μθ\mu_\theta: ∇θJ(θ)=Es∼ρμ[∇θμθ(s) ∇aqμ(s,a)∣a=μθ(s)].\nabla_\theta J(\theta) = \mathbb E_{s \sim \rho^\mu}\Big[ \nabla_\theta \mu_\theta(s)\, \nabla_a q^\mu(s, a) \big|_{a = \mu_\theta(s)} \Big]. Read it as the chain rule. The critic says in which direction a small change of (v,ω)(v, \omega) would raise the value, and ∇θμθ(s)\nabla_\theta \mu_\theta(s) says how to change the actor’s weights to move its output that way. Compare it with the policy gradient theorem of the REINFORCE section, for a stochastic policy: ∇θJ(πθ)=Eπθ[∇θlog⁡πθ(a∣s) Qπθ(s,a)].\nabla_\theta J(\pi_\theta) = \mathbb{E}_{\pi_\theta} \left[ \nabla_\theta \log \pi_\theta (a \mid s)\, Q^{\pi_\theta}(s, a) \right]. That gradient raises the log-probability of each sampled action in proportion to its value. It needs the value only at the actions the robot took, and it averages over many sampled actions to find the direction. The deterministic gradient needs one action per state, but it needs the slope ∇aqμ\nabla_a q^\mu of the value with respect to the action. Only a differentiable critic can supply that slope. The log-probability term is gone because a deterministic policy has no distribution over actions to differentiate. DDPG replaces qμq^\mu with the critic QwQ_w, so the actor’s loss is simply −Qw(s,μθ(s))-Q_w(s, \mu_\theta(s)) averaged over a batch of states.

Learning the critic

The critic learns by temporal differences, like the Q-table. For a stored transition (s,a,r,s′)(s, a, r, s') the target is y=r+γ (1−1[terminal]) Qw′(s′,μθ′(s′)),y = r + \gamma\,(1 - \mathbb 1[\text{terminal}])\, Q_{w'}\big(s', \mu_{\theta'}(s')\big), and the critic minimizes (Qw(s,a)−y)2(Q_w(s, a) - y)^2 over a batch. The difference y−Qw(s,a)y - Q_w(s, a) is the TD error of TD prediction, and the critic’s loss is its square. Compared with the Q-learning target, max⁡aQ(s′,a)\max_a Q(s', a) is replaced by the value of the action the actor would take in s′s'. As before, a goal or a collision cuts the bootstrap term and a timeout does not. In the MDP chapter’s terms, the critic does policy evaluation for μ\mu. Its target is a one-sample estimate of the right side of the Bellman expectation equation for action values, qμ(s,a)=Rsa+γ∑s′Pss′a qμ(s′,μ(s′)),q^\mu(s, a) = \mathcal R^a_s + \gamma \sum_{s'} \mathcal P^a_{ss'} \, q^\mu\big(s', \mu(s')\big), with the stored next state in place of the sum and a network in place of the table. The actor step is policy improvement. Policy iteration in the navigation MDP section set π′(s)=arg⁡max⁡aqπ(s,a)\pi'(s) = \arg\max_a q_\pi(s, a) exactly. The actor takes one gradient step toward a larger Qw(s,μθ(s))Q_w(s, \mu_\theta(s)) instead. DDPG alternates the two steps without running either to convergence, which makes it a form of approximate policy iteration. Qw′Q_{w'} and μθ′\mu_{\theta'} are target networks: slowly moving copies of the critic and the actor. Three more pieces keep training stable:
  • A replay buffer stores the last 200,000 transitions, and each update draws a random batch of 256 from it. Consecutive steps of one trajectory are strongly correlated, and random batches break that correlation. Reusing old transitions is allowed because DDPG, like Q-learning, is off-policy. The target uses μθ′(s′)\mu_{\theta'}(s'), the action of the current target actor, not the action stored in the buffer. A transition collected by an older, noisier policy is therefore still a valid sample of the dynamics. REINFORCE cannot reuse transitions this way, because its gradient is an expectation over the current policy’s own actions.
  • After each update the target weights move a fraction τ=0.005\tau = 0.005 toward the learned weights, w′←τw+(1−τ)w′w' \leftarrow \tau w + (1 - \tau) w'. The targets yy then change slowly instead of chasing the critic they train.
  • The deterministic actor never explores by itself, so during training Gaussian noise with standard deviation 0.2 is added to its two outputs before rescaling. Lillicrap et al. used temporally correlated Ornstein-Uhlenbeck noise. Independent noise is simpler and works here. The first 5000 steps use uniformly random actions to fill the buffer.
The training loop follows the description above. Every 10,000 steps it runs the actor without noise on 50 fixed episodes and records three numbers: the fraction that reach the goal, the critic’s estimate Qw(s0,μθ(s0))Q_w(s_0, \mu_\theta(s_0)) of the start states’ value, and the discounted return the robot actually collected from those starts. If the critic is accurate, the last two should agree. The critic’s target does not stop at the 40 s timeout, so its estimate includes rewards the robot would collect after it. To measure the same quantity, the evaluation keeps each episode running past the timeout until a goal or a collision, or for at most 1,000 steps, where γ1000\gamma^{1000} is below 10−410^{-4}. The success rate still counts only goals reached within 40 s.
Output from cell 6 Left: the fraction of 50 fixed episodes in which the actor, run without noise, reaches the goal. Right: the critic’s estimate of the start states’ value next to the discounted return the robot actually collected from them. The actor learns the task for a while: after 30,000 steps it reaches the goal in 44% of the evaluation episodes. Ten thousand steps later it reaches the goal in none of them, and it stays below a quarter until 90,000 steps. Only the last evaluation, at 100,000 steps, is better, at 60%. The right panel shows why. From 30,000 steps on, the critic’s estimate of the start-state value is far above the return the robot collects. At 40,000 and 50,000 steps the critic predicts about 24 for the start states, while the robot collects between −5-5 and −3-3 from them. The gap narrows only at the end of training, where the critic still predicts about 16 against an actual return of about 7. For comparison, the agent of the next section reaches the goal in almost every episode and collects about 15. This is the overestimation that Fujimoto et al. identified in DDPG (Fujimoto2018-uc). The actor is trained to climb the critic, so it plays the role of the max in the value-iteration backup of the navigation MDP section. With exact values, the max picks the best action. With noisy estimates, it tends to pick the action whose error happens to be largest, so the maximum of the estimates is biased upward even when each estimate is unbiased. Wherever the critic overestimates an action, the actor moves toward that action, and the bootstrapped targets pass the error back to earlier states. Nothing in the loop pulls the estimate back down, because the agent rarely tries the alternative actions that would show the critic is wrong. The run above produced one collapse and a partial recovery at the end. Other seeds and step sizes give different curves, often with several rises and collapses, and the best and worst moments depend on luck. The training loop kept the actor from its best evaluation. On the 300 test episodes of the earlier sections:
The best DDPG checkpoint, picked by an evaluation on 50 episodes, does worse than the 216-state Q-table of the previous section, even though it sees the full lidar scan and steers with continuous commands. Keeping the best checkpoint hides the instability without removing it. You cannot ship a training method whose result depends on when you stop it. The next section changes how the critic’s targets are built and gets a stable learner from the same networks.

References

  • Lillicrap, T., Hunt, J., Pritzel, A., Heess, N., Erez, T., et al. (2015). Continuous control with deep reinforcement learning. arXiv [cs.LG]. Link
  • Silver, D., Lever, G., Heess, N., Degris, T., Wierstra, D., et al. (2014). Deterministic Policy Gradient Algorithms. Proceedings of the 31st International Conference on Machine Learning. Link

Found an error on this page? Report an issue.