AGAI-Lab02: Learning Agents

In short

Agents now learn from their own rewards by trial and error, each independently, and the lab asks whether such learners reach a good equilibrium and whether a more powerful learner helps. In the Stag Hunt, two independent Q-learners mostly lock into the safe (D,D): initial values decide the equilibrium, and since one agent’s exploration is noise in the other’s rewards, exploration knocks them out of (C,C) but almost never out of (D,D). In the Coin Game, a grid-world social dilemma, tabular Q-learners learn to collect coins but never to leave the other’s alone, so their total reward stays near that of random agents. Irrelevant inputs blow up the Q-table and ruin learning; a neural-network learner (PPO) shrugs them off but still defects. Function approximation fixes generalisation, and the conflict of incentives remains.

The lab is ungraded practice that the lecturer calls the best preparation for the midterm. The notebook ships without outputs, so simulation numbers come from my own re-implementation of its models with the lab’s parameters (own random numbers, own PPO code); they show the expected behaviour but can differ in detail from a classroom run. Analytic results are exact.

Concepts tested: Q-Learning, Independent Learning, Epsilon-Greedy Policy, Exploration vs Exploitation, Stag Hunt, Prisoner’s Dilemma, Nash Equilibrium, Social Dilemma, Tabular RL, Function Approximation, PPO, Actor-Critic, REINFORCE


Part I: independent Q-learning in the Stag Hunt

The model

The game is Lab 1’s Stag Hunt with (both hunt stag), (I hunt stag alone), (I hunt hare while the other hunts stag) and (both hunt hare). C is stag, D is hare. It has two pure Nash equilibria, (C,C) and (D,D), and Lab 1’s threshold belief is

stag is the best response only if the partner hunts stag with probability above 2/3. Two Lab 1 benchmarks come back: rational agents with uniformly random beliefs reached (C,C) in 11% of encounters, and under replicator dynamics a population went to all-stag only from starting shares above 2/3, so from one third of the starting states.

The learners. The stage game repeats unchanged and nothing is remembered, so there is a single state. Each agent keeps two numbers, and , its estimates of what each action earns, and uses stateless Q-learning:

where:

  • is the action agent just played, and only its value is updated
  • is the payoff it just received
  • is the learning rate, the fraction of the prediction error that is corrected (0.1 throughout)

Regular Q-Learning learns per state and adds a look-ahead term to the target, , which credits an action for the state it leads to ( is the Discount Factor). With one state, is the same number whichever action was played, so it shifts both targets equally and never changes which action looks better. Dropping it (equivalently ) leaves the rule above.

Actions are [[Epsilon-Greedy Policy|-greedy]]: with probability a uniformly random action, otherwise the action with the larger -value, ties broken at random. So an agent whose greedy action is C plays D with probability .

Each agent learns from its own action and reward only and treats the partner as part of the environment: Independent Learning (Lecture 3, AGAI-L03 - Intro to Multi-Agent Reinforcement Learning). Because the partner is learning too, the payoff of each action keeps changing: a moving target.

What is measured. Each experiment runs 500 independent pairs for 3000 rounds. The outcome of a run is its greedy joint action, what the two would play now without exploration: (C,C), (D,D) or miscoordinated. An agent counts as a stag hunter only if strictly, so a tie counts as hare.

Q1: predictions before the runs

Statement

(a) Two independent Q-learners play the Stag Hunt () 3000 times in a row. They start knowing nothing (all value estimates equal to 0), and choose a random action (explore) 10% of the time. The experiment is repeated 500 times. In what fraction of the runs do you expect them to end at (C,C)? Choose one: less than 10%, 10-40%, 40-70%, more than 70%.

(b) Now suppose both agents start at (C,C): they already hunt stag and believe that this pays off. Will they keep hunting stag if they explore 10% of the time? And if they explore 50% of the time?

(a) Agents that know nothing start by playing at random, which is like holding the belief . Against a coin-flipping partner D earns more than C (2.5 against 2, Q2(b)), and the replicator benchmark puts in the basin of all-hare. So (C,C) should be rare: less than 10%. My runs give 5% to 10% across seeds (mean 6.6% over ten).

