1. Home
  2. Explore
  3. Computer Science
  4. Deep Reinforcement Learning

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Deep Reinforcement Learning

Deep Reinforcement Learning

Introduction

Deep reinforcement learning (deep RL) combines reinforcement learning with deep neural networks, becoming one of the most exciting areas in control theory and machine learning over the past decade. This approach allows reinforcement learning algorithms to scale to high-dimensional state and action spaces by using neural networks as function approximators for policies, value functions, or quality functions.


Deep Policy Networks

The simplest way to embed a deep neural network into a reinforcement learner is through a deep policy network. The policy function π(s,a)\pi(s, a)π(s,a) gives the probability of taking action aaa given state sss. The policy is parameterized by a neural network with weights θ\thetaθ:

Deep Policy Network: A neural network that takes the state sss as input and outputs a probability distribution over actions, parameterized by weights θ\thetaθ. The goal is to optimize θ\thetaθ to maximize the cumulative future reward.

  • The policy πθ(a∣s)\pi_\theta(a|s)πθ​(a∣s) is a function of the state, often high-dimensional (e.g., pixel space).

  • The neural network outputs probabilities for each action; the agent samples actions based on these probabilities.

  • Optimization over θ\thetaθ is performed using gradient-based methods (e.g., backpropagation) on a loss function that involves the expected future reward.

