Algorithmintro
Iterated elimination of dominated strategies
Also called iterated dominance, IESDS.
Repeatedly removes strictly dominated actions from a finite game until none remains. Every Nash equilibrium survives, and the result does not depend on the order.
- Time
- O(k^2 t) worst
- Space
- O(k) extra
- Where
- k = the total number of pure strategies of all players; t = the number of pure profiles (the size of one payoff table)
- Model
- Word RAM
- Properties
- comparison baseddeterministiciterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Hervé Moulin, 1979
Iterated elimination of dominated strategies is the procedure that removes, one at a time, a strategy of some player that another strategy beats against every remaining choice of the others, and repeats until no such strategy is left. It works on a finite normal-form game. With strict dominance it never removes a strategy that a Nash equilibrium uses, and the set that survives does not depend on the order of removal. With weak dominance, the topic of the variant section, both properties fail. A dominant strategy is the special case in which one strategy beats all the others in one step.
In plain words
Some choices are bad whatever the others do: another choice of the same player is better in every case. A sensible player never makes such a choice, so we can cross it out. Once it is gone, the other players know it is gone, and some of their own choices may now be bad in every remaining case, so we cross those out too. We repeat until nothing more can be crossed out. Sometimes one choice per player is left, and the game is solved. Often more is left, and the method only makes the game smaller. The method must compare against mixtures of choices too, not only single choices. It is safe when "better" means strictly better in every case. When "better" only means never worse, the order of crossing out changes the result.
The problem
The input is a finite game with players , finite sets of pure strategies and utilities on , which each player maximizes. For sets , write for the product of the with . A strategy is strictly dominated relative to if some mixed strategy on has
If can be taken pure, is strictly dominated by a pure strategy. The output is a product of nonempty sets, reached from by removing dominated strategies one at a time, such that no strategy in is strictly dominated relative to . The game is dominance solvable if each has one element.
The algorithm
IESDS(G, DOMINATED)- 1
A_i ← S_i for every player i - 2
repeat - 3
for each player i and each a in A_i, in a fixed order: - 4
if DOMINATED(G, A, i, a) returns a witness w: - 5
A_i ← A_i minus {a} - 6
append (i, a, w) to the log and go back to L2 - 7
until no call of line L4 returns a witness; return A and the log
The test DOMINATED decides one of three relations:
- Strict, by a pure strategy. Look for with for every . This is a direct comparison of two rows of the payoff table of player .
- Strict, by a mixed strategy. Solve one linear program: maximize subject to for every , and . The strategy is dominated exactly when the optimum is positive, and then is the witness. The program is the linear program of a zero-sum game, so LP duality gives a certificate in the other case: a probability distribution on against which is a best response.
- Weak, by a pure strategy. Look for with for every and for at least one . This is the variant whose result depends on the order.
Line L6 restarts the scan after each removal. That keeps the loop simple to analyze. An implementation may also continue the scan, since by the order independence below the result is the same for both strict tests.
Example
Take the bimatrix game below, rows T, M, B for player 1 and columns L, C, R for player 2, row payoff first.
| L | C | R | |
|---|---|---|---|
| T | 4, 3 | 5, 1 | 6, 2 |
| M | 2, 1 | 8, 4 | 3, 6 |
| B | 3, 0 | 9, 6 | 2, 8 |
With the pure test and the order "player 1 first, strategies in order", the run is:
| step | rows left | columns left | removed | witness | why |
|---|---|---|---|---|---|
| 1 | T, M, B | L, C, R | column C | R | column payoffs 2, 6, 8 beat 1, 4, 6 |
| 2 | T, M, B | L, R | row M | T | against L and R, T gets 4, 6 and M gets 2, 3 |
| 3 | T, B | L, R | row B | T | T gets 4, 6 and B gets 3, 2 |
| 4 | T | L, R | column R | L | against T, L gives 3 and R gives 2 |
| 5 | T | L | none |
The game is dominance solvable, and (T, L) with payoffs (4, 3) is its only Nash equilibrium, pure or mixed. In the first step no row is dominated: M is the best row against C, and T is the best row against L and R. Only after C is gone do rows M and B become dominated.
Mixed dominance. In the game with rows T, M, B and columns L, R where the row payoffs are T = (3, 0), M = (0, 3) and B = (1, 1), no pure strategy dominates B: T loses to B against R, and M loses to B against L. The mix gets against each column, which beats 1, so B is strictly dominated by a mixed strategy. The pure test stops at once and keeps all three rows; the mixed test removes B.
Order matters for weak dominance. Take rows T, M, B and columns L, R with payoffs (1, 1), (0, 0) in row T, (1, 1), (2, 1) in row M and (0, 0), (2, 1) in row B. M weakly dominates both T and B. If T goes first, R weakly dominates L, and the result is rows M and B against R, with payoffs (2, 1). If B goes first, L weakly dominates R, and the result is rows T and M against L, with payoffs (1, 1). If T and then B go, the result is row M against both columns. Three orders give three different games.
Correctness
The file proofs/correctness.md proves four claims for both strict tests. The loop stops after at most removals, because each pass through line L5 removes one strategy and no set becomes empty: a strategy that is alone in cannot be dominated. When it stops, no remaining strategy is dominated relative to , by the exit condition of line L7. No removed strategy is played with positive probability in any Nash equilibrium, because a dominated strategy is never a best response to a profile of the others that lives in , and a mixed strategy is a best response only if its support is inside the set of pure best responses . Finally, the result is the same for every order of removal, and every Nash equilibrium of the game restricted to is a Nash equilibrium of the full game. Together these say that the procedure loses no equilibrium and adds none.
Proof: Iterated strict dominance stops, keeps every Nash equilibrium, adds none, and does not depend on the orderfull
Let be a finite game with players , pure strategy sets and utilities , which the players maximize. For a product of subsets , a strategy is strictly dominated relative to if some mixed strategy on has for every , where . The pure test of line L4 is the case where puts weight 1 on one strategy. Every claim below holds for both tests; where the two proofs differ, both are given.
A removed strategy has a dominator that puts no weight on it. If dominates and , then , since would give . Let , a mixed strategy on minus . For every , , so . So from now on each dominator of puts weight 0 on ; the code builds its witness this way.
Termination and the exit condition
Let . Line L1 sets . Each pass through line L5 lowers by exactly 1. A strategy that is alone in is never dominated, because its only possible dominator is itself, which was excluded above. So every stays nonempty, at all times, and line L5 runs at most times. Between two passes through line L5, the scan of line L3 makes at most calls. So the procedure stops. It stops only at line L7, after a full scan in which no call of line L4 returned a witness, so no strategy of the result is strictly dominated relative to .
No removed strategy is used by a Nash equilibrium
Let be a mixed Nash equilibrium of . We show by induction on the number of removals that the support of every stays inside . At line L1, . Suppose the claim holds before line L5 removes from , with dominator relative to . By the induction hypothesis, puts all its weight on profiles , and so
where the inequality is strict because the weights are nonnegative and sum to 1, and each term on the left is larger. Since is an average of the values with , some pure has . So is not a pure best response to . In an equilibrium every strategy in the support of is a pure best response to (if a strategy with were not, moving its weight to a best response would raise ). So , and the claim holds after the removal.
A lemma: pushing a dominator into the surviving sets
Fix one run of the procedure. Number its removals in order, and let be its result. For a removed strategy of player , let be its number, and let be its witness; is a mixed strategy on the set alive at that time, with weight 0 on , and it dominates relative to .
Lemma. Let be a set of profiles of the others, and let be a mixed strategy of player on . Then there is a mixed strategy on with for every , and with strict inequality for every if puts positive weight outside .
Proof. If the support of is inside , take . Otherwise let be the strategy outside in the support of with the smallest , and let . This is a mixed strategy. For each , , so and . The support of is inside , the set alive at time , and does not contain . So every strategy outside in the support of was removed strictly after : those from because they were still alive when was removed, and the others from by the choice of . The smallest removal time outside in the support therefore grows by at least 1 at each step, and it is at most , so after at most steps the support is inside . Each step raised the payoff strictly against every , which gives the lemma. For the pure test, each is pure, stays pure at every step, and is pure.
Every equilibrium of the reduced game is an equilibrium of G
Let be a mixed Nash equilibrium of the game restricted to , so each lives on and no deviation inside gains. Suppose some minus had . Apply the lemma to the pure strategy with : it gives on with for every , so . That is a gain inside , which contradicts the choice of . So no pure deviation of gains, and is a Nash equilibrium of .
Together with the previous section: the Nash equilibria of are exactly the Nash equilibria of the game restricted to .
The result does not depend on the order
Take two runs, with results and . Let the second run remove in this order, where belongs to player and is strictly dominated relative to the set alive before its removal. We show by induction on that no lies in .
Suppose are not in . Then , since is minus these strategies. Suppose were in , with . Its dominator in the second run satisfies for every , and so for every . The lemma for the first run with gives on with for every . Then is strictly dominated relative to (by a pure strategy for the pure test, by the last sentence of the lemma), which contradicts the exit condition of the first run. So .
Hence every strategy that the second run removes is outside , which means . Swapping the two runs gives . So .
Weak dominance
For weak dominance by a pure strategy, termination and the exit condition hold with the same proof. The section on equilibria of fails: in the first order of the example of the page, the equilibrium (T, L) is removed. The section on the reduced game still holds with weak inequalities: the lemma, with in place of , gives for a gaining , the same contradiction. So every equilibrium of the reduced game is an equilibrium of , and since the reduced game is finite, Nash's theorem gives it an equilibrium: at least one equilibrium of survives every order. The order section fails, because the step " with one strict" does not transfer from to the smaller set : the profile with the strict inequality may be gone.
Complexity
Let and let be the number of pure profiles, so the input holds numbers. For the pure test, one call for the pair of player compares pairs of payoffs. One full scan of line L3 tries at most pairs for player , which costs at most comparisons, and in total. There are at most scans, so the time is comparisons in the worst case, in the word-RAM model with payoffs of bounded size. For a bimatrix game with rows and columns this is . The extra space is for the sets and the log.
The mixed test solves one LP with variables and constraints per call, so the whole procedure runs in time polynomial in the input size and its bit length with any polynomial LP method, such as the ellipsoid method or an interior point method (Conitzer and Sandholm 2005). The simplex method is fast in practice but exponential in the worst case. The reference code solves the small LP by trying every vertex, which is exponential and meant only for the games of its tests.
Properties
- Equilibria survive. Every mixed Nash equilibrium of has its support inside the result, and every equilibrium of the reduced game is an equilibrium of . So a dominance solvable game has exactly one Nash equilibrium, and it is pure.
- Order independence. For strict dominance, by pure or by mixed strategies, every order of removal gives the same (Conitzer and Sandholm 2005; Osborne and Rubinstein, Section 4.2).
- Mixed is stronger than pure. The mixed test removes every strategy that the pure test removes, and sometimes more, as in the example. The result of the mixed test is always contained in the result of the pure test.
- Rationalizability. With two players, the strategies that survive mixed strict dominance are exactly the rationalizable ones of Bernheim and Pearce (1984). With three or more players this holds when beliefs about the others may be correlated; the LP certificate above is such a correlated belief.
- Common knowledge. Each round of removal uses one more level of "each player knows that the others are rational". The game is solved only if rationality is common knowledge up to the number of rounds.
Variants and improvements
- Weak dominance. Remove weakly dominated strategies. The result depends on the order, as the example shows, and it can remove Nash equilibria: in the first order of the example, the pure equilibrium (T, L) is lost. Every equilibrium of the reduced game is still an equilibrium of , so at least one equilibrium always survives. Conitzer and Sandholm (2005) proved that deciding if some order of weak removals eliminates a given strategy is NP-complete, and so is deciding if some order leaves one profile, both with and without mixed dominators. Gilboa, Kalai and Zemel (1993) had proved a version of these results for dominance by pure strategies.
- Simultaneous removal. Remove in each round all strategies that are weakly dominated relative to the current sets. This fixes one order, so the result is unique, and it is a common way to state weak iterated dominance.
- Dominance in succinct games. In Bayesian games and other games given succinctly, iterated dominance by pure strategies can need exponentially many rounds (Conitzer and Sandholm 2005).
- Extensive games. Backward induction in a finite game of perfect information removes, at each node, the moves that are worse for the mover; it is related to iterated weak dominance in the normal form, and it gives a subgame perfect equilibrium.
When to use it
Run strict elimination first on any game you want to solve. It is exact, it never loses an equilibrium, and it can shrink the game a lot before an expensive method such as support enumeration or the Lemke-Howson algorithm. Use the pure test when speed matters and the mixed test when you have an LP solver, since it removes more. Use weak dominance only with a stated order, and only when you accept that some equilibria may be lost.
Pitfalls
- Testing only pure dominators. A strategy that no pure strategy dominates can still be dominated by a mix, as B in the example. A program that tests only pure strategies is correct but removes less; say which test it uses.
- Weak for strict. Writing in place of in the pure test turns the procedure into weak elimination, which depends on the order and can lose equilibria.
- Dominance relative to the full game. After a removal, the test must use the current sets of the other players. A strategy that is not dominated against all of can become dominated against , as rows M and B in the example.
- Floating point. The test compares exact payoffs. With floats, two equal sums can compare unequal, and a strategy can be removed by a tie. Keep payoffs rational, as the code does with Fraction.
- Reading survival as play. The surviving set is what rationality alone allows. A game where nothing is dominated, such as matching pennies, is not solved by the method at all.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Shared helper of the algorithmic game theory pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Finite games in normal form, with exact payoffs and exact equilibrium checks.
A game is a pair (sizes, pay). sizes is a tuple (k_1, ..., k_n) of the numbers of pure
strategies of the n players; the pure strategies of player i are 0, ..., k_i - 1. pay is a
dict that maps each profile, a tuple s = (s_1, ..., s_n), to a tuple of n Fraction
utilities, which each player maximizes. A cost game passes the utilities u = -c.
A mixed profile sigma is a list of n lists; sigma[i][a] is the probability, a Fraction,
that player i plays a. A distribution on profiles (for correlated and coarse correlated
equilibria) is a dict from profiles to Fraction; missing profiles have probability 0.
All checks are exact: there is no tolerance anywhere. There is no LP and no equilibrium
algorithm in this module.
"""
from fractions import Fraction
from itertools import product
def profiles(sizes):
"""Return the list of all pure profiles, in lexicographic order."""
return list(product(*(range(k) for k in sizes)))
def from_bimatrix(A, B):
"""Return the game of the bimatrix (A, B): the row player gets A[r][c], the column player B[r][c]."""
m, n = len(A), len(A[0])
if len(B) != m or any(len(row) != n for row in A) or any(len(row) != n for row in B):
raise ValueError("A and B must be m by n matrices of the same shape")
pay = {(r, c): (Fraction(A[r][c]), Fraction(B[r][c])) for r in range(m) for c in range(n)}
return (m, n), pay
def random_game(rng, sizes, lo, hi):
"""Return a game with integer utilities drawn uniformly from lo to hi (inclusive), as Fraction."""
sizes = tuple(sizes)
pay = {s: tuple(Fraction(rng.randint(lo, hi)) for _ in sizes) for s in profiles(sizes)}
return sizes, pay
def _replace(s, i, a):
return s[:i] + (a,) + s[i + 1:]
def _weight(sigma, s, skip=None):
w = Fraction(1)
for k, a in enumerate(s):
if k != skip:
w *= sigma[k][a]
if w == 0:
return w
return w
def expected_utility(game, i, sigma):
"""Return u_i(sigma), the expected utility of player i when the players draw independently."""
sizes, pay = game
return sum((_weight(sigma, s) * pay[s][i] for s in profiles(sizes)), Fraction(0))
def deviation_payoffs(game, i, sigma):
"""Return the list of u_i(a, sigma_-i) for every pure strategy a of player i."""
sizes, pay = game
out = [Fraction(0)] * sizes[i]
for s in profiles(sizes):
w = _weight(sigma, s, skip=i)
if w:
out[s[i]] += w * pay[s][i]
return out
def pure_best_responses(game, i, sigma):
"""Return the sorted list of the pure strategies of player i that maximize u_i(a, sigma_-i)."""
d = deviation_payoffs(game, i, sigma)
best = max(d)
return [a for a, v in enumerate(d) if v == best]
def max_gain(game, sigma):
"""Return the largest gain of any player from a pure deviation: max_i (max_a u_i(a, sigma_-i) - u_i(sigma)).
The result is never negative, because u_i(sigma) is an average of the deviation payoffs.
"""
sizes, _ = game
gain = Fraction(0)
for i in range(len(sizes)):
d = deviation_payoffs(game, i, sigma)
u = sum((p * v for p, v in zip(sigma[i], d)), Fraction(0))
gain = max(gain, max(d) - u)
return gain
def is_distribution(p):
"""Return True if p (a sequence, or a dict of probabilities) is nonnegative and sums to exactly 1."""
vals = list(p.values()) if isinstance(p, dict) else list(p)
return all(v >= 0 for v in vals) and sum(vals, Fraction(0)) == 1
def _is_mixed_profile(game, sigma):
sizes, _ = game
return len(sigma) == len(sizes) and all(
len(sigma[i]) == k and is_distribution(sigma[i]) for i, k in enumerate(sizes))
def is_nash(game, sigma):
"""Return True if sigma is a mixed Nash equilibrium: no pure deviation gains for any player."""
return _is_mixed_profile(game, sigma) and max_gain(game, sigma) == 0
def is_epsilon_nash(game, sigma, eps):
"""Return True if no player gains more than eps by a pure deviation (the additive form)."""
return _is_mixed_profile(game, sigma) and max_gain(game, sigma) <= eps
def _check_dist(game, dist):
sizes, _ = game
allowed = set(profiles(sizes))
return all(s in allowed for s in dist) and is_distribution(dist)
def is_correlated(game, dist):
"""Return True if dist is a correlated equilibrium.
For every player i and every pair a, b of its pure strategies, the sum over the profiles s
with s_i = a of dist(s) (u_i(s) - u_i(b, s_-i)) is at least 0.
"""
sizes, pay = game
if not _check_dist(game, dist):
return False
for i, k in enumerate(sizes):
for a in range(k):
rows = [(q, s) for s, q in dist.items() if s[i] == a and q]
for b in range(k):
if b != a and sum((q * (pay[s][i] - pay[_replace(s, i, b)][i]) for q, s in rows), Fraction(0)) < 0:
return False
return True
def is_coarse_correlated(game, dist):
"""Return True if dist is a coarse correlated equilibrium.
For every player i and every pure strategy b, E_{s ~ dist} u_i(s) >= E_{s ~ dist} u_i(b, s_-i).
"""
sizes, pay = game
if not _check_dist(game, dist):
return False
for i, k in enumerate(sizes):
here = sum((q * pay[s][i] for s, q in dist.items()), Fraction(0))
for b in range(k):
if sum((q * pay[_replace(s, i, b)][i] for s, q in dist.items()), Fraction(0)) > here:
return False
return True
def pure_nash_brute(game):
"""Return the list of all pure Nash equilibria, found by checking every profile."""
sizes, pay = game
out = []
for s in profiles(sizes):
if all(pay[s][i] >= pay[_replace(s, i, b)][i] for i in range(len(sizes)) for b in range(sizes[i])):
out.append(s)
return out
iterated_elimination_of_dominated_strategies.py 158 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iterated-elimination-of-dominated-strategies/. The authors are listed in prov/M509ET.jsonl.
"""Iterated elimination of dominated strategies in a finite normal-form game.
A game is the pair (sizes, pay) of the helper agtgame: pay maps each profile to a tuple of
Fraction utilities, which the players maximize. The surviving strategies are returned as a
list of sorted lists, one per player.
Three dominance tests are given:
- strict dominance by a pure strategy (a direct comparison),
- strict dominance by a mixed strategy (one small linear program, solved here exactly by
checking every vertex, which is only meant for the small games of the tests),
- weak dominance by a pure strategy, whose iterated result depends on the order.
"""
from fractions import Fraction
from itertools import combinations, product
def _contexts(alive, i):
"""The profiles of the other players that are still alive, as tuples with a hole at i."""
return list(product(*(alive[k] if k != i else [None] for k in range(len(alive)))))
def _put(t, i, a):
return t[:i] + (a,) + t[i + 1:]
def dominated_by_pure(game, alive, i, a):
"""Return a strategy b in alive[i] with u_i(b, t) > u_i(a, t) for every alive t, or None."""
_, pay = game
ctx = _contexts(alive, i)
for b in alive[i]:
if b != a and all(pay[_put(t, i, b)][i] > pay[_put(t, i, a)][i] for t in ctx):
return b
return None
def weakly_dominated_by_pure(game, alive, i, a):
"""Return b in alive[i] with u_i(b, t) >= u_i(a, t) for every alive t and > for one, or None."""
_, pay = game
ctx = _contexts(alive, i)
for b in alive[i]:
if b == a:
continue
d = [pay[_put(t, i, b)][i] - pay[_put(t, i, a)][i] for t in ctx]
if all(x >= 0 for x in d) and any(x > 0 for x in d):
return b
return None
def _solve(M, rhs):
"""Solve the square system M x = rhs exactly; return None if M is singular."""
k = len(M)
A = [list(row) + [r] for row, r in zip(M, rhs)]
for col in range(k):
piv = next((r for r in range(col, k) if A[r][col] != 0), None)
if piv is None:
return None
A[col], A[piv] = A[piv], A[col]
for r in range(k):
if r != col and A[r][col] != 0:
f = A[r][col] / A[col][col]
A[r] = [x - f * y for x, y in zip(A[r], A[col])]
return [A[r][k] / A[r][r] for r in range(k)]
def maximin(D):
"""Return (z, x) with x in the simplex over the rows of D maximizing z = min_c sum_r x_r D[r][c].
This is the linear program max z subject to sum_r x_r D[r][c] >= z for every column c,
x >= 0 and sum_r x_r = 1. Its optimum is at a vertex, where R of the C + R inequalities are
tight (R rows, C columns). The function tries every choice of R tight inequalities, which
is exponential and only meant for small matrices.
"""
R, C = len(D), len(D[0])
best = None
# Unknowns: x_0, ..., x_{R-1}, z. Inequality j < C: sum_r x_r D[r][j] - z >= 0.
# Inequality C + r: x_r >= 0. The equality sum_r x_r = 1 is always tight.
rows = [[D[r][c] for r in range(R)] + [Fraction(-1)] for c in range(C)]
rows += [[Fraction(int(r == q)) for q in range(R)] + [Fraction(0)] for r in range(R)]
eq = [Fraction(1)] * R + [Fraction(0)]
for tight in combinations(range(C + R), R):
sol = _solve([rows[j] for j in tight] + [eq], [Fraction(0)] * R + [Fraction(1)])
if sol is None:
continue
x, z = sol[:R], sol[R]
if all(v >= 0 for v in x) and all(sum(x[r] * D[r][c] for r in range(R)) >= z for c in range(C)):
if best is None or z > best[0]:
best = (z, x)
return best
def mixed_dominance(game, alive, i, a):
"""Decide if a is strictly dominated by a mixed strategy on the alive strategies.
Returns ("dominated", sigma), where sigma is a dict from the other alive strategies of
player i to probabilities with sum_b sigma_b u_i(b, t) > u_i(a, t) for every alive t, or
("best response", q), where q is a dict from alive contexts t to probabilities such that a
is a best response of player i to the belief q (Pearce's lemma, by LP duality).
"""
_, pay = game
ctx = _contexts(alive, i)
rivals = [b for b in alive[i] if b != a]
if not rivals:
return "best response", {ctx[0]: Fraction(1)}
D = [[pay[_put(t, i, b)][i] - pay[_put(t, i, a)][i] for t in ctx] for b in rivals]
z, x = maximin(D)
if z > 0:
return "dominated", {b: p for b, p in zip(rivals, x) if p}
# The dual: a belief q over the contexts with sum_t q_t D[b][t] <= 0 for every rival b.
w, q = maximin([[-D[b][t] for b in range(len(rivals))] for t in range(len(ctx))])
assert -w == z, "the primal and dual values differ"
return "best response", {t: p for t, p in zip(ctx, q) if p}
def dominated_by_mixed(game, alive, i, a):
"""Return a mixed strategy (a dict) that strictly dominates a, or None."""
kind, cert = mixed_dominance(game, alive, i, a)
return cert if kind == "dominated" else None
TESTS = {"pure": dominated_by_pure, "mixed": dominated_by_mixed, "weak": weakly_dominated_by_pure}
def iterated_elimination(game, rule="pure", pick=None):
"""Remove dominated strategies until none is left, and return (alive, log).
rule is "pure" or "mixed" (strict dominance) or "weak" (weak dominance by a pure strategy).
pick chooses which dominated strategy to remove when several are: it gets the list of
(player, strategy) pairs and returns one of them. By default the first pair in the order
of players and strategies is removed. log lists (player, strategy, witness) in the order of
removal.
"""
test = TESTS[rule]
sizes, _ = game
alive = [list(range(k)) for k in sizes] # @line L1
log = []
while True: # @line L2
found = []
for i in range(len(sizes)): # @line L3
for a in alive[i]:
w = test(game, alive, i, a) # @line L4
if w is not None:
found.append((i, a, w))
if pick is None:
break
if found and pick is None:
break
if not found: # @line L7
return alive, log
if pick is None:
i, a, w = found[0]
else:
i, a = pick([(i, a) for i, a, _ in found])
w = next(x for j, b, x in found if (j, b) == (i, a))
alive[i].remove(a) # @line L5
log.append((i, a, w)) # @line L6
test_iterated_elimination_of_dominated_strategies.py 270 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/iterated-elimination-of-dominated-strategies/. The authors are listed in prov/M509ET.jsonl.
import random
from fractions import Fraction as F
import agtgame
from agtgame import (deviation_payoffs, expected_utility, from_bimatrix, is_coarse_correlated,
is_correlated, is_distribution, is_epsilon_nash, is_nash, max_gain, profiles,
pure_best_responses, pure_nash_brute, random_game)
from iterated_elimination_of_dominated_strategies import (
dominated_by_mixed, dominated_by_pure, iterated_elimination, maximin, mixed_dominance,
weakly_dominated_by_pure)
H = F(1, 2)
T3 = F(1, 3)
PD = from_bimatrix([[3, 0], [5, 1]], [[3, 5], [0, 1]]) # 0 = cooperate, 1 = defect
PENNIES = from_bimatrix([[1, -1], [-1, 1]], [[-1, 1], [1, -1]])
RPS_A = [[0, -1, 1], [1, 0, -1], [-1, 1, 0]]
RPS = from_bimatrix(RPS_A, [[-x for x in row] for row in RPS_A])
BOS = from_bimatrix([[2, 0], [0, 1]], [[1, 0], [0, 2]])
# Chicken, strategy 0 = dare (D), 1 = chicken (C).
CHICKEN = from_bimatrix([[0, 7], [2, 6]], [[0, 2], [7, 6]])
# ---------------------------------------------------------------- the helper agtgame
def test_profiles_and_shapes():
assert profiles((2, 3)) == [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)]
assert len(profiles((2, 3, 4))) == 24
sizes, pay = from_bimatrix([[1, 2, 3]], [[4, 5, 6]])
assert sizes == (1, 3) and pay[(0, 2)] == (F(3), F(6))
g1 = random_game(random.Random(7), (2, 2, 2), -3, 3)
g2 = random_game(random.Random(7), (2, 2, 2), -3, 3)
assert g1 == g2 and all(-3 <= v <= 3 and isinstance(v, F) for t in g1[1].values() for v in t)
def test_expected_utility_matches_brute_force():
rng = random.Random(11)
for _ in range(30):
sizes = tuple(rng.randint(1, 3) for _ in range(rng.randint(2, 3)))
game = random_game(rng, sizes, -5, 5)
sigma = []
for k in sizes:
w = [rng.randint(0, 4) for _ in range(k)]
if sum(w) == 0:
w[0] = 1
sigma.append([F(x, sum(w)) for x in w])
for i in range(len(sizes)):
brute = sum(F(1) * game[1][s][i] * _prod(sigma[k][s[k]] for k in range(len(s)))
for s in profiles(sizes))
assert expected_utility(game, i, sigma) == brute
d = deviation_payoffs(game, i, sigma)
assert sum(p * v for p, v in zip(sigma[i], d)) == brute
best = max(d)
assert pure_best_responses(game, i, sigma) == [a for a in range(sizes[i]) if d[a] == best]
assert max_gain(game, sigma) >= 0
def _prod(xs):
out = F(1)
for x in xs:
out *= x
return out
def test_check_values_of_nash():
assert is_nash(PENNIES, [[H, H], [H, H]])
assert not is_nash(PENNIES, [[F(1), F(0)], [H, H]])
assert pure_nash_brute(PENNIES) == []
assert is_nash(RPS, [[T3] * 3, [T3] * 3]) and expected_utility(RPS, 0, [[T3] * 3, [T3] * 3]) == 0
mixed = [[F(2, 3), T3], [T3, F(2, 3)]]
assert is_nash(BOS, mixed)
assert expected_utility(BOS, 0, mixed) == F(2, 3) == expected_utility(BOS, 1, mixed)
assert pure_nash_brute(BOS) == [(0, 0), (1, 1)]
chick = [[T3, F(2, 3)], [T3, F(2, 3)]]
assert is_nash(CHICKEN, chick) and expected_utility(CHICKEN, 0, chick) == F(14, 3)
assert pure_nash_brute(PD) == [(1, 1)]
def test_epsilon_nash_and_distributions():
sigma = [[F(1), F(0)], [F(1), F(0)]] # both cooperate in the prisoner's dilemma
assert max_gain(PD, sigma) == 2
assert is_epsilon_nash(PD, sigma, F(2)) and not is_epsilon_nash(PD, sigma, F(199, 100))
assert not is_nash(PD, [[H, F(1, 3)], [H, H]]) # not a distribution
assert is_distribution([H, H]) and not is_distribution([H, F(2, 3)])
assert not is_distribution({(0, 0): F(3, 2), (1, 1): -H})
def test_correlated_and_coarse_correlated():
third = {(1, 1): T3, (0, 1): T3, (1, 0): T3}
assert is_correlated(CHICKEN, third) and is_coarse_correlated(CHICKEN, third)
assert all(sum(q * CHICKEN[1][s][i] for s, q in third.items()) == 5 for i in (0, 1))
best = {(0, 1): F(1, 4), (1, 0): F(1, 4), (1, 1): H}
assert is_correlated(CHICKEN, best)
assert all(sum(q * CHICKEN[1][s][i] for s, q in best.items()) == F(21, 4) for i in (0, 1))
assert not is_correlated(CHICKEN, {(1, 1): F(1)})
# The product of the mixed equilibrium is a correlated equilibrium.
x = [T3, F(2, 3)]
prod = {(r, c): x[r] * x[c] for r in range(2) for c in range(2)}
assert is_correlated(CHICKEN, prod)
# Rock-paper-scissors: uniform on the six profiles without a tie is a CCE but not a CE.
six = {(r, c): F(1, 6) for r in range(3) for c in range(3) if r != c}
assert is_coarse_correlated(RPS, six) and not is_correlated(RPS, six)
assert not is_correlated(CHICKEN, {(5, 5): F(1)})
def test_every_ce_is_a_cce_on_random_games():
rng = random.Random(3)
for _ in range(200):
game = random_game(rng, (rng.randint(2, 3), rng.randint(2, 3)), 0, 4)
ps = profiles(game[0])
w = [rng.randint(0, 3) for _ in ps]
if sum(w) == 0:
continue
dist = {s: F(x, sum(w)) for s, x in zip(ps, w)}
if is_correlated(game, dist):
assert is_coarse_correlated(game, dist)
# Pure equilibria are correlated equilibria.
for s in pure_nash_brute(game):
assert is_correlated(game, {s: F(1)})
# ---------------------------------------------------------------- the elimination
def test_prisoners_dilemma_is_solved():
alive, log = iterated_elimination(PD)
assert alive == [[1], [1]]
assert [(i, a) for i, a, _ in log] == [(0, 0), (1, 0)]
THREE = from_bimatrix([[4, 5, 6], [2, 8, 3], [3, 9, 2]], [[3, 1, 2], [1, 4, 6], [0, 6, 8]])
def test_trace_of_the_page():
alive, log = iterated_elimination(THREE)
assert alive == [[0], [0]]
assert [(i, a, w) for i, a, w in log] == [(1, 1, 2), (0, 1, 0), (0, 2, 0), (1, 2, 0)]
MIXED_ONLY = from_bimatrix([[3, 0], [0, 3], [1, 1]], [[1, 0], [0, 1], [1, 0]])
def test_mixed_dominance_without_pure_dominance():
alive = [[0, 1, 2], [0, 1]]
assert dominated_by_pure(MIXED_ONLY, alive, 0, 2) is None
assert dominated_by_mixed(MIXED_ONLY, alive, 0, 2) == {0: H, 1: H}
kind, belief = mixed_dominance(MIXED_ONLY, alive, 0, 0)
assert kind == "best response"
assert iterated_elimination(MIXED_ONLY, "pure")[0] == [[0, 1, 2], [0, 1]]
assert iterated_elimination(MIXED_ONLY, "mixed")[0][0] == [0, 1]
def _check_certificate(game, alive, i, a):
_, pay = game
kind, cert = mixed_dominance(game, alive, i, a)
others = [b for b in alive[i] if b != a]
ctx = agt_contexts(alive, i)
if kind == "dominated":
assert is_distribution(cert) and set(cert) <= set(others)
for t in ctx:
assert sum(p * pay[put(t, i, b)][i] for b, p in cert.items()) > pay[put(t, i, a)][i]
else:
assert is_distribution(cert) and set(cert) <= set(ctx)
ua = sum(q * pay[put(t, i, a)][i] for t, q in cert.items())
for b in others:
assert sum(q * pay[put(t, i, b)][i] for t, q in cert.items()) <= ua
return kind
def agt_contexts(alive, i):
from iterated_elimination_of_dominated_strategies import _contexts
return _contexts(alive, i)
def put(t, i, a):
return t[:i] + (a,) + t[i + 1:]
def test_certificates_on_random_games():
rng = random.Random(5)
for _ in range(120):
sizes = (rng.randint(2, 4), rng.randint(2, 3)) if rng.random() < 0.7 else (2, 2, 2)
game = random_game(rng, sizes, 0, 6)
alive = [list(range(k)) for k in sizes]
for i in range(len(sizes)):
for a in alive[i]:
kind = _check_certificate(game, alive, i, a)
if dominated_by_pure(game, alive, i, a) is not None:
assert kind == "dominated"
def test_maximin_value_against_a_grid():
rng = random.Random(9)
for _ in range(40):
cols = rng.randint(1, 4)
D = [[F(rng.randint(-4, 4)) for _ in range(cols)] for _ in range(2)]
z, x = maximin(D)
grid = max(min(F(k, 60) * D[0][c] + F(60 - k, 60) * D[1][c] for c in range(len(D[0])))
for k in range(61))
assert z >= grid and is_distribution(x)
def _restricted_pure_nash(game, alive):
sizes, pay = game
out = []
import itertools
for s in itertools.product(*alive):
if all(pay[s][i] >= pay[put(s, i, b)][i] for i in range(len(sizes)) for b in alive[i]):
out.append(s)
return out
def test_order_does_not_matter_for_strict_dominance():
rng = random.Random(1)
for trial in range(60):
sizes = (rng.randint(2, 4), rng.randint(2, 4)) if trial % 3 else (2, 3, 2)
game = random_game(rng, sizes, 0, 5)
for rule in ("pure", "mixed"):
base, _ = iterated_elimination(game, rule)
for seed in range(3):
r = random.Random(seed)
other, _ = iterated_elimination(game, rule, pick=lambda c: r.choice(c))
assert other == base
# Every pure Nash equilibrium survives, and the equilibria of the reduced game
# are exactly the pure equilibria of the original game.
pne = pure_nash_brute(game)
assert all(all(s[i] in base[i] for i in range(len(sizes))) for s in pne)
assert _restricted_pure_nash(game, base) == pne
assert all(set(m) <= set(p) for m, p in zip(iterated_elimination(game, "mixed")[0],
iterated_elimination(game, "pure")[0]))
WEAK = from_bimatrix([[1, 0], [1, 2], [0, 2]], [[1, 0], [1, 1], [0, 1]])
def _priority(order):
return lambda c: min(c, key=lambda p: order.index(p) if p in order else len(order))
def test_weak_dominance_depends_on_the_order():
# Rows T, M, B are 0, 1, 2 and columns L, R are 0, 1.
first, _ = iterated_elimination(WEAK, "weak", pick=_priority([(0, 0), (1, 0)]))
assert first == [[1, 2], [1]]
assert all(WEAK[1][(r, 1)] == (F(2), F(1)) for r in first[0])
other, _ = iterated_elimination(WEAK, "weak", pick=_priority([(0, 2), (1, 1)]))
assert other == [[0, 1], [0]]
assert all(WEAK[1][(r, 0)] == (F(1), F(1)) for r in other[0])
third, _ = iterated_elimination(WEAK, "weak")
assert third == [[1], [0, 1]]
assert weakly_dominated_by_pure(WEAK, [[0, 1, 2], [0, 1]], 0, 0) == 1
assert dominated_by_pure(WEAK, [[0, 1, 2], [0, 1]], 0, 0) is None
def test_nothing_to_remove():
for g in (PENNIES, RPS, BOS, CHICKEN):
for rule in ("pure", "mixed", "weak"):
alive, log = iterated_elimination(g, rule)
assert alive == [list(range(k)) for k in g[0]] and log == []
def test_helper_has_no_algorithm():
names = {n for n in dir(agtgame) if not n.startswith("_")}
assert names >= {"profiles", "from_bimatrix", "random_game", "expected_utility",
"deviation_payoffs", "pure_best_responses", "max_gain", "is_nash",
"is_epsilon_nash", "is_distribution", "is_correlated",
"is_coarse_correlated", "pure_nash_brute"}
History
The removal of dominated strategies is part of the classical analysis of games in normal form; Osborne and Rubinstein (1994, Chapter 4) give the standard modern account. Moulin (1979) called a game dominance solvable when iterated removal of dominated strategies leaves one outcome, and used it for voting rules. Bernheim (1984) and Pearce (1984) defined rationalizability, and Pearce proved the lemma that a strategy is never a best response exactly when a mixed strategy strictly dominates it. Gilboa, Kalai and Zemel (1993) studied the complexity of the procedure and proved questions about the weak version NP-complete for pure dominators. Conitzer and Sandholm (2005) gave one LP for mixed dominance, path independence and polynomial time for strict iterated dominance, and NP-completeness for weak iterated dominance with and without mixed dominators.
References
- Martin J. Osborne and Ariel Rubinstein, A Course in Game Theory, MIT Press, 1994, Chapter 4, Section 4.2 (iterated elimination of strictly dominated actions, and its link to rationalizability) and Section 4.3 (weakly dominated actions)
- Yoav Shoham and Kevin Leyton-Brown, Multiagent Systems, Algorithmic, Game-Theoretic, and Logical Foundations, Cambridge University Press, 2009, Chapter 4 (computing solution concepts of normal-form games), the section on domination and iterated removal
- The complexity of eliminating dominated strategies, the NP-completeness of questions about the iterated elimination of weakly dominated strategies, with dominance by pure strategies
- Vincent Conitzer and Tuomas Sandholm, Complexity of (iterated) dominance, Proceedings of the 6th ACM Conference on Electronic Commerce (EC 2005), 88-97, one LP decides dominance by a mixed strategy; iterated strict dominance is path independent and polynomial; deciding if a strategy can be removed by iterated weak dominance is NP-complete
- Rationalizable strategic behavior and the problem of perfection, the lemma that a strategy is never a best response if and only if a mixed strategy strictly dominates it
- Rationalizable strategic behavior, the definition of rationalizable strategies
- Dominance solvable voting schemes, the definition of a dominance solvable game
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag M509ET Edit this page History Report an error Markdown