(b) A rational agent would stay: against a partner who explores 10% of the time, C earns 3.8 and D 2.95 (Q4). The learners mostly do not: at about 80% of runs leave (C,C) within 3000 rounds, at almost all within a few dozen rounds.

Q2: the baseline run

Statement

Both agents start with , , , in the Stag Hunt and, as a sanity check, in the Prisoner’s Dilemma ().

(a) In what fraction of the runs did the learners end at each outcome? Compare with Lab 1, where rational agents with uniform beliefs reached (C,C) in 11% of the encounters and the replicator dynamics reached all-C from 1/3 of the initial states. Did learning help coordination?

(b) Early in learning, which action earns more for the row agent, and why? Hint: what does the partner do in the first rounds, and what do C and D earn against such a partner? Explain why the learners lock into (D,D) so quickly.

(c) In the Prisoner’s Dilemma the learners always end at (D,D). Is this a coordination failure in the same sense as in the Stag Hunt? Use the notion of a dominant action and/or Nash equilibrium to answer.

Share of runs per greedy outcome after a given round (one run of 500 pairs; miscoordination is at most 1% in the Stag Hunt and 7% in the Prisoner’s Dilemma):

round110050010003000
SH (C,C)0.280.290.290.240.10
SH (D,D)0.720.710.710.760.90
PD (D,D)0.720.781.001.001.00

(a) At round 3000 the Stag Hunt learners end at (C,C) in 5% to 10% of runs (across seeds) and at (D,D) in the rest; the Prisoner’s Dilemma learners end at (D,D) in every run. Learning did not help: the learners do worse than Lab 1’s rational agents (11%) and far worse than the replicator dynamics (one third). In round 1 about 28% of runs settle at (C,C) and the rest at (D,D); after that exploration slowly knocks (C,C) runs over to (D,D) (Q4), and none come back.

(b) In the first rounds all -values are 0, so both agents break ties at random: the partner is a coin flip. Against it

D earns more on average, and, more important for a learner, never less than 2, while C earns 0 half the time. Round 1 in detail:

  • Both played C: both earned 4, , so both now prefer C. Probability 1/4.
  • Both played D: both earned 2, , so both prefer D.
  • One of each: the D player earned 3 and prefers D. The C player earned 0, so it is still tied; as soon as its tie-break picks D it earns 2 and prefers D.

So a run reaches (C,C) essentially only if both play C in round 1, probability 1/4 (28% in my run; a few mixed runs also meet at C in round 2 when the D player explores). Lock-in is quick because of a feedback loop: once my partner plays D, C pays me 0, so I never see evidence that C could pay 4, and my D in turn makes C pay 0 for my partner. can only rise when both play C in the same round, which during exploration happens in of rounds.

(c) No. In the Prisoner’s Dilemma D is dominant ( and ), so (D,D) is the unique Nash equilibrium. There was no other equilibrium to coordinate on: the learners found the only one, and their values reflect it (final average ). The bad outcome is a Social Dilemma, an incentive problem: (C,C) Pareto dominates (D,D), yet each agent does better by defecting whatever the other does. In the Stag Hunt (C,C) is itself an equilibrium, which the learners could have reached and mostly missed: that is a coordination failure.

Q3: initial values as beliefs

Statement

An agent that believes its partner hunts stag with probability starts with and . Three pairs of beliefs are compared: both optimistic (0.8, 0.8), both pessimistic (0.4, 0.4), and an optimist meeting a sceptic (0.9, 0.5), with .

(a) Which pairs of initial beliefs lead to (C,C)? Compare with the threshold of Lab 1.

(b) An optimist (belief 0.9) meets a sceptic (belief 0.5). Which equilibrium do they reach? Who adapts to whom, and how many rounds does it take? Use the update rule: what happens to the optimist’s in the first rounds?

(c) How would these results change if you increase , and why? Test it with .

belief starts with
0.93.62.9+0.7C
0.83.22.8+0.4C
0.52.02.5−0.5D
0.41.62.4−0.8D

(a) Both optimistic ends at (C,C) in 100% of runs, both pessimistic at (D,D) in 100%, and the optimist with the sceptic at (D,D) in 99% to 99.8%. The link to is exact:

