Search

Search papers and lessons

Counterfactual Regret Minimization

Level 4 · 12 min read

CFR finds strong strategies for imperfect-information games by running a no-regret learner at every information set; its average strategy approaches equilibrium in two-player zero-sum games.

On this page

  • Colour = topic mix
  • Discrete math
  • Game theory
  • Calculus
  • Linear algebra
  • Microeconomics
  • Optimization
  • ReadReady to readNot yet

TL;DR

Counterfactual regret minimization (CFR) is an algorithm for games where players cannot see everything, such as poker. It repeatedly plays the game against itself, and at every information set it runs a no-regret learner that asks how much each action would have gained compared with the strategy actually played. In a two-player zero-sum game, the average of the strategies it plays approaches a Nash equilibrium, which is a set of strategies where neither player gains by switching.

Builds on: Information Set, No-Regret Learning, Mixed Strategy · Leads to: Self-Play, Minimax Game

Where it's used

Heads-up limit hold'em. In 2015 a team led by Michael Bowling reported that heads-up limit Texas hold'em, a two-player game with a limit on bet sizes, was essentially solved. The computation used a CFR variant run over the game tree, and the resulting strategy is close to unbeatable: no opponent can expect to win more than a negligible amount against it.

Libratus. In January 2017 an AI named Libratus beat professional players at heads-up no-limit Texas hold'em, a game with unlimited bet sizes and a far larger tree. Its blueprint strategy came from CFR-based self-play on an abstracted version of the game, and it then refined its play during the match.

Pluribus. In 2019 Pluribus beat professional players at six-player no-limit Texas hold'em. CFR was run in a sampled form, where the algorithm updates only part of the tree on each pass, which keeps the cost low enough for a game with more than two players. The guarantees are weaker than in the two-player case, but the method worked well in practice.

How it works

Take one decision in a poker-like game and let the learner see only what it can see. The example freezes the opponent so that the arithmetic is easy to follow. The opponent bets with probability 0.8 (write this as H) and checks with probability 0.2 (write this as T). Player 1 chooses H or T, and it earns +1 when its choice matches the opponent's action and −1 otherwise. Player 1 runs regret matching, which is CFR at a single information set.

  1. Start with a uniform strategy. Player 1 plays H and T with probability 0.5 each. Check: the two probabilities add to 1.
  2. Measure each action against the opponent. Against the opponent's 0.8 and 0.2, H earns 0.8⋅1+0.2⋅(−1)=0.60.8 \cdot 1 + 0.2 \cdot (-1) = 0.6, and T earns 0.8⋅(−1)+0.2⋅1=−0.60.8 \cdot (-1) + 0.2 \cdot 1 = -0.6. Check: the two values have the same magnitude and opposite sign, as they should.
  3. Compute the value of the strategy played. The uniform strategy earns 0.5⋅0.6+0.5⋅(−0.6)=00.5 \cdot 0.6 + 0.5 \cdot (-0.6) = 0. Check: the average of the two action values, weighted by the strategy, gives 0.
  4. Record the regret. The regret of an action is its value minus the strategy's value, so H has regret 0.6−0=0.60.6 - 0 = 0.6 and T has regret −0.6−0=−0.6-0.6 - 0 = -0.6. Add these to the running totals, which are now 0.6 for H and −0.6 for T.
  5. Turn the regrets into a strategy. Keep only the positive running totals. Only H is positive, so the next strategy plays H with probability 1, and T with probability 0. Check: a strategy that puts all its weight on the action with positive regret is valid.
  6. Repeat with the new strategy. Playing H with probability 1 earns 0.6, so H has regret 0.6−0.6=00.6 - 0.6 = 0 and T has regret −0.6−0.6=−1.2-0.6 - 0.6 = -1.2. The running totals are now 0.6 for H and −1.8 for T. The next strategy is again H with probability 1.
  7. Average the strategies. Over three iterations, the strategies played were (0.5, 0.5), (1, 0) and (1, 0). The average probability of H is (0.5+1+1)/3≈0.83(0.5 + 1 + 1) / 3 \approx 0.83. Check: the strategy that matters in the end is the average, not the last one.
