Feature Construction and Deep Q-Networks (DQN)
Feature Construction and Deep Q-Networks (DQN)
12.1 Revision of Function Approximation and Semi-Gradient TD Methods
The agenda for this lecture covers three main topics: (1) a quick revision of function approximation methods, (2) feature construction for function approximation, and (3) the Deep Q-Network (DQN) algorithm — the first major breakthrough in deep reinforcement learning.
12.1.1 Tabular Representation vs. Parameterized Function Approximation
In the methods learned before function approximation — called tabular methods — the core idea is straightforward: we maintain a table where each row corresponds to a state (for state-value functions) or a state-action pair (for action-value functions), and the corresponding entry stores the estimated value. For instance, state has value 71, state has value 70, state has value , and so on. If we are working with state-action pairs, the table can be thought of as a matrix: rows , and so forth.
The critical property of tabular methods is that each entry can be learned independently. We can make the value of one particular state-action pair perfect while another row — one that has never been visited — remains untouched. This independence is both a strength and a limitation.
The limitation becomes apparent when the state space is large or continuous. Consider a scenario where states , , and are frequently visited, but state — which sits in their vicinity — has never been encountered. Because tabular methods require direct visits to update a value, would have no good estimate despite being surrounded by well-estimated states. This is where function approximation becomes essential: if nearby states have informative values, we should be able to estimate 's value from them.
In function approximation, we replace the table with a parameterized function. Instead of storing a value for every state or state-action pair, we learn a function (for state values) or (for action values), where is the parameter vector (the weights we tune during learning). The input is the state (or state-action pair), and the output is the estimated value. The task shifts from filling a table to learning the parameters such that the function's estimates are close to optimal for all states or state-action pairs.
12.1.2 Symbol Registry — Function Approximation
| Symbol | Meaning | LaTeX | Type |
|---|---|---|---|
| State | scalar or vector | ||
| Action | scalar | ||
| Parameter vector of the approximating function | vector in | ||
| Approximate state-value function | scalar | ||
| Approximate action-value function | scalar | ||
| or | Feature(s) representing the state | scalar or vector | |
| Learning rate (step size) | scalar, | ||
| Discount factor | scalar, | ||
| Target return (Monte Carlo or n-step) | scalar | ||
| Gradient with respect to | vector of partial derivatives |
12.1.3 Limitations of Tabular Methods and Motivation for Function Approximation
With a nonlinear function representation, finding parameters that produce optimal values for all state-action pairs is a near-impossible task. The reasons are grounded in what we know from machine learning and deep learning:
- Continuous or enormous state spaces: Not all states can be visited. The state space may be continuous (e.g., a robot's joint angles), making exhaustive enumeration impossible. Even discrete spaces like Atari game screens have possible states — visiting them all is infeasible.
- The moving-parameter problem: When we adjust the parameter vector to improve the estimate for one particular state-action pair, the same parameter governs the values of all state-action pairs. Fixing one may break others. In the professor's words: "When you actually move to fix this combination, I would actually go wrong somewhere else." This is the core tension of function approximation in RL — unlike supervised learning where each training example is independent.
- Global optimum is not the goal: With our background in machine learning, we know that global optimum is not what we are chasing. We want a useful approximation — one with which we can act effectively in the environment. A policy derived from a "good enough" value function can still be excellent.
The function can be as complex as a deep neural network (input: state representation, output: value) or as simple as a linear function . In either case, the job is to learn the parameters using gradient descent, and specifically stochastic gradient descent (SGD), where we estimate the loss for each individual example rather than summing over all examples.
12.1.4 Gradient Monte Carlo vs. Semi-Gradient TD(0) Update Rules
This algorithm evaluates a given policy using a differentiable function to approximate . A function is differentiable if it can be differentiated with respect to its parameters — this is what makes gradient-based learning possible. For a linear function , the derivatives are and .
The algorithm proceeds as follows:
- Initialize parameters .
- Repeat forever (for each episode):
- Generate a complete episode: .
- For each state in the episode:
- Compute the target (the discounted sum of all rewards from step to the end).
- Update:
The error term is : the target (sum of discounted rewards) minus the current network's prediction. The gradient tells us which direction to move to increase . Multiplying by the error and stepping in that direction reduces the prediction error. This is standard stochastic gradient descent — nothing unusual.
- If and , the error is
- Update:
- The larger the error, the larger the step. The larger the feature value, the more that weight gets adjusted.
Monte Carlo methods require waiting until the end of an episode to compute . They are not online in the way that one-step TD, two-step TD, or three-step TD are. To convert the Monte Carlo algorithm into a one-step TD method, we replace the target with the one-step TD target — the immediate reward plus the discounted estimated value of the next state:
The update rule becomes:
This is the semi-gradient TD(0) update. The term semi-gradient will be explained in Section 12.1.6.
12.1.5 Symbol Registry — Semi-Gradient TD Update
| Symbol | Meaning | LaTeX | Type |
|---|---|---|---|
| Immediate reward at time | scalar | ||
| State at time | state | ||
| Next state at time | state | ||
| Target (Monte Carlo return or n-step return) | scalar | ||
| Current estimate of state value | scalar | ||
| Estimate of next state value (bootstrap) | scalar |
12.1.6 The Semi-Gradient Nature and Moving Target Problem
When we use the one-step TD target , a subtle but important issue arises: both the target and the estimate depend on the same parameter . This is bootstrapping — we are using our current estimate to form the target.
In true gradient descent, the target should represent a fixed, correct value. Think of supervised learning: the label is fixed (a cat is always a cat). In Monte Carlo, is the sum of discounted rewards — it does not depend on . It is a reasonably good target, independent of the current parameters.
But in TD methods, the target also depends on . Every time we update , the target shifts. This is the moving target problem: "If every example updates the parameter and uses the updated parameter to make a prediction and get the differences, that's a moving target."
Because the target depends on the same parameters we are updating, we are no longer performing true gradient descent. The gradient of the target with respect to is being ignored — we only differentiate the estimate term , not the bootstrap term . We treat the bootstrap part as a fixed target, even though it is not.
In Sutton and Barto's words (Chapter 9): "Bootstrapping methods are not in fact instances of true gradient descent. They take into account the effect of changing the weight vector on the estimate, but ignore its effect on the target. They include only a part of the gradient and, accordingly, we call them semi-gradient methods."
The semi-gradient approach is not a mistake — it is a deliberate simplification. It still produces usable results, even with large networks, despite the mathematical impurity. The professor shares his own experience: "That's sort of a confusion I actually got when I learned this course earlier. I'm just keeping my target to be bootstrapping, but my gradient becomes incomplete. Then I actually went closer and read the book, and that's when I actually understood that that's how it does."
For linear function approximation, semi-gradient TD(0) is proven to converge to the TD fixed point , where the value error is bounded by times the minimum possible error (Sutton & Barto, Eq. 9.14). This bound can be large when is close to 1, but the method is still much faster than Monte Carlo in practice due to lower variance.
12.1.7 Student Questions and Answers
A: The professor clarifies that in online (one-step TD), we don't generate the whole episode first — we take a step, update parameters, take another step, update again. The bootstrap value uses the current parameters, not a pre-computed value from a completed episode. This is the key difference from Monte Carlo: TD learning happens during the episode, not after.
12.1.8 Multi-Step (n-Step) Semi-Gradient TD Methods and Tail-End Handling
The one-step TD target uses only one reward before bootstrapping. We can extend this to n-step targets, which use rewards before bootstrapping:
For a two-step target at state :
For a three-step target:
where and . The first terms are observed rewards (discounted), and the last term is the bootstrap estimate steps into the future.
This matches Sutton & Barto (Eq. 7.1 / 9.16): .
More precisely (Sutton & Barto, Chapter 7): if , then — the full return. This is because all missing rewards are zero and the terminal state value is zero.
This tail-end handling is the part of the n-step algorithm that "people would actually look at and say, hey, that's getting very difficult." But it is not fundamentally difficult — it is just bookkeeping.
The algorithm uses a variable (tau) to track which state to update: . When we reach time , we update the estimate for state . This indexing ensures that each state gets updated once its n-step target is fully available. The update rule for n-step semi-gradient TD is:
12.1.9 Symbol Registry — n-Step Semi-Gradient TD
| Symbol | Meaning | LaTeX | Type |
|---|---|---|---|
| Number of steps before bootstrapping | positive integer | ||
| n-step target starting from time | scalar | ||
| Reward at step | scalar | ||
| State steps ahead | state | ||
| Index of the state being updated () | integer | ||
| Index of the terminal state | integer |
Pitfall — Forgetting tail-end near termination: Don't try to bootstrap from beyond the terminal state. If the episode ends at , and you want a 2-step target from , you only have one reward — the target is just with no bootstrap term.
12.1.10 Worked Computation: 2-Step Semi-Gradient TD Update on a Linear Function
- Episode:
- Linear function:
- Initial parameters: ,
- State representations (feature values): , ,
- Discount factor: (the professor explicitly says "assume gamma is 1")
- Learning rate: (left as a parameter — the formula form is what matters for the exam)
- We perform a 2-step semi-gradient TD update.
Step 1 — Compute the 2-step target for :
The 2-step target uses two rewards and bootstraps from :
First, compute using the current parameters with :
Now compute the target (with ):
Step 2 — Compute the estimate for :
Step 3 — Compute the TD error:
Step 4 — Compute the gradient:
Since :
Step 5 — Update :
Step 6 — Update :
The professor's narrative: "Now you should be able to make an update, . How do I make a update? The new — look at this expression. equals old plus alpha within bracket , your two-step target."
Step 7 — Continue for :
After updating and , we use the updated parameters to compute the target and estimate for . This is the sequential nature of the update within a single episode — within an episode of 1000 steps, we would make 1000 parameter updates.
Sense-check: The target (8.1) is larger than the estimate (4.7), so the error is positive (+3.4). The update increases both and , which will increase — pushing the estimate toward the target. This is exactly what gradient descent should do.
Exam note: Be able to solve this type of problem for 2-step and 3-step TD with linear functions. The professor explicitly expects this on the exam: "If you just during the exam, if you're taking a look at this algorithm and you get lost with these indexes, I think you will not be able to make it."
Bridge: Now that we understand the gradient update machinery, the natural question is: what features should we use? The professor chose to skip classical feature construction (polynomial, Fourier, tile coding) and jump directly to the deep learning approach — where the network learns its own features. This leads us to Section 12.2 and ultimately to DQN.
12.2 Classical Feature Construction vs. Deep Learning Feature Extraction
12.2.1 Manual Feature Engineering in Classical RL
Before deep learning, the quality of function approximation in RL depended almost entirely on how well the engineer designed the feature representation. The lecture notes that these feature construction methods are "largely classical" — they were essential before neural networks became practical, but they require significant domain expertise.
The main classical methods, referenced in Sutton and Barto (Chapter 9.5), include:
- Polynomial basis features: Represent states using polynomial combinations of state dimensions. For a 2D state , a second-order polynomial basis would be . These capture interactions between dimensions but grow exponentially with state dimension — features for order and dimension .
- Fourier basis features: Represent states using cosine functions at different frequencies: , where is an integer vector. Fourier features work well for smooth functions and are easy to select by frequency, but they struggle with discontinuities (they produce "ringing" artifacts).
- Tile coding (coarse coding): The most practical classical method for continuous state spaces. The state space is covered by multiple overlapping grids (tilings), each offset slightly. A state activates one tile per tiling, producing a sparse binary feature vector. Tile coding gives controllable generalization: nearby states share tiles and thus generalize to each other. It was the go-to method for problems like Mountain Car.
- Radial basis functions (RBFs): The continuous-valued generalization of coarse coding. Each feature is a Gaussian bell centered at a prototype state: . RBFs produce smooth, differentiable approximations but are computationally expensive in high dimensions.
The professor chose to skip detailed coverage of these methods not because they are unimportant, but because the field has moved to automatic feature extraction. The key insight: instead of engineering features by hand, let a deep neural network learn them from data.
12.2.2 Transition to Automatic Feature Extraction in Deep RL
In deep RL, the neural network's hidden layers act as automatic feature extractors. A convolutional neural network (CNN) processing Atari game screens learns to detect edges, shapes, objects, and game-specific patterns — all without human engineering. The first layers detect low-level features (edges, colors), middle layers combine these into higher-level patterns (objects, spatial relationships), and the final layers produce Q-values for each action.
This is the same principle that revolutionized computer vision: rather than hand-designing image features (SIFT, HOG), deep learning lets the network discover what features matter for the task. In RL, this means the same network architecture can work across different games without game-specific feature engineering — which is exactly what the DQN papers demonstrated on seven Atari games.
12.3 Deep Q-Networks (DQN): Architecture and Challenges
Hook: Standard deep learning needs millions of labeled examples. In a game like Pong, you don't get labels — you get sparse rewards, delayed feedback, and correlated data. How do you train a neural network under these conditions? DQN was the first algorithm to solve this problem convincingly.
12.3.1 Historical Context and Breakthrough of DQN
The DQN algorithm is "one of the most popular algorithms which gave a first major breakthrough, first major arguably the first major breakthrough in the world of deep reinforcement learning." It was the first algorithm to use deep learning along with an established reinforcement learning framework and demonstrate that value functions can be learned through classic deep learning techniques.
The algorithm was demonstrated on seven Atari 2600 games using the Arcade Learning Environment (ALE) — a standard benchmark simulator created by Bellemare et al. (2013) for evaluating deep RL algorithms. The Atari 2600 console (released 1977) has a simple RAM (128 bytes) and a low-resolution screen (160×210 pixels), making it easy to emulate on modern computers while still presenting complex decision-making challenges. The most significant aspect of the DQN result: one network structure, without any changes, played all seven games. This generality was groundbreaking — the same architecture captured something fundamental about decision-making from visual input, without game-specific engineering.
The papers to study (shared by the professor in the course chat):
- DQN1 — "Playing Atari with Deep Reinforcement Learning" (NIPS 2013, Mnih et al.) — introduces experience replay as the key innovation
- DQN2 — "Human-level control through deep reinforcement learning" (Nature 2015, Mnih et al.) — adds the decoupled target network; this is the refined version
- DDQN — "Deep Reinforcement Learning with Double Q-learning" (van Hasselt et al., 2015) — addresses overestimation bias
All three papers come from DeepMind (now Google DeepMind). The Nature 2015 publication was significant because it appeared in one of the world's most prestigious scientific journals, signaling that deep RL had reached mainstream credibility.
12.3.2 The Four Key Challenges in Combining Deep Learning with Reinforcement Learning
The DQN paper identifies fundamental challenges that make applying deep learning to RL non-trivial. Each challenge has a concrete consequence for training:
Challenge 1: Sparse, noisy, and delayed rewards.
In supervised learning, every training example has a correct label. In RL, the agent receives a single scalar reward at each step — and most steps have zero reward. Consider a chess game: you might take 100 moves before getting a win/loss signal. The reward is also noisy (randomness in the environment) and delayed (the consequence of move 1 might not appear until move 50). This makes it hard for the network to learn which actions were good.
Challenge 2: Delay between actions and resulting rewards (credit assignment).
The time gap between taking an action and seeing its consequence can be enormous. In Atari Breakout, you might bounce the ball 200 times before hitting the right brick. Which of those 200 actions mattered? This is the credit assignment problem — figuring out which actions in a long sequence were responsible for the reward.
Challenge 3: Correlated successive samples.
Deep learning assumes training data is independent and identically distributed (i.i.d.) — each example is unrelated to the others. In RL, consecutive states are highly correlated: state is just one frame after . Training on correlated data leads to high-variance gradient updates and unstable learning. This is what experience replay solves.
Challenge 4: Non-stationarity.
In supervised learning, the data distribution is fixed (the dataset doesn't change). In RL, the distribution shifts as the agent's policy improves — the agent visits different states as it learns better actions. The network is trying to hit a target that keeps moving. This is what the target network addresses.
12.3.3 Input Preprocessing, Frame Stacking, and Hardware Artifact Mitigation
The DQN takes a screen image (raw pixels from the Atari game) as input. The raw Atari screen is 210×160 pixels with 3 color channels (RGB) — a total of 100,800 dimensions per frame. This is the state space the agent must learn from.
Preprocessing pipeline (from Mnih et al., Nature 2015):
- Grayscale conversion: Color carries little useful information for most Atari games. Converting to grayscale reduces the input from 3 channels to 1, cutting dimensionality by a factor of 3.
- Downsampling: The 210×160 grayscale image is downsampled to 84×84 pixels. This further reduces dimensionality while preserving the essential game information (objects, positions, movements).
- Frame stacking: A single 84×84 frame cannot capture temporal information — a ball at one position doesn't tell you its direction. The solution is to stack the most recent 4 frames into a single input tensor of shape 84×84×4. This gives the network information about velocity, direction, and recent changes.
The preprocessed representation is denoted (phi), representing the processed version of state . The professor uses rather than to emphasize that the input is a transformation of the raw state — not the state itself. When we write , the network takes the 84×84×4 frame stack as input and outputs a Q-value for action .
Pitfall — Confusing with : The raw state is the full game screen. The preprocessed state is the 84×84×4 tensor. The network always sees , never . When the algorithm says "observe state ", the next step is always "preprocess to form ".
12.3.4 Detailed Deep Convolutional Network Architecture Specifications
Why a CNN? The input is an image (84×84×4). Convolutional neural networks are designed for spatial data — they detect patterns (edges, shapes, objects) regardless of position. A fully connected network would need a weight for every pixel, resulting in millions of parameters. A CNN uses shared weights (filters) that slide across the image, dramatically reducing the parameter count while capturing spatial structure.
The DQN architecture (from Mnih et al., Nature 2015):
| Layer | Type | Details | Output Shape |
|---|---|---|---|
| Input | — | Preprocessed frame stack | 84×84×4 |
| 1 | Convolutional | 32 filters, 8×8, stride 4, ReLU activation | 20×20×32 |
| 2 | Convolutional | 64 filters, 4×4, stride 2, ReLU activation | 9×9×64 |
| 3 | Convolutional | 64 filters, 3×3, stride 1, ReLU activation | 7×7×64 |
| 4 | Fully Connected | 512 units, ReLU activation | 512 |
| Output | Linear | One Q-value per action |
The network outputs Q-values for all possible actions simultaneously in a single forward pass. For example, if the game has 4 actions (up, down, left, right), the output layer has 4 neurons, each producing one Q-value.
Professor's explanation: "For S prime, there are four outcomes, you get four different values. And what will you do in the target? You get the max of all four."
This design simplifies the computation in Q-learning. Instead of calling the network once per action (4 calls for 4 actions) and taking the max, we call the network once and take the max of the output vector. This is both computationally efficient and architecturally elegant.
Pitfall — DQN only works with discrete actions: The operation in the target requires enumerating all actions. For continuous action spaces (e.g., robot joint torques), you can't enumerate infinitely many actions. DQN is fundamentally limited to discrete, finite action spaces. This is why it works for Atari (typically 4-18 actions) but not for continuous control.
12.3.5 Symbol Registry — Deep Q-Network Architecture
| Symbol | Meaning | LaTeX | Type |
|---|---|---|---|
| Preprocessed representation of state at time (84×84×4 tensor) | tensor | ||
| Parameters of the Q-network (current, updated every step) | vector | ||
| Parameters of the target Q-network (frozen for steps) | vector | ||
| Q-network output for preprocessed state , action , parameters | scalar | ||
| Replay memory / replay buffer (stores recent transitions) | set of transitions | ||
| Capacity of replay memory (typically 100K–1M) | integer | ||
| Frequency (in steps) for updating target network (typically 1K–10K) | integer | ||
| Exploration parameter for -greedy (decayed from 1.0 to 0.1) | scalar in | ||
| Number of discrete actions | integer |
12.3.6 Student Questions and Answers
Q: How does the Q-network handle multiple actions? Do we call the network once per action?
A: No — the network is structured to output Q-values for ALL possible actions in a single forward pass. The output layer has neurons (one per action). For example, with four actions (up, down, left, right), the network outputs four numbers at once. To compute in the target, we pass the next state through the network once and take the maximum of the outputs — this simplifies the computation from network calls to just 1.
Recap: DQN is the first deep RL breakthrough. It faces four challenges (sparse rewards, credit assignment, correlated samples, non-stationarity) and addresses them through preprocessing (grayscale, downsample, 4-frame stack), a CNN architecture (outputs all Q-values in one forward pass), and two key algorithmic innovations (experience replay + target network) covered in Section 12.4. The network only works with discrete action spaces.
Bridge: We've seen the architecture — how the network processes input and produces Q-values. Now we need to understand the two algorithmic innovations that make training stable: the target network and experience replay.
12.4 Core Algorithmic Components of DQN: Experience Replay and Target Network
12.4.1 Purpose, Inputs, and Outputs of the DQN Architecture
| Innovation | Problem Addressed | Mechanism |
|---|---|---|
| Target Network () | Moving target / non-stationarity | Freeze a copy of the Q-network for steps; use it to compute stable targets |
| Experience Replay () | Correlated samples | Store transitions in a buffer; sample random mini-batches for training |
The agent-environment interaction flow:
- The agent observes the current screen (preprocessed into , an 84×84×4 tensor).
- The Q-network (parameters ) outputs Q-values for all actions given .
- An action is selected using -greedy: with probability choose random, otherwise choose .
- The action is executed in the Arcade Learning Environment (ALE).
- The environment returns a reward and the next screen.
- The transition is stored in the replay buffer .
- A mini-batch is randomly sampled from to update .
- Every steps, (copy current parameters to target network).
12.4.2 Deep-Dive 1: Decoupled Target Q-Network ()
The first innovation addresses the moving target problem discussed in Section 12.1.6. In standard Q-learning with function approximation, the target is:
But is being updated at every step. The target shifts with every update.
- Q-network (with parameters ): Updated at every step via gradient descent. Used to compute the current estimate .
- Target Q-network (with parameters ): Kept frozen for steps. Used to compute the target: .
Every steps, the parameters are copied: . Between copies, remains fixed.
The modified update rule:
Notice: the target uses (frozen), the gradient uses (current). This is the key difference from standard Q-learning.
The professor's explanation: "Think of it like this... I will always update my Q1 network and that's what my estimate always. And Q2 network, every time you actually complete 10 step, 100 step, I will copy the parameters here. So that this Q2 will stay same thing for say 10 step, 50 step, or 100 step, whatever you actually define."
- Replacement update (used in the Nature 2015 paper): every steps. Simple, but the target suddenly jumps when the copy happens.
- Polyak (soft) update: at every step. The target changes gradually. Hyperparameter controls how slowly changes (larger = slower change, e.g., ).
Neither is definitively better. The replacement update gives a stable target between copies; the Polyak update avoids sudden jumps. For the exam, the professor uses the replacement update form.
Typical values of : 1,000–10,000 for Atari games; 100–1,000 for simpler problems like CartPole.
Why this helps: By keeping the target network fixed for a period, the target does not shift with every parameter update. This transforms the problem into something closer to standard supervised regression — the network is fitting a fixed target. As the textbook notes: "Introducing a target network literally stops the target from moving." It is "technically look like 2 networks, but then you are actually learning parameter at only one place."
12.4.3 Deep-Dive 2: Experience Replay Buffer ()
Experience replay addresses the correlated data problem. The solution: store transitions in a replay buffer and sample randomly from it to form mini-batches.
- : preprocessed 84×84×4 tensor of the current state
- : action taken (discrete integer)
- : reward received (scalar, clipped to in the Nature 2015 paper)
- : preprocessed tensor of the next state
- Fixed capacity (typically 100,000 to 1,000,000 transitions)
- When full, the oldest transition is discarded (FIFO — first in, first out)
- Discarding old data is intentional: older transitions are from earlier policies and less relevant to the current policy
- Randomly sample transitions (typically ) from the buffer
- Compute the DQN loss for each transition:
- Average the losses:
- Update via gradient descent on
Why this helps: Randomly sampling from a large buffer breaks temporal correlation. A mini-batch drawn from 200,000 stored transitions is much closer to i.i.d. than 32 consecutive steps from the same episode. Additionally, each transition can be reused multiple times across different updates — improving sample efficiency compared to on-policy methods that discard data after one use.
12.4.4 Loss Formulation, Huber Error Clipping, and Optimization
- The target uses (frozen) instead of (current)
- The training examples come from the replay buffer, not online interaction
Huber loss (Smooth L1 loss): In practice, the Nature 2015 paper uses the Huber loss instead of the squared error:
where is the TD error. The Huber loss is quadratic for small errors (giving smooth gradients) and linear for large errors (preventing exploding gradients from outliers). This makes training more robust than pure MSE, especially when rewards are clipped to .
12.4.5 Theoretical Analysis of Overestimation Bias in Q-Learning
From the textbook (T2 Ch5): with actions and noisy but unbiased estimates, the expected maximum is already above the true maximum. For example, with actions where the true Q-values are all zero, — a significant positive bias.
This overestimation is problematic when combined with bootstrapping: incorrect high Q-values propagate backwards through time, compounding the error. Double DQN (van Hasselt et al., 2015) addresses this by using the training network to select the action and the target network to evaluate it — decoupling selection from evaluation. This will be covered in subsequent lectures.
12.4.6 Evolution of Deep Q-Learning: NIPS 2013 vs. Nature 2015 vs. Double DQN
The professor shows the algorithms from both DQN1 (NIPS 2013) and DQN2 (Nature 2015) side by side for comparison.
| Feature | DQN1 (NIPS 2013) | DQN2 (Nature 2015) | DDQN (2015) |
|---|---|---|---|
| Experience Replay | Yes | Yes | Yes |
| Target Network | No (single network) | Yes ( frozen for steps) | Yes |
| Target Construction | |||
| Overestimation | Severe | Reduced (but still present) | Significantly reduced |
| Exam relevance | — | This is the exam version | Covered in later lectures |
The professor emphasizes: "This algorithm is from 2015 and that's all what matters for the exam perspective."
12.4.7 Student Questions and Answers
A: The professor explains the implementation: store all transitions in a replay buffer as they occur during gameplay. When it's time to update the network, randomly sample examples (e.g., 16 or 32) from the buffer, compute the DQN loss on each, average the losses, and use that for one gradient descent step. This breaks temporal correlation — unlike sampling 10 consecutive steps from the same episode, which would still be highly correlated and would not represent a true mini-batch.
12.4.8 Symbol Registry — Core DQN Components
| Symbol | Meaning | LaTeX | Type |
|---|---|---|---|
| Current Q-network parameters (updated every step) | vector | ||
| Target Q-network parameters (frozen for steps) | vector | ||
| Replay buffer (stores recent transitions) | set of transitions | ||
| Replay buffer capacity (100K–1M) | integer | ||
| Target network update frequency (1K–10K steps) | integer | ||
| Number of episodes for training | integer | ||
| Mini-batch size (typically 32) | integer | ||
| Preprocessed state at time (84×84×4) | tensor | ||
| Action at time | scalar | ||
| Reward at time (clipped to ) | scalar | ||
| Exploration rate for -greedy (decayed 1.0 → 0.1) | scalar |
12.4.9 Complete Pseudocode Walkthrough of Nature DQN (DQN2)
Step 1 — Initialization:
- Initialize replay memory with capacity .
- Initialize the Q-network with random parameters .
- Initialize the target Q-network with parameters (both start identical).
Step 2 — Outer loop (for each episode, to ):
- Begin with the starting state.
- Preprocess: obtain the last 4 frames, downsample to 84×84, convert to grayscale, stack → form .
Step 3 — Inner loop (for each step within the episode):
- Action selection: Feed into the Q-network. The network outputs Q-values for all actions. Select action using -greedy: is typically decayed from 1.0 to 0.1 over the first 1M frames.
- Execute action: Execute in the ALE. Observe reward and next screen.
- Preprocess next state: Process the new screen → form .
- Store transition: Store in . If is full, discard the oldest transition.
- Sample mini-batch and update: Randomly sample a mini-batch of transitions
from . For each transition:
- Compute target: (if terminal, )
- Compute loss:
- Update:
- Update target network: Every steps, copy: .
The professor summarizes the three key changes from standard Q-learning:
- "Since the target is moving, I want to have a target parameter to be different. So every step I would actually refresh the target. So I am kind of decoupling this network and this network."
- "I'm actually introducing mini-batch gradient descent via sampling a mini-batch from the replay buffer."
- The state representation uses preprocessed frames rather than raw states .
12.5 Pedagogical Insights: Mathematical Abstraction and AI Learning Partners
12.5.1 Numerical Hand Calculations vs. High-Level Systems Abstraction
A student (Chiranjit/Chirag) remarks that numerical examples help them understand the theory. The professor responds with an important pedagogical point about the role of abstraction and advocates for higher-level thinking.
Numerical examples are valuable and the professor uses them "very judiciously where I actually need it." For the N-step semi-gradient TD algorithm, numerical examples are possible and instructive — the professor demonstrated a complete 2-step TD update by hand (Section 12.1.10). Working through the algebra with real numbers builds confidence that you understand the mechanics of the update rule: what the target is, how the gradient is computed, and how parameters change.
However, for DQN with a CNN, hand-computing a mini-batch gradient update on paper is not feasible or meaningful. "Even for a mini batch update, I need to actually look at assume a reasonably good network. I don't think, you know, a numerical is possible in DQN. So if you start expecting numbers everywhere you get into trouble."
- Simple linear function approximation (2-3 parameters)
- Small n-step TD problems (2-3 steps, 2-3 states)
- Verifying that you understand the form of an update rule
- Deep neural networks with thousands of parameters
- Mini-batch updates over 32 or 64 transitions
- CNN architectures with convolutional layers
The professor emphasizes that the ability to work at multiple levels of abstraction is a skill expected at this level of study: "For everything, I just want to look at the numbers and then feel convinced, I think my ability to look at things at a little higher level and be still be able to make sense out of it is something that I'm missing."
Certain things must be understood at a higher level. From that higher-level understanding, one should gain the confidence to handle lower-level details. The DQN algorithm should be understood as a coherent system — the interaction between experience replay, target network, and Q-learning — not as a sequence of matrix multiplications.
12.5.2 Student Dialogue: Using Interactive LLM Partners for Deep Technical Reading
A student shares their approach to reading research papers: they upload papers to ChatGPT, which knows their learning history, and ask it to explain the paper and suggest what textbook sections to study as prerequisites. The student finds this effective for building the prerequisite chain needed to understand advanced material.
The professor observes that two years ago, people were reluctant to admit using ChatGPT for learning, viewing it as "outsourcing." Now there is maturity to accept AI tools as learning partners. The key distinction: "Ultimately, it matters as to what you gain, how much you actually gain, how much depth you actually gain."
At work, the objective is different — getting things done quickly and correctly. As long as the tool meets the objective, it is a valuable resource. But in a learning context, the goal is depth of understanding, not just output.
The professor also notes that classroom interaction from multiple perspectives provides a different kind of learning that AI cannot fully replace: "In a class which is where there's a question from multiple different perspectives, I think the learning is actually going to be immense." A student asking "why does this work?" from one angle, and another asking from a completely different angle, creates understanding that no single AI conversation can replicate.
12.5.3 Student Questions and Answers
Exam Guidance Summary
Key Industry Applications
Atari game playing. DQN was demonstrated on seven Atari 2600 games using the Arcade Learning Environment (ALE), a standard benchmark simulator created by Bellemare et al. (2013). The same network architecture — a convolutional neural network with three convolutional layers and one fully connected layer — played all seven games without structural changes. This generality was the key result: a single learning algorithm could master diverse games from raw pixel input, suggesting the approach captured something fundamental about decision-making from visual data. The Atari benchmark remains one of the most widely used testbeds for deep RL research.
DeepMind's breakthrough. The DQN papers come from DeepMind (now part of Google DeepMind), the same research group behind AlphaGo, AlphaFold, and other landmark AI systems. Vladimir Mnih is the lead author on both the NIPS 2013 and Nature 2015 papers. The Nature 2015 paper was published in one of the most prestigious scientific journals, signaling that deep RL had reached mainstream scientific credibility. DeepMind's subsequent work built directly on DQN: Double DQN, Prioritized Experience Replay, Dueling DQN, and eventually Rainbow DQN (combining all improvements).
Game AI as a benchmark. The Arcade Learning Environment (ALE) serves as a standard benchmark for evaluating deep RL algorithms. It provides a simulator interface where agents interact with games step by step, receiving screen images as observations and discrete actions as inputs. The ALE's design — low-resolution images, discrete actions, diverse game mechanics — makes it an ideal testing ground. After Atari, the field moved to more complex benchmarks: 3D navigation (ViZDoom, DeepMind Lab), multiplayer games (StarCraft II, Dota 2), and robotics simulations.
ChatGPT as a learning partner. Students are using ChatGPT and similar LLMs as interactive learning partners for reading technical papers, understanding prerequisites, and getting personalized explanations. This represents a fundamental shift in how technical material is consumed: from passive reading to active dialogue. The professor endorses this approach when used to deepen understanding rather than shortcut it. The key differentiator is whether the tool helps you build mental models or merely produces outputs you don't understand.
DRL Lecture 12 notes · Feature Construction and Deep Q-Networks (DQN)
Sections Breakdown
Covers tabular vs parameterized methods, gradient Monte Carlo, semi-gradient TD, and n-step TD with worked examples.
Contrasts hand-crafted features with automatic neural network feature extraction.
DQN breakthrough, four key challenges, CNN architecture, input preprocessing.
Target network, experience replay, loss formulation, overestimation bias, DQN algorithm.
Abstraction levels and AI as learning partners.
Exam Revision Notes
Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.
Function Approximation and Semi-Gradient TD
Must-know: Solve 2-step and 3-step semi-gradient TD numerical problems with linear functions. Understand the universal update form. Know why it's called 'semi-gradient'.
⚠️ Top pitfall: Confusing t (current time) with τ (state being updated) in n-step methods. Forgetting tail-end handling.
Self-check: Why is TD(0) called 'semi-gradient'? What gradient is being ignored?
Connects to: Classical Feature Construction, DQN Architecture, DQN Algorithmic Components
Classical Feature Construction
Must-know: Classical methods are 'largely classical' — the professor skipped them to go directly to DQN where deep learning handles feature extraction automatically.
⚠️ Top pitfall: Confusing the professor's sequencing choice with content being unimportant.
Self-check: Why did the professor skip detailed coverage of polynomial basis, Fourier basis, and tile coding?
Connects to: Function Approximation, DQN Architecture
DQN Architecture and Challenges
Must-know: DQN from 2015 Nature paper. 4 challenges in DL+RL. CNN outputs all Q-values in one pass. Only discrete actions. Input: 84x84x4.
⚠️ Top pitfall: Confusing φ (preprocessed) with S (raw state). Forgetting DQN requires discrete actions.
Self-check: Why stack 4 frames? Why output all Q-values at once?
Connects to: Function Approximation, DQN Algorithmic Components
DQN Algorithmic Components
Must-know: Target network: θ⁻ frozen for C steps. Experience replay: store transitions, random sample mini-batches. Huber loss. Overestimation bias.
⚠️ Top pitfall: Confusing θ (updated) with θ⁻ (frozen). Sampling consecutive transitions instead of random.
Self-check: What two problems do experience replay and target network solve?
Connects to: Function Approximation, DQN Architecture
Abstraction and Learning Partners
Must-know: n-step TD numericals by hand YES. DQN CNN gradients by hand NO. Abstraction is a skill.
⚠️ Top pitfall: Expecting to verify every algorithm with numerical examples.
Self-check: Why can you do a numerical walkthrough for 2-step TD but not for DQN with CNN?
Connects to: Function Approximation, DQN Algorithmic Components
Was this lecture useful?
BitsNotes AI Assistant
Subject Notes AssistantConfigure AI Chat
Choose how to access the chatbotSigned in as
Powered by BitsNotes — 20 messages per day. No API key needed. Want unlimited access? Use "Bring Your Own Key" mode.
Sign in to use AI Chat
Get 20 free AI messages per day to ask questions about your lecture notes. Sign in with Google or GitHub — it takes 5 seconds.
Sign In to BitsNotesSwitch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.