So an agent’s first greedy action is Lab 1’s best response to its belief. When both start on the same side, play confirms the beliefs (two stag hunters earn 4, two hare hunters earn 2 and barely try C), so with little exploration equilibrium selection moves into the initialisation.

(b) They reach (D,D): the optimist adapts to the sceptic, and the sceptic never moves. With exploration switched off the update rule gives this trace. C earns the optimist 0 against the sceptic’s D, so each C play multiplies its by .

roundoptimistits , scepticits ,
1C, earns 03.24, 2.90D, earns 32.00, 2.55
2C2.916, 2.90D2.00, 2.595
3C2.624, 2.90D2.00, 2.636
4D, earns 22.624, 2.81D, earns 22.00, 2.572
7D2.624, 2.590D2.00, 2.417
8C again2.362, 2.590D2.00, 2.475

The optimist hunts stag for three rounds and switches in round 4: , while is still above. The switch is not yet final. At (D,D) its falls towards while its is stale (not updated while it plays D) and still above 2, so it relapses to C in rounds 8, 14 and 25, each time earning 0 and losing another 10%. After the sixth stag hunt , below anything can reach, and from round 26 the pair stays at (D,D).

The sceptic never plays C, so its is never updated, and its D earns 3 or 2, which keeps between 2 and 3 and so above . At exploration is too rare to show it that stag pays 4 before the optimist gives up. The agent whose current action is punished does the adapting.

(c) With , the two optimists end at (C,C) in only 18% to 22% of runs (against 100%), while the other two pairs stay at (D,D) in at least 99%. More exploration does not rescue the pairs at (D,D) and destroys most of the optimists’ (C,C): the partner’s exploratory D gives a stag hunter 0, which hits hard, while a hare hunter loses little when the partner explores (Q4).

Q4: exploration as noise in the other’s rewards

Statement

Both agents start at (C,C) with the values of belief , , and . The exploration rate is or .

(a) Both agents start at (C,C), which is a Nash equilibrium. For which settings does (C,C) survive 3000 rounds? Against a partner that explores 10% of the time, C is still the best response (expected payoff 3.8, against 2.95 for D): why do the learners nevertheless leave (C,C)? Hint: what does actually estimate when ?

(b) Why is the opposite escape, from (D,D) to (C,C), much less likely?

Expected payoffs against an exploring partner at (C,C), and my runs (first exit: median round over runs that left):

C paysD pays(C,C) at 3000first exit
0.013.982.995100%almost none leave
0.053.902.97581% to 84%round 1300
0.13.802.9517% to 20%round 480
0.53.002.750.2% to 0.4%round 12

(a) (C,C) survives at , mostly survives at 0.05, is mostly lost at 0.1 and entirely at 0.5, although C stays the best response in every row.

Unrolling the update shows what is:

where is the payoff of the -th most recent C play: an exponentially weighted average of the recent payoffs of C. The weights halve about every 6.6 plays, so remembers roughly the last payoffs. With a constant learning rate it estimates “what C paid lately”, a noisy quantity, and never settles on the expected value 3.8.

At the partner plays D in 5% of rounds, and each such round pays me 0 and cuts my by 10%. From 3.8, three zeros give , below . Three zeros within a short stretch are enough, and over 3000 rounds, with each agent exposed to the other’s exploration, such a streak is likely. For a payoff with variance the weighted average has standard deviation ; with that is 0.20 around 3.80 (my runs: mean 3.80, standard deviation 0.20, minimum about 2.0).

Once one agent’s dips below its , it plays D, and the partner earns 0 every round and follows within about three rounds. Both may retry stag a few times while their stale is above 2, as the optimist did in Q3(b), and some pairs re-coordinate, but each failed retry costs another 10% until (D,D) holds. At C leads by only 0.25 and a single zero () is enough, so (C,C) falls within a dozen rounds.

So the learners leave a Nash equilibrium because one agent’s exploration is noise in the other’s rewards, and a constant learning rate makes each agent react to that noise as if the partner had changed.