flowchart LR
  A["Current strategy at each information set"] --> B["Play the game against the opponent"]
  B --> C["Counterfactual value of each action"]
  C --> D["Add regrets to running totals"]
  D --> E["Positive totals give the next strategy"]
  E --> A
  E --> F["Average of strategies converges to equilibrium"]

The math

Setup

Let N={1,2}N = \{1, 2\} be the players, and let σ\sigma be a profile of strategies, one per player. For each information set II of player ii, let A(I)A(I) be the set of actions available there, and let σ(I,a)\sigma(I, a) be the probability of action aa at II. The probability of reaching a history hh under σ\sigma is πσ(h)\pi^\sigma(h), which multiplies the probabilities of every move on the path, including chance moves. Write π−iσ(h)\pi_{-i}^\sigma(h) for the same product with player ii's own moves left out, so it counts only the opponent's and chance's contribution.

Definition: Counterfactual value

The counterfactual value of action aa at information set II for player ii is

viσ(I,a)=∑h∈Iπ−iσ(h) uiσ(h⋅a),v_i^\sigma(I, a) = \sum_{h \in I} \pi_{-i}^\sigma(h) \, u_i^\sigma(h \cdot a),

where uiσ(h⋅a)u_i^\sigma(h \cdot a) is the expected payoff to player ii when play goes through hh and then the action aa, and both players follow σ\sigma from then on. The value of the information set itself is the strategy-weighted average of its action values, which is an expected value: viσ(I)=∑aσ(I,a) viσ(I,a)v_i^\sigma(I) = \sum_{a} \sigma(I, a) \, v_i^\sigma(I, a).

The word "counterfactual" refers to the weight π−iσ\pi_{-i}^\sigma. The value of reaching II is computed as if player ii had done everything it could to reach II, and the chance of its own moves is left out.

Step 2 in symbols: action values

With q=0.8q = 0.8 as the opponent's probability of H, the payoff of H is u1(H)=2q−1=0.6u_1(H) = 2q - 1 = 0.6, and the payoff of T is u1(T)=1−2q=−0.6u_1(T) = 1 - 2q = -0.6. The factor 2q−12q - 1 is the expected payoff of matching minus mismatching, with the probability of each.

Step 4 in symbols: regret

Let σt\sigma_t be the strategy at iteration tt. The instantaneous regret of action aa at II is rt(I,a)=viσt(I,a)−viσt(I)r_t(I, a) = v_i^{\sigma_t}(I, a) - v_i^{\sigma_t}(I), and the cumulative regret after TT iterations is

RT(I,a)=∑t=1Trt(I,a).R_T(I, a) = \sum_{t=1}^{T} r_t(I, a).

With the numbers above, r1(H)=0.6r_1(H) = 0.6 and r1(T)=−0.6r_1(T) = -0.6, so R1(H)=0.6R_1(H) = 0.6 and R1(T)=−0.6R_1(T) = -0.6.

Step 5 in symbols: regret matching

Let RT+(I,a)=max⁡(RT(I,a),0)R_T^{+}(I, a) = \max(R_T(I, a), 0). The next strategy is

