AGAI-L04: Deep RL and Intro to Deep MARL

In short

A Q-table learns each value in isolation, so in a large state space most rows are never visited. A neural network’s shared weights generalise. DQN is Q-learning with a network, a target network (against moving targets) and a replay buffer (against correlated data). Value-based agents only express ε-greedy policies over discrete actions, so policy gradient methods learn the policy itself: REINFORCE (Monte Carlo return, high variance), A2C (critic’s advantage, lower variance, some bias), PPO (clipped updates). In MARL, training and execution can each be centralised or decentralised; IDQN’s replay buffer goes stale as the other agents change.

Feeds mock questions 13 to 21 (Deep RL, including the open question 21 on the Coin Game) and 22, 23 and 26 (stale replay in IDQN, choosing a training mode, independent REINFORCE against IDQN).

Why tables stop working

Tabular Q-learning (Lecture 3) keeps one row per state and one column per action, and moves each entry towards a target (reward plus discounted value of the best next action):

In complex environments this fails for two reasons.

  • It cannot generalise. Each value is updated in isolation, so learning about one state teaches nothing about a similar one, and the agent has to visit every state-action pair many times. As the number of states explodes, many are visited rarely or never. An unvisited row still holds its initial zeros, so the agent acts at random there.
  • It needs too much space. The table grows linearly with the number of possible inputs (state-action pairs), which grows exponentially with the number of state variables.

Stochastic rewards and discrete actions are no problem for a table.

Irrelevant lamps in the Coin Game ( Lab 2)

A state is (own cell, other agent’s cell, coin cell, whether the coin has the agent’s colour) on a 3×3 grid: rows. Add lamps that switch on and off at random and never affect the game. To a table, observations that differ in one lamp are different states, so each lamp doubles the rows: , which is for , and rows that differ only in a lamp share nothing.

The budget is fixed in decisions per agent: , about 105 decisions per row without lamps and 0.4 with 8 lamps. Most rows are never visited, and the agents play close to random.

Function approximation: learn a function instead of a table

Function approximation

Learn a parameterised function of some input , and train the parameters so that accurately approximates the optimal function . can be a value function (state in, expected return out) or a policy (state in, action or action probabilities out).

All inputs share the parameters, so an update for one input also changes the output for similar inputs: the generalisation the table lacked. What a network learns about the coin’s position applies under every lamp pattern, and it can give the lamps little weight.

  • Linear function (Linear Function Approximation): a weighted sum of state features. Simple, generalises, resists overfitting. Problem: high bias, not expressive enough.
  • Deep neural network (Neural Network Function Approximation): a universal method. Learns feature representations of states automatically, represents non-linear, complex functions, and handles high-dimensional data such as images (CNNs) and sequences of observations (RNNs, which carry a hidden state). This is deep reinforcement learning.

The price of a network: less stable training (next two sections), no general convergence guarantee (it can diverge), and more computation per decision.

Deep Q-learning: Q-learning with a network

Replace the table by a network . The standard design takes the state as input and outputs one Q-value per discrete action: one forward pass gives every action’s value, and the greedy action is the largest output. (A network that outputs a probability per action is a policy network.)

The table update becomes a regression: minimise the squared difference between target and estimate.

Deep Q-learning loss and target

  • : the target, as in Q-learning. After a terminal state no reward follows, so it is just .
  • : the network’s estimate for the action taken.

is updated by gradient descent on . The target is treated as a fixed number: no gradient flows through , only through the estimate. Actions are still chosen ε-greedily.

What breaks: moving targets and correlated data

Moving target problem

The targets depend on , so any update to changes the targets. Because a network generalises, targets move faster than in tabular methods, where one state-action value changes at a time, when visited. Learning chases a moving goal and can oscillate or diverge.

Correlation of consecutive experience

Training data are not independent and identically distributed (i.i.d.): consecutive steps look alike and cover a small region of the state space. This can make the value function overfit to recent experience and cause catastrophic forgetting of previously learned estimates.

DQN: a target network and a replay buffer

Target network, against moving targets. Keep a copy of the network, (also written ), and compute targets with it: . The copy gets no gradient steps; every so many steps it is overwritten, . In between, the targets stay fixed.

Replay buffer, against correlated data. Store every transition , and compute each loss on a minibatch sampled uniformly from the buffer. A random minibatch mixes many episodes, so its samples are much less correlated. Extra advantages: each transition is re-used for several updates, and batches give more stable gradients.

The two fixes solve different problems, so DQN needs both.

DQN

Deep Q-Networks (DQN) is a foundational deep RL algorithm based on Q-learning: Q-learning + target network + replay buffer. See Deep Q-Network (DQN).

Algorithm: DQN
Initialise Q-network θ, target network θ̄ ← θ, empty replay buffer D
For each time step t:
  Choose a_t ε-greedily from Q(s_t, · ; θ)
  Apply a_t, observe r_t and s_{t+1}, store (s_t, a_t, r_t, s_{t+1}) in D
  Sample a random minibatch of transitions (s, a, r, s') from D
  For each: y ← r if s' is terminal, else r + γ · max_a' Q(s', a'; θ̄)
  Gradient step on the mean of (y − Q(s, a; θ))²       // no gradient through y
  Every so many steps: θ̄ ← θ

DQN is off-policy (Off-Policy Learning). The buffer holds actions chosen by older ε-greedy versions of the agent, and the max in the target estimates the greedy policy’s values whatever policy chose them. That is what makes replay possible.

What a value-based agent cannot express

  • Limited policies. ε-greedy over three actions gives the greedy action and each other action : one favourite plus uniform noise. A policy like is out of reach. In games good policies are often mixed (matching pennies needs 50/50).
  • Continuous actions. DQN has one output per discrete action, and a max over a continuous action (a steering angle) is an optimisation problem at every step. It is easier to learn a policy that outputs a continuous value.

So policy gradient methods use a network to represent the policy directly.

Policy gradients: learn the policy directly

In a policy gradient method a network with parameters outputs a preference per action, and a softmax turns them into probabilities . Any distribution is reachable, and the agent explores by sampling. For continuous actions the network can output, say, the mean of a distribution.

The aim: change so that actions leading to better outcomes become more likely. Differentiating the expected return directly would need to know how changing changes which states are visited, which requires the transition model. The policy gradient theorem removes that term: the gradient is an average, over the current policy’s own experience, of . Here is the direction that makes more likely in , and , how good is, weights it. So samples can estimate the gradient without a model.

still has to be estimated: by Monte Carlo returns (REINFORCE) or by another network (actor-critic: A2C, PPO). Because the average is over the current policy’s own experience, these methods are on-policy (On-Policy Learning): data is used to update the policy that generated it, then thrown away.

REINFORCE: estimate Q with the return

REINFORCE plays a whole episode, then uses the discounted return from each step, , as its estimate of (Monte Carlo).

REINFORCE gradient estimate

is a sampled number with no gradient of its own; it scales the push towards the action taken.

Advantages: simple, no critic, and with exact Monte Carlo returns the gradient estimate is unbiased.

Problem: high variance. Different trajectories from the same state can give very different returns (random actions, random transitions, long episodes), so gradients are unstable and learning is slow. It also has to wait until the episode ends.

Fix: a baseline. Use . A state-dependent baseline leaves the expected gradient unchanged but reduces variance: if all returns from a state are around 100, the raw estimate pushes every action up; with , better-than-usual actions go up and worse ones down. A learned as baseline leads to actor-critic methods.

Actor-critic methods and A2C

Actor-critic methods learn the policy (the actor) and a bootstrapped estimate of the state value (the critic), and use the critic in place of the Monte Carlo return.

  • Benefits: single steps replace full rollouts (efficient training), and variance is lower than Monte Carlo.
  • Costs: bias from bootstrapping (the critic’s estimates may be inaccurate), an extra component to train, and performance depends on critic and rollout settings (extra hyperparameters).

A2C guides the policy gradient with the advantage:

Advantage and A2C updates

  • how much better taking is than just following the policy; estimates , is the baseline (at a terminal : )
  • actor: minimise . Positive advantage: the action did better than expected and becomes more likely. Negative: less likely.
  • critic: minimise with , a regression as in DQN

Both networks update every step. A2C is on-policy, so it uses no replay buffer.

PPO: limit how far one update moves the policy

A single policy gradient update can still shift the policy a lot, and a bad step changes the data collected next: a source of instability. Proximal policy optimisation (PPO), one of the most used policy gradient methods, limits how much the policy can change in one update.

PPO clipped loss

  • : new over old probability of the action; means no change
  • clip keeps in ( is unrelated to ε-greedy); the min takes the more pessimistic term

Once a good action’s ratio exceeds (or a bad one’s drops below ), the clipped term is a constant, so no gradient pushes it further. Inside the range the update is the ordinary advantage-weighted one.

Pros: often stable updates, and it can reuse a batch for several optimisation passes because the policy stays close to the one that collected it. Cons: more complicated than REINFORCE, still generally on-policy (cannot reuse old data indefinitely), and clipping is no strict guarantee against large or harmful changes.

Comparing the deep RL methods

DQNREINFORCEA2CPPO
LearnsQ-valuespolicypolicy + criticpolicy + critic
Dataoff-policy, replayon-policy, full episodeson-policy, single stepson-policy, few passes
Strengthre-uses datasimple, unbiasedlower variancestable updates
Weaknessdiscrete actions, ε-greedyhigh variancecritic biasmore complex

Deep MARL: who sees what, and when

Lecture 3’s setting and challenges stay (Stochastic Game; non-stationarity, equilibrium selection, credit assignment, curse of dimensionality). Deep MARL adds a choice for both training and execution:

Centralised and decentralised

Centralised: use information about the other agents (their observations, actions, policies, values, or a global state) to train an agent. Decentralised: condition only on the agent’s own individual history.

Three modes (Centralised Training with Decentralised Execution):

  • Centralised training and execution (CTCE): Lecture 3’s centralised learning, one policy over the joint action space. Challenges: needs a joint reward, does not scale with the number of agents, and agents may be distributed by design.
  • Decentralised training and execution (DTDE): Lecture 3’s independent learning; each agent has only its own model and observations. Challenges: no information about the others, non-stationarity, hard to coordinate, unstable learning.
  • Centralised training with decentralised execution (CTDE): train with shared information or a centralised critic, then each agent acts on its local observations only. The topic of Lecture 5.

Choosing a mode

Autonomous cars cannot exchange all sensor data while driving, but a simulator provides all data in training: CTDE. CTCE would need the impossible exchange on the road; DTDE would waste the simulator’s information.

Independent deep learners

Independent learning (DTDE) is commonly used and competitive, and often it is the setting we have, as when each organisation programs its own agent (Assignment 1). Each method above has an independent version (IDQN, independent REINFORCE, IA2C, IPPO) in which each agent treats the others as part of the environment (Independent Learning).

Independent DQN and its stale replay buffer

In IDQN each agent trains its own Q-network, target network and replay buffer on its own observations and rewards.

New challenge: stored experience may no longer be relevant once the other agents change their policies. The agent trains on an environment that no longer exists. Being off-policy does not help: it covers the agent’s own old actions, while the others’ behaviour is part of its environment.

Remedies:

  • A smaller replay buffer, holding only recent transitions from policies close to the others’ current ones. A larger buffer makes it worse.
  • Importance sampling weights (MARL book, Ch 9): store all agents’ action probabilities with each transition and, on replay, weight it by how likely the others are to act that way now.

The target network and the discount factor have nothing to do with the age of the data.

Independent policy gradient methods

Advantage over IDQN: they always learn from the updated policies of the other agents. Being on-policy, each update uses recent experience from the others’ current policies and then discards it, so independent REINFORCE adapts faster to other learners than IDQN.

Challenge: independent MARL exacerbates sources of learning instability, such as the variance of Monte Carlo returns, which now also vary as the others change.

  • Independent REINFORCE: simple, decentralised, no critic, local or shared team rewards. High variance, worst with long episodes and shared team rewards.
  • IA2C: each agent has an actor and its own critic; lower variance, more frequent updates. But the critic learns in a changing environment, and with a shared team reward it does not solve credit assignment.
  • IPPO: each agent clips its own update; often stable, several passes, acts on local information. But it does not guarantee that the joint policy changes safely, the others’ updates keep the environment non-stationary, and it remains generally on-policy.

What to be able to answer

  • Why tables fail, and the lamps arithmetic; what a network gains and costs.
  • DQN: input and output, terminal target, no gradient through the target, what each fix does, off-policy.
  • Why policy gradients; the REINFORCE gradient, the advantage, the A2C updates, the PPO clip; variance and baselines.
  • Which training mode fits a scenario; IDQN’s stale buffer and remedies; why independent policy gradients adapt faster.

Exam questions

Flashcards