(b) At (D,D) with , C pays on average and D pays . For C to become greedy, must climb from about 0.2 to above 2:

  • is updated only when I explore C (5% of rounds), and pays 4 only if the partner explores C in the same round (probability 0.05). The other 95% of my C plays pay 0 and pull it back down.
  • Each success moves only 10% of the way to 4: , about seven successes with no failure in between.
  • Even then both must switch together: one that switches alone earns 0 against a hare hunter and switches back.

Starting at (D,D) (both pessimistic) with , my runs saw one transition to (C,C) in 500 runs of 3000 rounds, and it fell back. Structurally these are the Stag Hunt’s basins: leaving (C,C) needs the partner to look like a defector more than of the time, leaving (D,D) needs it to look like a cooperator more than of the time. In Lab 1’s terms (D,D) is risk-dominant (), and noisy learners drift to it and stay.

Common pitfalls in Part I

  • “C is the best response, so learners stay at (C,C).” A constant-rate learner tracks recent payoffs and reads a streak of exploratory defections as a change in the partner.
  • “More exploration helps coordination.” In the Stag Hunt it destroys (C,C) and leaves (D,D) intact.
  • Calling the Prisoner’s Dilemma result a coordination failure. It has one equilibrium, and the learners found it.

Part II: the Coin Game with tabular Q-learning

The model

The Coin Game (Lerer and Peysakhovich, 2017) turns the repeated Prisoner’s Dilemma into a grid world. Two agents, red and blue, move on a grid that always holds exactly one coin, red or blue.

  • The grid is a torus (walking off one edge enters the opposite one), so every cell is at most two moves away.
  • Actions: up, down, left, right. Both agents move at the same time and may share a cell.
  • An agent picks up the coin by moving onto its cell; both can take the same coin in the same step. A new coin of random colour then appears on a random cell not occupied by an agent.
  • An episode lasts 16 steps; then agents and coin are placed at random again.
  • Each agent observes four one-hot grids (36 numbers): its own position, the other’s position, the coin if it has its own colour, the coin if it has the other’s colour.

A pickup pays the picker +1 whatever the coin’s colour, and taking the other player’s coin costs that player 2:

pickuppickercoin’s ownertotal
own coin+1(the picker)+1
other’s coin+1−2−1

Going for your own coins and leaving the other’s alone is the cooperative pattern; taking every reachable coin is defection. Both are patterns of movement the agents must discover from positions.

Three measures, averaged over the games of an update: individual performance (coin pickups per episode, both agents together, any colour; random agents get about 3.7), restraint (the share of pickups of the picker’s own colour: 0.5 for colour-blind agents, 1 for full restraint) and welfare (total reward per episode, red plus blue). From the table,

so welfare needs both skill and restraint, and colour-blind experts score about 0.

The learners. Each agent runs regular Q-Learning with a table (Tabular RL):

where is the state read from the observation (own cell, other’s cell, coin cell, whether the coin is mine: rows), one of the four moves and the next state, with , , and all values starting at 0. The term now matters: it credits a move for bringing the agent closer to a coin. Each agent treats the other as part of the environment. Training runs 32 games in parallel; one update is one 16-step episode in each, so 512 decisions per agent.

The lab’s text speaks of 300 updates, but the training function’s default, which its cells run, is 1000. I report values at update 300 and at the end of the 1000-update run.

Q5: predictions before the runs

Statement

(a) Two independent Q-learners are trained with their own rewards. After training, what share of each agent’s pickups do you expect to be coins of its own colour?

(b) How large will the total reward per episode (red + blue) be, compared with two agents that move at random?

(a) About half. Nothing in an agent’s own reward pays for restraint (Q6(b)), so a self-interested learner takes whichever coin it can reach, and colours are random.

(b) About the same as random agents, close to 0. The learners will pick up many more coins, but colour-blind pickups add nothing to the total on average (welfare formula). Both predictions hold (Q6).

Q6: what the Q-learners learn

Statement

(a) Describe the three panels (individual performance, restraint, welfare). How did their individual performance evolve? Did they show restraint? Compare their total reward with that of random agents.

(b) Use the payoffs to explain why an agent that maximises its own reward picks up every coin it can reach, whatever its colour. What is the expected total reward per pickup when both agents do this?

(c) Why can independent Q-learning, by itself, not find the outcome in which both agents only pick up their own coins? Relate your answer to the Prisoner’s Dilemma and to the phrase “treats the other agent as part of the environment”.

pickupsown sharewelfare
random agents3.6 to 3.80.49 to 0.52−0.1 to +0.1
update 10012.10.60+2.4
update 30014.00.57+2.0
update 100016.90.52+0.6

(Per episode, averaged over 20 updates of one run; two more seeds give 16.8 to 17.3 pickups, share 0.52 and welfare +0.7 at update 1000.)

(a) Individual performance rises steadily from the random level to about 17 coins per episode for the pair after 1000 updates (4.6 times random), and is still creeping up. Restraint stays near 0.5: a small bump to about 0.6 around updates 100 to 200 fades back to 0.52. Welfare follows the formula, , so the total ends barely above random agents’ (about 0) with more than four times the pickups. The agents got good at the individual task and no better at the social one.

The early bump is not cooperation. A likely reason, read off the payoffs: taking a coin rather than letting the other take it is worth to me for my own coin and for the other’s. So a selfish learner races harder for its own coins, and once both reach every coin fast, that preference matters less.

(b) Compare taking a coin with leaving it, from my own reward only. Taking it pays +1 now, whatever its colour. Leaving the other’s coin pays me 0, and if the other then takes it I still get 0. The −2 my taking causes lands in the other’s reward, which never enters my -values. So in every state taking is at least as good for me as leaving: it plays the role of D in the Prisoner’s Dilemma, a dominant action. When both agents do it, half the pickups are own coins (+1 in total) and half the other’s ():

(A simultaneous pickup of one coin also totals 0: over two pickups.)

(c) Two reasons work together. First, each Q-learner maximises its own return, and for that return restraint is costly: it gives up +1 now and protects only the other’s reward. It could pay only if it changed what the other does later (reciprocity, as Tit-for-Tat in Lab 1). Second, independent Q-learning treats the other agent as part of the environment: the other’s behaviour is just part of the transitions and rewards, and the state holds positions and the coin, with no record of whether the other has been restrained. So neither agent can reward restraint or punish a defector; in Lab 1’s terms both are memory-0 with respect to the partner, and against any fixed behaviour of the other, taking every coin is the best response. The result is mutual defection, as with the Part I learners in the Prisoner’s Dilemma. Restraint would need rewards that include the other’s welfare, memory of the other’s behaviour, or learners that account for how the other learns.

Q7: irrelevant lamps (prediction)

Statement

Each agent’s observation gets lamps: signals switched on or off at random at every step, with no effect on the game. For a table, two observations differing in one lamp are different states: rows. Before running: how do you expect the individual performance of the Q-learners (coin pickups per episode) to change with 4 and with 8 lamps? Would the lamps bother a human player?

The best policy ignores the lamps, but a table cannot know that: it learns each lamp pattern separately. With a fixed amount of experience, 4 lamps should slow learning noticeably and 8 lamps (256 copies of every state) should leave the agents close to random. A human would not be bothered: after a few steps they would see that the lamps change whatever anyone does and ignore them, because people generalise across situations that differ only in irrelevant details.

Q8: why the table breaks

Statement

Tabular Q-learners are trained with 0, 4 and 8 lamps and the same training budget. After training, the code reports the fraction of states visited during training and the share of decisions, in new games, taken in never-visited states (where all values are 0, so the agent acts at random).

(a) How does the individual performance change with the number of lamps? Quote the numbers.

(b) State space. How many rows does the Q-table have with lamps? Compute for .

(c) Training budget. The budget is counted in decisions per agent (environment steps): . Compute for the runs above (read the three numbers from the code). How many decisions per state does it give on average, , for ?

(d) Expected number of visited states. Assume each of the decisions lands in a state drawn uniformly at random from the states, independently.

  1. Show that the probability that a given state is never visited is , and hence that the expected number of visited states is .
  2. Compute it for and compare the fraction visited with the printed fraction. Your prediction should be too high. Not all position states can occur: where can the coin not be when an agent makes a decision? Count the states that can occur and redo the computation with them.
  3. Under the same assumption, what share of the test decisions should fall in never-visited states? Compare with the printed share.

(e) Use (c) and (d) to explain the result of (a).

(f) The best policy is the same with and without lamps. Why can a table not discover this? What would a learner need in order to be unaffected by the lamps?

(a) Pickups per episode (random agents: about 3.7):

lampsupdate 300update 1000
014.016.9
49.912.8
84.76.6

(Three seeds agree within about 1.5 pickups at update 300 and 0.5 at update 1000.) Four lamps cost about a quarter of the performance; eight leave the agents barely above random after 300 updates and far below the lamp-free learners after 1000. With lamps, restraint stays between 0.47 and 0.56; the 4-lamp learners end with share 0.56 and welfare about +1.5, which matches the early phase in which the lamp-free learners also had a share above 0.5 (Q6(a)): they are slower along the same path.

(b) : 1,458 rows for , 23,328 for , 373,248 for .

(c) From the code: 1000 updates, 32 games, 16 steps, so

and for , for and for . (With the 300 updates the text mentions, and , and .)

(d) 1. One decision misses a given state with probability , so independent decisions all miss it with probability , using for large . Each state is visited with probability , and by linearity of expectation (summing over the states) the expected number of visited states is .

(d) 2. With all states the predicted visited fractions are , and . My runs print 0.790, 0.790 and 0.648, lower in every case.

When an agent decides, the coin is never on an agent’s cell: an agent standing on it would have picked it up, and new coins go on free cells. If the agents are on different cells ( ordered pairs) the coin has 7 possible cells; if they share one (9 cases) it has 8:

and : 1,152, 18,432 and 294,912, so only of the rows can ever be visited. Then , and ; the expected visited share of reachable states is 1, 1 and , and of all rows , and . Printed: 0.790, 0.790, 0.648. The corrected model fits almost exactly (my runs visited every reachable state for 0 and 4 lamps, and 82.0% for 8).

(d) 3. A test decision lands in a uniform reachable state, never visited with probability : , , and for 8 lamps. Printed: 0.000, 0.000 and 0.174. (With the 300-update budget the 8-lamp prediction would be .)

(e) The budget is fixed while the table grows by , so experience per row shrinks by the same factor. With 0 lamps each reachable state gets about 444 decisions, enough to learn its values. With 4 lamps every state is visited, but only about 28 times across four actions, and each update corrects 10% of the error while bootstrapping from under-trained next-state values, so values are only partly learned. With 8 lamps the average state is seen 1.7 times: 17% of test decisions land in a row never seen (random action), and most of the rest in rows seen once or twice, with values near 0. That is close to random play, hence 6.6 pickups.

(f) A table has one independent row per observation: nothing learned in one row is used in any other, so it cannot notice that 256 rows differing only in the lamps call for the same action. It must learn the same policy 256 times over, from 1/256 of the data each time. To be unaffected, a learner needs generalisation across states: a representation that shares parameters between similar observations and can learn to give the lamps no weight, such as Function Approximation with a neural network (Neural Network Function Approximation) or with features that leave the lamps out.


Part III: deep RL with PPO

The model

Deep reinforcement learning replaces the table with a neural network that takes the observation (36 numbers plus lamps) as input; all states share the weights, so learning in one state carries over to similar ones. The lab uses PPO (proximal policy optimisation), a policy gradient method: it learns the policy itself and changes its parameters to make actions with higher long-term reward more likely.

Actor and critic. PPO is an Actor-Critic method with two separate networks, each with two hidden layers of 64 tanh units:

  • the actor outputs one preference per action; a softmax turns them into probabilities (Softmax Policy) and the agent samples its action;
  • the critic outputs one number, an estimate of the return from state .

Advantage. The actor makes action more likely in proportion to its advantage, how much better it did than the critic expected:

This is the one-step estimate. The code mixes horizons with Generalized Advantage Estimation: weight gives the one-step estimate, the whole rest of the episode (Monte Carlo); here . The critic is trained towards the target .

Clipped actor loss. Each batch, collected by the behaviour policy (the policy before the update), is used for several gradient steps. The importance sampling weight measures how far the policy has moved since, and the loss clips it:

Beyond the clipped term stops rewarding further change, so each update stays in a trust region around .

Full update. Each minibatch minimises the actor loss, minus times the policy’s Entropy (entropy regularisation), plus times the critic loss . Adam with learning rate 0.003 runs 4 epochs of 4 minibatches over each batch of 512 decisions (16 gradient steps), with advantages normalised to mean 0 and standard deviation 1 within the batch and the gradient norm clipped at 0.5. Then the batch is thrown away (PPO is on-policy). Without a critic the advantage becomes the Monte Carlo return (the discounted sum of rewards from to the end of the episode), which is REINFORCE.

In the Coin Game each agent runs its own PPO (independent PPO), with the other agent treated as part of the environment, exactly as the Q-learners did.

Q9: the pieces of PPO

Statement

(a) What does the critic add, compared with an algorithm that uses the Monte Carlo return of the whole episode (REINFORCE)?

(b) The Q-learners needed -greedy exploration. Where does a PPO agent’s exploration come from, and which term of the loss keeps it from disappearing too early?

(a) REINFORCE pushes every action up in proportion to the whole return that followed it. In a lucky episode even bad moves are reinforced, and the return mixes the effects of many later actions, coin placements and the other agent’s moves, so the gradient estimate has high variance. The critic adds:

  • a Baseline: subtracting asks whether the action did better than usual from this state, which removes the part of the outcome that does not depend on the action and lowers the variance;
  • bootstrapping: with the advantage uses in place of the rest of the episode, so an action is judged mainly by its immediate consequences. This sharpens credit assignment and lowers variance further, at the price of some bias when the critic is wrong.

(The code’s batch normalisation of advantages subtracts the batch mean, a crude constant baseline, so its REINFORCE variant is not entirely without one.)

(b) From the policy itself: the agent samples from the actor’s probabilities, so every action with non-zero probability keeps being tried. Training pushes good actions towards probability 1, which would end exploration; the entropy regularisation term ( times the policy’s entropy) rewards spread-out probabilities, so the policy does not become deterministic too early.

Q10: PPO against the table

Statement

Each agent runs its own PPO learner with the same budget as the tabular learners, without lamps and with 8 lamps.

(a) Without lamps, which learner reaches the higher individual performance after 300 updates, and which one learns faster? Which one needs more computation?

(b) With 8 lamps, compare the two learners. Why is PPO hardly affected? Relate your answer to Q8(f).

(c) Look at the restraint and outcome panels. Does PPO solve the social dilemma? What is the problem that a better function approximator does not solve?

(d) Give one situation in which you would still choose a table rather than a neural network.

Pickups per episode at updates 300 and 1000, own share and welfare at update 1000 (PPO: two seeds of my own implementation; its level depends on implementation details more than the table’s, so the comparisons matter more than its exact numbers):

learner, lamps@300@1000sharewelfare
table, 014.016.90.52+0.6
table, 84.76.60.48−0.3
PPO, 011.5 to 12.612.2 to 13.20.52 to 0.53+0.5 to +0.7
PPO, 811.6 to 12.412.8 to 13.30.51+0.2 to +0.3

(a) Without lamps the table wins in my runs on both counts: it is ahead after 50 updates (10.7 pickups against 6.8 to 8.1), after 300 and after 1000. PPO reaches 11 to 12 pickups by update 200 and then plateaus with an almost deterministic policy (average entropy falls from 1.37 nats, near the maximum , to 0.05 to 0.11 by update 300). The lamp-free game is the best case for a table: 1,152 reachable states, each visited about 444 times. PPO needs much more computation: every decision passes through two networks and each batch is used for 16 gradient steps through both, while the table changes one entry per decision. The notebook’s timing comments put a PPO run at several times a tabular one; in my code it was 125 s against 8 s.

(b) With 8 lamps PPO does as well as without them, while the table drops to 6.6, so PPO now leads by about a factor two. This is the generalisation Q8(f) asked for. The network has one set of weights for all observations, so experience under one lamp pattern is used under every other. The lamps carry no information about the return, so the gradient pushes their weights without a consistent direction, they get no lasting influence, and behaviour depends on the positions alone. The network hardly grows: 8 more inputs add 512 weights to each first layer (the actor goes from 6,788 to 7,300 parameters), while the table goes from 5,832 entries to 1,492,992.