σT+1(I,a)={RT+(I,a)∑bRT+(I,b)if the denominator is positive,1∣A(I)∣otherwise.\sigma_{T+1}(I, a) = \begin{cases} \dfrac{R_T^{+}(I, a)}{\sum_{b} R_T^{+}(I, b)} & \text{if the denominator is positive,} \\[1ex] \dfrac{1}{|A(I)|} & \text{otherwise.} \end{cases}

Here ∑b\sum_b adds over the actions bb at II, and the case split covers the start, when no action has positive regret.

Step 7 in symbols: the average strategy

The average strategy is

σˉT(I,a)=∑t=1Tπiσt(I) σt(I,a)∑t=1Tπiσt(I),\bar{\sigma}_T(I, a) = \frac{\sum_{t=1}^{T} \pi_i^{\sigma_t}(I) \, \sigma_t(I, a)}{\sum_{t=1}^{T} \pi_i^{\sigma_t}(I)},

where πiσt(I)\pi_i^{\sigma_t}(I) is the probability that player ii reaches II, weighting each strategy by how often it is actually used. In the frozen-opponent example the information set is at the root, so this weight is 1 at every iteration. The theorem that CFR relies on says that the cumulative regret of each information set grows no faster than the square root of the number of iterations, so the average strategy's distance from equilibrium shrinks as the iterations grow. The result is stated for two-player zero-sum games.

Worked examples

Example
1. Tiny: turning cumulative regrets into a strategy

Three actions at one information set have cumulative regrets (3,1,0)(3, 1, 0).

  1. Keep the positive parts: (3,1,0)(3, 1, 0) is already nonnegative.
  2. Add them: 3+1+0=43 + 1 + 0 = 4.
  3. Divide each by 4: the strategy is (3/4,1/4,0)(3/4, 1/4, 0).
  4. Check: 0.75+0.25+0=10.75 + 0.25 + 0 = 1.
  5. Now take cumulative regrets (−2,−1)(-2, -1) for two actions. No action has positive regret, so the denominator is zero.
  6. Use the fallback: the strategy is (1/2,1/2)(1/2, 1/2).

Interpretation: regret matching puts weight on actions that would have helped in the past, and it falls back to uniform only when nothing would have helped.

Example
2. Standard: why reach probability scales regret

Player 1 reaches information set II only when chance or the opponent lets it. Suppose the probability of that, π−1σ(h)\pi_{-1}^\sigma(h), is 0.2. Under the current strategy σ=(0.5,0.5)\sigma = (0.5, 0.5) for actions call and fold, the continuation payoffs when the action is taken at hh are u(h⋅call)=1u(h \cdot \text{call}) = 1 and u(h⋅fold)=−1u(h \cdot \text{fold}) = -1.

  1. Counterfactual value of call: v(I,call)=0.2⋅1=0.2v(I, \text{call}) = 0.2 \cdot 1 = 0.2.
  2. Counterfactual value of fold: v(I,fold)=0.2⋅(−1)=−0.2v(I, \text{fold}) = 0.2 \cdot (-1) = -0.2.
  3. Value of the information set: v(I)=0.5⋅0.2+0.5⋅(−0.2)=0v(I) = 0.5 \cdot 0.2 + 0.5 \cdot (-0.2) = 0.
  4. Regret of call: 0.2−0=0.20.2 - 0 = 0.2. Regret of fold: −0.2−0=−0.2-0.2 - 0 = -0.2.
  5. Check: if II were reached with probability 1, the regrets would be 1 and −1. The 0.2 factor scales them down by exactly 0.2.

Interpretation: an information set that is rarely reached is updated less, because a mistake there costs the player less in expectation. This is what keeps the update correct when the tree is large and reach probabilities vary across it.

Example
3. Realistic: reading a training log

A training run for a poker agent records the cumulative regrets at one decision, a strong hand facing a bet: raise 120, call 40, fold −30, measured in chips.

  1. Keep the positive parts: raise 120, call 40, fold 0.
  2. Add them: 120+40+0=160120 + 40 + 0 = 160.
  3. Divide: raise 120/160=0.75120 / 160 = 0.75, call 40/160=0.2540 / 160 = 0.25, fold 00.
  4. Check: 0.75+0.25+0=10.75 + 0.25 + 0 = 1.
  5. Read the result: the algorithm would raise three times in four and call once in four, and would never fold, since fold's regret is negative.
  6. Report the average strategy from the run, not this current one, when comparing the agent to others.

Interpretation: a mixed strategy at a single decision is a frequency, and the regrets tell the algorithm which frequency it can still improve on.

Try it: if the regret of call rises to 80 while raise stays at 120, what are the new raise and call probabilities? Answer: the positive total is 120+80=200120 + 80 = 200, so raise is 120/200=0.6120 / 200 = 0.6 and call is 80/200=0.480 / 200 = 0.4.

Common mistakes and tradeoffs

It is tempting to think the current strategy is the one to use. In fact, in a two-player zero-sum game the average of the strategies converges to equilibrium, while the current strategy can oscillate between good and bad plays. The average is the output to report.

It is tempting to think that low regret guarantees an equilibrium in every game. In fact the two-player zero-sum case has the strongest guarantee, and in games with more players or with general payoffs the average strategies approach a weaker equilibrium concept rather than a Nash equilibrium.

It is tempting to think "counterfactual" means the algorithm imagines the opponent behaving differently. In fact it means the player's own reach is left out of the weight, so that a decision is judged by what it would earn if the player had reached the information set.

When to use CFR: when a game has imperfect information, is large enough that enumerating strategies by hand is impossible, and is two-player zero-sum or can be handled by its multi-player variants. When not to use it: when the game is small enough for a linear program, where exact solvers are more precise, or when the task is single-agent learning with a known reward, where policy-gradient methods are usually simpler. Alternatives: linear programming over the sequence form for small games, fictitious play, and policy-gradient methods in reinforcement learning.

History

The regret-matching rule was analysed by Sergiu Hart and Andreu Mas-Colell in 2000, who showed that it drives the empirical frequency of play toward the set of correlated equilibria in general games. Martin Zinkevich, Michael Johanson, Michael Bowling and Carmelo Piccione introduced counterfactual regret minimization in 2007, applying regret matching at every information set of a poker game and proving that the average strategy converges to equilibrium in two-player zero-sum games.

Later variants made the method practical. CFR+ changed the update rule to keep cumulative regrets nonnegative, which sped up convergence in practice. Sampled versions, such as Monte Carlo CFR, update only part of the tree on each pass. CFR+ was behind the 2015 result, and sampled variants were behind the 2017 and 2019 results described above.

Recap

  • CFR runs a no-regret learner at every information set, and the regret of each action is its counterfactual value minus the value of the current strategy.
  • Regret matching turns positive cumulative regrets into the next strategy, and falls back to uniform when no regret is positive.
  • The counterfactual weight leaves out the player's own reach probability, so rarely reached information sets are updated less.
  • In two-player zero-sum games the average strategy approaches a Nash equilibrium, so that average is the output.
  • Read next: Self-Play for training by playing against copies of oneself, and Minimax Game for the zero-sum structure that makes the guarantee possible.

Check yourself

QuestionRecall: what does regret matching do with the cumulative regrets to choose the next strategy?Show answer
It keeps only the positive cumulative regrets, divides each by their total, and uses the result as the next strategy. If no regret is positive, it uses the uniform strategy.
QuestionComputation: an information set has cumulative regrets 6, 2, −4 for three actions. What is the next strategy?Show answer
Keep the positive parts: 6, 2 and 0. Their total is 8, so the strategy is 6/8=0.756/8 = 0.75, 2/8=0.252/8 = 0.25 and 00.
QuestionWhy: why does CFR leave out the player's own reach probability when computing counterfactual values?Show answer
Regret asks whether a different action would have done better at the points where the player decides. Those points are judged as if the player had tried to reach them, so the weight counts only the chance and the opponent's moves. Including the player's own reach would make the update depend on the current strategy in a way that breaks the regret guarantee.
QuestionApplied: a researcher runs CFR on a three-player poker variant and reports the current strategy after the last iteration. What should they report instead, and why?Show answer
They should report the average strategy over the iterations. The guarantee of convergence to equilibrium is for the average, while the current strategy can oscillate. Also, with three players the guarantee is weaker than for two-player zero-sum games, so the result should not be described as a Nash equilibrium.

Sources