A classic example is Pong from pixels (Andrej Karpathy's blog), where a deep policy network with ~150 lines of Python code learns to play Pong directly from raw pixel inputs. The network takes over a thousand pixels as input and outputs the probability of moving the paddle up or down.


Policy Gradient Optimization

Policy gradient methods provide a principled way to update policy parameters θ\thetaθ by computing the gradient of the expected cumulative reward with respect to θ\thetaθ. This is more general than neural networks — any parameterized policy can use this approach.

The expected cumulative future reward R(σ∣θ)R(\sigma|\theta)R(σ∣θ) for a policy πθ\pi_\thetaπθ​ can be expressed using the asymptotic state distribution μθ(s)\mu_\theta(s)μθ​(s) and the quality function Q(s,a)Q(s,a)Q(s,a):

R(θ)=∑sμθ(s)∑aπθ(a∣s)Q(s,a)R(\theta) = \sum_s \mu_\theta(s) \sum_a \pi_\theta(a|s) Q(s,a)R(θ)=∑s​μθ​(s)∑a​πθ​(a∣s)Q(s,a)
  • μθ(s)\mu_\theta(s)μθ​(s) is the long-term probability of being in state sss under policy πθ\pi_\thetaπθ​.

  • Q(s,a)Q(s,a)Q(s,a) is the expected future reward from taking action aaa in state sss.

To optimize θ\thetaθ, we compute the gradient ∇θR(θ)\nabla_\theta R(\theta)∇θ​R(θ):

∇θR(θ)=E[Q(s,a)⋅∇θlog⁡πθ(a∣s)]\nabla_\theta R(\theta) = \mathbb{E} \left[ Q(s,a) \cdot \nabla_\theta \log \pi_\theta(a|s) \right]∇θ​R(θ)=E[Q(s,a)⋅∇θ​logπθ​(a∣s)]

This policy gradient is derived using the log-derivative trick:

  1. Start with the expression for R(θ)R(\theta)R(θ).

  2. Compute gradient, noting that μθ(s)\mu_\theta(s)μθ​(s) depends on θ\thetaθ (a subtle point often glossed over).

  3. Rewrite using ∇θπθ(a∣s)=πθ(a∣s)∇θlog⁡πθ(a∣s)\nabla_\theta \pi_\theta(a|s) = \pi_\theta(a|s) \nabla_\theta \log \pi_\theta(a|s)∇θ​πθ​(a∣s)=πθ​(a∣s)∇θ​logπθ​(a∣s).

  4. The result becomes an expectation over the policy of the quality function times the gradient of the log-policy.

The gradient signal ∇θlog⁡πθ(a∣s)⋅Q(s,a)\nabla_\theta \log \pi_\theta(a|s) \cdot Q(s,a)∇θ​logπθ​(a∣s)⋅Q(s,a) is easier to compute with backpropagation and provides the update direction for θ\thetaθ to increase the expected reward.


Deep Q Learning

Deep Q learning is one of the most successful and widely demonstrated deep RL methods. It uses a neural network to approximate the quality function Q(s,a)Q(s,a)Q(s,a), parameterized by weights θ\thetaθ.

Deep Q Learning: A neural network parameterizes the quality function Qθ(s,a)Q_\theta(s,a)Qθ​(s,a), and the network is trained to minimize the temporal difference (TD) error.

The basic Q-learning update (from earlier lectures) is:

Q(s,a)←Q(s,a)+α[R+γmax⁡a′Q(s′,a′)−Q(s,a)]Q(s,a) \leftarrow Q(s,a) + \alpha \left[ R + \gamma \max_{a'} Q(s',a') - Q(s,a) \right]Q(s,a)←Q(s,a)+α[R+γmaxa′​Q(s′,a′)−Q(s,a)]

In deep Q learning, the loss function for the neural network is the mean squared TD error:

L(θ)=E[(R+γmax⁡a′Qθ(s′,a′)−Qθ(s,a))2]\mathcal{L}(\theta) = \mathbb{E}\left[ \left( R + \gamma \max_{a'} Q_{\theta}(s', a') - Q_{\theta}(s,a) \right)^2 \right]L(θ)=E[(R+γmaxa′​Qθ​(s′,a′)−Qθ​(s,a))2]
  • The network is trained using stochastic gradient descent and backpropagation.

  • This replaces storing QQQ values for every state-action pair, which is infeasible for large state spaces (e.g., chess has ~108010^{80}1080 states, Go even more).

  • The neural network acts as a function approximator, extracting low-dimensional features of the quality function.

Applications: DeepMind's Atari game playing is a landmark example. A convolutional neural network takes raw pixel input and learns to play games like Breakout, often discovering strategies that rival expert humans (e.g., drilling a hole in the wall to let the ball bounce behind blocks).

Architecture:

  • Convolutional layers process pixel space.

  • Fully connected layers map to joystick actions.

  • The network learns the optimal QQQ function through trial and error.

The approach achieved human-level control on many Atari games (those above a "human-level" threshold).

Dueling Deep Q Networks (DDQN)

A variation called dueling deep Q networks splits the quality function into two separate networks:

  • Value network V(s)V(s)V(s): estimates the value of being in state sss.

  • Advantage network A(s,a)A(s,a)A(s,a): estimates the advantage of taking action aaa over other actions in state sss.

The quality function is reconstructed as:

Q(s,a)=V(s)+A(s,a)Q(s,a) = V(s) + A(s,a)Q(s,a)=V(s)+A(s,a)

This decomposition is useful when the quality of different actions is very similar for a given state. The two networks are trained jointly — the value network tries to explain as much of QQQ as possible from the state alone, and the advantage network captures the marginal effect of each action. This can improve learning efficiency, especially in games where state differences are more informative than action differences.


Actor-Critic Methods

Actor-critic methods combine the strengths of policy-based and value-based reinforcement learning. They are older than deep RL but have been adapted successfully with neural networks.

Actor-Critic: Two learners — an actor learns a policy π\piπ, and a critic learns a value function VVV (or QQQ). The critic critiques the actor's policy, providing feedback to improve it.

  • Actor: A policy network that decides actions (policy-based learner).

  • Critic: A value network that estimates how good the current state/action is (value-based learner).

Actor-Critic Policy Gradient

A simple implementation uses the policy gradient from earlier, but the quality function QQQ is now provided by the critic. The actor updates its parameters θ\thetaθ using:

∇θJ(θ)=E[Q(s,a)⋅∇θlog⁡πθ(a∣s)]\nabla_\theta J(\theta) = \mathbb{E} \left[ Q(s,a) \cdot \nabla_\theta \log \pi_\theta(a|s) \right]∇θ​J(θ)=E[Q(s,a)⋅∇θ​logπθ​(a∣s)]
  • The critic learns Q(s,a)Q(s,a)Q(s,a) using temporal difference learning.

  • The actor uses the critic's QQQ estimate to compute the gradient and update its policy.

  • This mixes value-based information (from the critic) with policy optimization (from the actor).

Advantage Actor-Critic (A2C)

Using the dueling Q network idea, the critic can provide an advantage function A(s,a)=Q(s,a)−V(s)A(s,a) = Q(s,a) - V(s)A(s,a)=Q(s,a)−V(s), which reduces variance in the policy gradient. The advantage actor-critic method uses:

  • Actor: a deep policy network πθ(a∣s)\pi_\theta(a|s)πθ​(a∣s).

  • Critic: a deep dueling Q network that outputs V(s)V(s)V(s) and A(s,a)A(s,a)A(s,a).

The policy gradient update then uses the advantage instead of the raw QQQ:

∇θJ(θ)=E[A(s,a)⋅∇θlog⁡πθ(a∣s)]\nabla_\theta J(\theta) = \mathbb{E} \left[ A(s,a) \cdot \nabla_\theta \log \pi_\theta(a|s) \right]∇θ​J(θ)=E[A(s,a)⋅∇θ​logπθ​(a∣s)]

This approach is more stable and converges faster than pure Q-learning or pure policy gradient because gradient-based updates are more efficient than model-free value iteration.

Deep Actor-Critic with DDQN Critic

A modern deep actor-critic architecture:

  • Critic: a deep dueling Q network (DDQN) that learns Q(s,a)Q(s,a)Q(s,a) using TD error.

  • Actor: a deep policy network updated with policy gradients, using the critic's QQQ as the quality estimate.

The critic is updated by minimizing the TD error (like deep Q learning), while the actor is updated using the policy gradient derived from the critic's output. This joint optimization allows the agent to learn both a value function and a policy simultaneously.


Deep Model Predictive Control (Mentioned)

A different flavor of deep RL is deep model predictive control (MPC). This approach uses classical optimal control (model predictive control) — which involves expensive online optimization with model forecasting — and then trains a neural network policy to mimic the optimal controller. The trained network can then make decisions rapidly without the computational overhead of online MPC. This area is a separate topic with ongoing research.


Summary

Approach

Core Idea

Key Algorithm

Deep Policy Network

Neural network outputs action probabilities

Policy gradient with backprop

Deep Q Learning

Neural network approximates Q(s,a)Q(s,a)Q(s,a)

Minimize TD error

Dueling DQN

Split QQQ into VVV and AAA

Improved sample efficiency

Actor-Critic

Separate policy (actor) and value (critic)

Joint update using policy gradient and TD learning

Advantage Actor-Critic

Use advantage A=Q−VA = Q - VA=Q−V for policy gradient

A2C, A3C

Deep reinforcement learning continues to evolve rapidly, with new architectures and algorithms appearing regularly. The combination of deep neural networks with reinforcement learning principles has enabled breakthroughs in game playing, robotics, and control.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent