Deep Q-learning

(Tabular) Q-Learning

Tabular means storing one Q-value for each state-action pair (s, a). Q-learning uses experience to update these entries without needing the transition probabilities.

Q-value iteration:

Qk+1(s,a)←∑s′P(s′|s,a)(R(s,a,s′)+γmaxa′Qk(s′,a′))

For a fixed (s, a), consider every possible next state s′. In each case, add the immediate reward to the discounted best next Q-value, then average using the transition probabilities. The max chooses the next action a′; the current action a is already fixed.

Rewrite as expectation:

Qk+1(s,a)←Es′∼P(s′|s,a)[R(s,a,s′)+γmaxa′Qk(s′,a′)]

This is exactly the same update. E is shorthand for the probability-weighted sum above, and s′ ∼ P(s′ | s, a) means the next state follows the environment’s transition distribution.

(Tabular) Q-Learning: replace expectation by samples

  1. For a state-action pair (s, a), receive:

    s′∼P(s′|s,a)

    Take action a in state s and observe one next state s′ and reward r. The environment produces the sample; we do not need to know the numerical probabilities in P.

  2. Consider your old estimate:

    Qk(s,a)

    This is the Q-value currently stored for the state and action just visited.

  3. Consider your new sample estimate:

    target(s′)=R(s,a,s′)↑Observed reward+γmaxa′Qk(s′,a′)↑Discounted future value

    Use the observed reward r for R(s, a, s′), then add the best next Q-value from the current table, discounted by γ. This target uses one observed outcome instead of averaging over all possible outcomes. The future value is still an estimate.

  4. Incorporate the new estimate into a running average:

    Qk+1(s,a)←(1−α)Qk(s,a)↑Keep old estimate+α[target(s′)]↑Add sample estimate

    α is the learning rate, with 0 < α ≤ 1. Keep a fraction 1 − α of the old estimate and add a fraction α of the target. A smaller α makes a smaller adjustment; α = 1 replaces the old value with the target. Only the visited (s, a) entry changes.

    For example, let the old Q-value be 4, the target be 10, and α = 0.1:

    0.9×4+0.1×10=4.6

    With a constant α, this is a weighted running average: recent samples receive more weight.

(Tabular) Q-Learning: Algorithm

Start with Q0(s,a) for all s, a.

Get initial state s.

For k = 0, 1, 2, … till convergence:

Sample action a, get next state s′ and reward r.

If s′ is terminal:

target=R(s,a,s′)

Sample a new initial state s′.

Else:

target=R(s,a,s′)+γmaxa′Qk(s′,a′)
Qk+1(s,a)←(1−α)Qk(s,a)+α[target]
s←s′

How to sample actions?

Choose random actions?

This provides exploration: try different actions and collect evidence about their returns. But choosing randomly all the time does not use what we have learned to favor good actions.

Choose action that maximizes Qk(s,a) (i.e. greedily)?

This is exploitation: use the current Q estimates to choose the action that appears best. It helps turn learned values into good decisions, but these estimates can be wrong, especially early in learning.

Pure greedy selection can get stuck. Q-learning updates only the state-action pairs it visits. If an action has a low estimate and is never tried, its estimate cannot improve, even if that action is actually better.

Why exploration matters

Consider a one-step task. A always gives reward 1, and B always gives reward 10. We have tried A, but not B:

ActionCurrent Q estimateActual reward
A11
B010

Pure greedy selection keeps choosing A because 1 > 0. B stays at 0 because it is never tried. Exploration occasionally tries B, discovers its reward, and lets us update its Q-value. We can then learn to prefer B.

ε-Greedy: choose random action with prob. ε, otherwise choose action greedily

For ε = 0.1, we use the random branch 10% of the time and the greedy branch 90% of the time. The random branch samples from all actions, so it can also pick the greedy action.

ε-greedy balances earning reward using what we currently know with gathering experience that may reveal a better action. The sampled action determines what experience we collect; the Q-learning target still uses the max over next actions.

Why is it off-policy?

Two roles for a policy

target(s′)=R(s,a,s′)↑Observed reward+γmaxa′Qk(s′,a′)↑Greedy future value

The max builds the target around the best next action, regardless of which next action the behavior policy actually chooses. This lets us collect experience with one policy while learning about another: off-policy learning.

We still update the Q-value for the action a actually taken. The max concerns the future continuation from s′; it does not change which current action produced the observed reward and next state.

Example

At s′, suppose going left has Q-value 5 and going right has Q-value 2. The behavior policy may go right to explore. The preceding Q-learning update still uses 5 as the future value, because its target selects the best next action.

If the observed reward is 1 and γ = 0.9, the target is:

target=1+0.9×5=5.5

What does “converges to optimal policy” mean?

With sufficient exploration and suitable learning rates, tabular Q-values approach the optimal Q-values. Choosing greedily from those learned values gives an optimal policy. A behavior policy that keeps exploring can still take suboptimal actions even after the values have converged.

The conditions below apply to a finite tabular MDP with bounded rewards and 0 ≤ γ < 1. Deep Q-learning keeps the off-policy target, but using a neural network does not automatically inherit this tabular convergence guarantee.

Caveats:

Technical requirements.

Example: αt(s,a)=1t+1

The learning rates are 1, 1/2, 1/3, … . They become smaller without shrinking too quickly:

1+12+13+⋯=∞1+14+19+⋯<∞

A constant α = 0.1 fails the second condition: its squares keep adding 0.01 forever. A faster decrease, αₜ = 1 / (t + 1)², fails the first condition: the total learning is finite. The schedule 1 / (t + 1) satisfies both.

Can Tabular Methods Scale?

Discrete environments

Discrete means states can be counted; it does not mean there are few of them. Gridworld has only a small set of positions, while a Tetris board or an Atari screen can have an enormous number of configurations.

These are illustrative sizes from the slides. For example, a 10 × 20 board with each cell empty or occupied has 2200 ≈ 1060 patterns. For Atari, 128 bytes have 256128 ≈ 10308 combinations; an 84 × 84 image with 256 grayscale values per pixel has about 1016992 possible images. Not every possible pattern is a reachable game situation.

Continuous environments (by crude discretization)

Angles, velocities, and joint positions take continuous values. Crude discretization replaces each variable with a small number of bins, allowing us to use a table, but the number of combinations grows exponentially with the number of variables.

Bd↑B bins for each of d variables

With 10 bins per variable, 2 variables give 100 combinations, 10 give 1010, and 100 give 10100. The slides’ continuous-environment counts depend on how the states are discretized. Finer bins grow the table further, while coarse bins lose detail.

A Q-table needs a value for every state-action pair. The obstacle is both memory and experience: too many entries to store, and too many to visit often enough. We need to share what we learn across similar states.

Approximate Q-Learning

Instead of a table, we have a parametrized Q function: Qθ(s, a). The function predicts a Q-value from the state and action; θ is a shared set of learned parameters.

Can be a linear function in features:

Qθ(s,a)=θ0f0(s,a)+θ1↑Learned weightf1(s,a)↑Feature+⋯+θnfn(s,a)

Each fᵢ(s, a) describes some aspect of the state and action, and θᵢ controls its contribution. For example, navigation features could describe distance to the goal and nearby obstacles. A constant feature f₀ = 1 supplies a bias term. Shared weights let experience in one situation affect predictions in other, similar situations.

Or a neural net, decision tree, etc.

With a deep neural network, θ contains its weights and biases: this gives deep Q-learning. The gradient rule below applies to differentiable models, such as linear functions and neural networks.

Learning rule:

Recall Approximate Q-Learning

Instead of a table, we have a parametrized Q function. For example, a neural net Qθ(s, a).

Learning rule:

First predict the future return and construct a target; then train the network’s current prediction toward that target. θₖ labels the parameters before this update, and θₖ₊₁ labels them afterward. For example, if Q predicts 4 and the fixed target is 7, the update tries to raise that prediction.

DQN Training Algorithm

Algorithm 1: deep Q-learning with experience replay.

Initialize replay memory D to capacity N.

Initialize action-value function Q with random weights θ.

Initialize target action-value function Q̂ with weights θ⁻ = θ.

For episode = 1, …, M do

Initialize sequence and preprocessed sequence:

s1={x1},φ1=φ(s1)

For t = 1, …, T do

With probability ε select a random action aₜ; otherwise select:

at=arg maxaQ(φ(st),a;θ)

Execute action aₜ in the emulator and observe reward rₜ and image xₜ₊₁.

Set sₜ₊₁ = (sₜ, aₜ, xₜ₊₁) and preprocess φₜ₊₁ = φ(sₜ₊₁).

Store transition (φₜ, aₜ, rₜ, φₜ₊₁) in D.

Sample a random minibatch of transitions (φⱼ, aⱼ, rⱼ, φⱼ₊₁) from D.

Set:

yj={rjif episode terminates at step j + 1rj+γmaxa′Q^(φj+1,a′;θ−)otherwise

Perform a gradient descent step on:

(yj−Q(φj,aj;θ))2

with respect to the network parameters θ, averaged over the minibatch.

Every C steps reset:

Q^=Q

End For

End For

The agent acts in the environment and stores transitions in replay memory. A learner samples minibatches, updates the online Q-network, and periodically copies it to the target network.

DQN Details

DQN on ATARI

The input is screen pixels; the outputs are Q-values for the available actions. Game-score changes provide reward, clipped to −1, 0, or +1 during training. The same architecture and training recipe were used across games, with a separate set of network weights trained for each game.

Double DQN

There is an upward bias in the maximum of estimated Q-values: when estimates contain error, the max tends to pick an action whose value has been overestimated.

maxaQ(s,a;θ)

For example, suppose two actions both have true value 5, and each estimate independently takes value 4 or 6 with equal probability. The four equally likely pairs have maxima 4, 6, 6, and 6. Their average is 5.5, even though each individual estimate averages 5. Selecting the largest estimate creates overestimation.

DQN already maintains two sets of weights, θ and θ⁻. Double DQN uses them for different parts of the next-state target:

a*=arg maxa′Q(s′,a′;θ)↑Select with online network
y=r+γQ(s′,a*;θ−)↑Evaluate with target network

The online network supplies the action index a*. The target network then supplies the value of that action. This reduces the coupling between choosing an action for its high estimate and evaluating it with the same estimate.

Double DQN loss:

Li(θi)=𝔼(s,a,s′,r)∼D[(r+γQ(s′,arg maxa′Q(s′,a′;θi);θi−)−Q(s,a;θi))2]

The inner arg max uses θᵢ to choose an action at s′. The outer Q uses θᵢ⁻ to evaluate it. Discount that future value by γ and add the observed reward r to form the target; compare that target with Q(s, a; θᵢ), square the difference, and average over samples from replay memory D. Hold the target fixed when updating θᵢ. For terminal transitions, the target is just r.

For example, at s′ the online network estimates A = 8 and B = 7, while the target network estimates A = 5 and B = 6. Double DQN selects A with the online network and uses the target network’s value 5. With r = 1 and γ = 0.9, the target is 5.5. Standard DQN takes the target network’s maximum 6, giving a target of 6.4.

Atari results

StatisticNo opsHuman starts
DQNDDQNDQNDDQNDDQN (tuned)
Median93%115%47%88%117%
Mean241%330%122%273%475%

These are human-normalized game scores: 100% corresponds to the human reference and 0% to the random-agent reference. “No ops” randomizes the initial state by waiting before play. “Human starts” begins from states sampled from human play, testing performance across a wider range of starting situations. Median summarizes the middle game; mean is more sensitive to very large scores on a few games.

Original Double DQN plots for Wizard of Wor and Asterix: orange DQN value estimates become large and unstable, while blue Double DQN estimates are steadier. The score plots below show stronger Double DQN performance.
Original paper, Figure 3: value estimates above and game scores below, for Wizard of Wor and Asterix. Orange: DQN; blue: Double DQN. In these examples, reducing overestimation also improves learning stability.

Prioritized Experience Replay

StatisticDQNDouble DQN (tuned)
BaselineRank-basedBaselineRank-basedProportional
Median48%106%111%113%128%
Mean122%355%418%454%551%
> baseline—41—3842
> human1525303333
# games4949575757

Baseline uses uniform replay. Rank-based sampling prioritizes a transition according to its error’s position in the sorted list; proportional sampling uses the error magnitude. “> baseline” counts games that improve over the corresponding baseline, and “> human” counts games that exceed the human reference. The DQN results cover 49 games; the Double DQN results cover 57.

Original prioritized replay learning curves. Red rank-based and blue proportional replay reach the reference score sooner than black uniform Double DQN. Gray uniform DQN is lower.
Original paper, Figure 4: learning speed across 57 Atari games. Left: median of the best score achieved so far; right: median of the mean score achieved so far. Scores are normalized to the uniform Double DQN reference, so 100% marks that reference level. Red: rank-based; blue: proportional; black: uniform Double DQN; gray: uniform DQN.

Further DQN improvements

“Rainbow: Combining Improvements in Deep Reinforcement Learning,” Matteo Hessel et al., 2017

Rainbow combines six improvements: Double Q-learning, prioritized replay, dueling networks, multi-step returns, distributional learning, and noisy networks.