(c) No. At every stage of training restraint stays between 0.48 and 0.56 and welfare between about −0.1 and +1.2 per episode, close to the Q-learners. The rewards can also be lopsided: in one run red averaged −1.0 per episode and blue +1.7. A better function approximator solves a problem of representation, learning a good policy from fewer, more varied data. The dilemma is a problem of incentives: under each agent’s own reward, taking every reachable coin is the best response to anything the other does (Q6(b)), and independent PPO optimises exactly that reward with the other treated as part of the environment. A more capable optimiser of the same selfish objective finds the same defection.

(d) When the state space is small and discrete and every state is visited often, as in the Part I stage game or the lamp-free Coin Game, where the table beat PPO with a fraction of the computation. Or when the values must be exact and inspectable, or the setting needs the convergence guarantee tabular Q-learning has in a stationary single-agent problem.

Q11: wrap-up

Statement

(a) Give two experiments in this lab in which a faster or more capable learner led to a worse, or no better, collective outcome. Quote the numbers.

(b) Complete the sentence, with evidence from Parts II and III: “Deep RL solved …, but not …“.

(c) Suppose the two agents of the Stag Hunt in Part I were PPO learners instead of Q-learners. Would the problem of equilibrium selection disappear? Why (not)?

(a)

  1. More training in the Coin Game. The tabular Q-learners’ welfare peaked at about +2.4 to +2.7 per episode around updates 100 to 200 (12 to 14 pickups, own share 0.60) and fell to +0.6 by update 1000 (16.9 pickups, share 0.52): better at the individual task, worse collectively, ending barely above random agents (about 0) with 4.6 times their pickups.
  2. PPO against the table with 8 lamps. PPO is the more capable learner, 12.8 to 13.3 pickups against 6.6, and its collective outcome is no better: own share 0.51 against 0.48, welfare +0.2 to +0.3 against −0.3, all close to 0.

(b) “Deep RL solved generalisation: 8 irrelevant lamps left PPO at its lamp-free level (12.8 to 13.3 pickups) while they cut the table from 16.9 to 6.6, but not the social dilemma: with either learner the own share stays near 0.5 and welfare near 0, because each agent’s own reward makes taking every coin the best response.”

(c) No. Equilibrium selection comes from the game together with learners that each follow their own payoff, and a network changes neither; with a single state there is nothing to generalise over. For a two-action softmax policy with logit difference , and the expected payoff is , where are the expected payoffs of C and D against a partner who plays C with probability . Since ,

Like Lab 1’s replicator equation , this pushes towards C exactly when . A fresh network gives about , so each agent sees , its gradient points towards D, and the pair drifts to (D,D), as the replicator dynamics do from ; both starting above would lead to (C,C). Both pure equilibria stay stable ( near , near ), so the outcome depends on initialisation and noise. Sampled actions and the entropy bonus keep the policies stochastic, which acts like exploration and, as in Q4, threatens (C,C) more than (D,D). Clipping limits the size of each step and leaves its direction unchanged.

Common pitfalls in Parts II and III

  • Reading an own share above 0.5 as cooperation. Own coins are worth more to a selfish agent (taking one also prevents a −2).
  • Counting all rows as visitable. Only 1,152 of the 1,458 position states can occur.
  • “A better learner fixes the dilemma.” Function approximation fixes representation; the dilemma comes from the rewards.

What to be able to write

  • The stateless Q-learning update, why the term can be dropped, and why a constant learning rate makes an exponentially weighted average of recent payoffs.
  • Why learners from reach (C,C) essentially only if both play C in round 1, and then lock into (D,D).
  • Why the Prisoner’s Dilemma result is a social dilemma and the Stag Hunt result a coordination failure.
  • , and the optimist-sceptic trace.
  • Why exploration knocks learners out of (C,C) and almost never out of (D,D).
  • The Coin Game’s rewards, the welfare formula, and why taking every coin is dominant with expected total 0 per pickup.
  • State counts, reachable states, the budget , and the uniform-visit model with its fit.
  • The pieces of PPO and what the critic adds over REINFORCE.
  • “Deep RL solved generalisation, but not the social dilemma”, and why PPO would not remove equilibrium selection in the Stag Hunt.

Exam questions

Flashcards