Algorithmadvanced
Proportional response dynamics
Also called proportional response.
Each buyer splits its budget in proportion to the utility each good gave it last round. It converges to the Fisher market equilibrium.
- Time
- O(T n m) worst
- Space
- O(n m) extra
- Where
- T = the number of rounds; m = the number of goods; n = the number of buyers
- Model
- Real RAM
- Properties
- deterministiciterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Fang Wu, Li Zhang, 2007
Proportional response dynamics is a simple, distributed way to reach the equilibrium of a linear Fisher market. In every round, each buyer bids money on goods, each good's price is the total money bid on it, and each buyer gets a share of the good equal to her share of the bids. Then every buyer splits her budget again, in proportion to the utility that each good gave her in the round that just ended. No buyer solves an optimization problem, there is no step size, and every good is sold in every round. Birnbaum, Devanur and Xiao showed that one round is exactly one step of mirror descent with the Kullback-Leibler divergence on a convex potential of Shmyrev, and from this the potential gap is at most after rounds.
In plain words
Every buyer has a budget and spreads it as bids over the goods she likes. A good costs whatever money was bid on it, and each bidder gets a piece of it in proportion to her bid. A buyer then looks at what each good gave her: if one good gave her half of her total pleasure, she puts half of her budget on it in the next round. Goods that pay off well get more money, and goods that pay off badly get less. Prices rise on goods that many buyers like and fall on the others. Round after round, the bids settle at the market equilibrium, where every buyer spends only on her best goods.
The problem
There are buyers and goods, with one unit of each good. Buyer has a budget and utility for all of good , linear in the amount. Every buyer likes some good and every good is liked by some buyer. A bid matrix has , when , and for each buyer. Find bids whose prices are the equilibrium prices: with the allocation , every buyer spends only on goods of maximum bang per buck .
The algorithm
PROPORTIONAL-RESPONSE(utilities u, budgets e, rounds T)- 1
b_ij ← e_i / (the number of goods that i likes) for every good j with u_ij > 0, else 0 - 2
for t ← 1 to T do - 3
p_j ← Σ_i b_ij for every good j - 4
x_ij ← b_ij / p_j for every buyer i and good j - 5
v_i ← Σ_j u_ij x_ij for every buyer i - 6
b_ij ← e_i u_ij x_ij / v_i for every buyer i and good j - 7
return the bids of all rounds
Line L3 clears the market: the price of a good is the money on it. Line L4 shares each good in proportion to the bids, so every good is fully allocated. Line L5 is the utility of each buyer, and line L6 splits her budget in proportion to the parts of that utility. The new bids again add up to . A bid that is positive stays positive, so any start with positive bids on all liked goods works; line L1 is only one choice.
The Shmyrev potential of a bid matrix is
where the second sum is over the pairs with . It is convex, and its minimizers are exactly the equilibrium bids. Its gradient is , and line L6 equals , scaled to the budget of buyer . This is mirror descent with step and the KL divergence, which is the multiplicative weights form of gradient descent.
Example
Two buyers and two goods, , , budgets . At the equilibrium the prices are : buyer 1 has bang per buck and spends her on good 1, and buyer 2 has bang per buck and spends her on good 2. The minimum of is .
| round | prices | bids of buyer 1 | bids of buyer 2 | |
|---|---|---|---|---|
| 0 | ||||
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 5 | ||||
| 10 | ||||
| 20 |
In round 0, buyer 1 gets of each good and utility , half of it from each good, so she keeps her split. Buyer 2 gets of each good, with utility from good 1 and from good 2, so she moves to the split . In round 1 the prices are already , but the bids are not an equilibrium, because both buyers still bid on a good that is not their best. The prices then move away and come back as the bids concentrate. goes down in every round.
For the market , with budgets , the prices stay at and buyer 1 bids exactly on good 1 in round .
Correctness
The proof is in proofs/correctness.md. The minimizers of over the bid matrices are the equilibrium bids, by the optimality conditions. Line L6 is the mirror descent step, and is smooth relative to the KL divergence with constant : the gap is the KL divergence of the price vectors, which is at most the KL divergence of the bids by the log sum inequality. With the three-point identity of the KL divergence, this gives that never goes up, that never goes up, and that . So the prices converge to the unique equilibrium prices and the bids converge to equilibrium bids.
Proof: Proportional response is mirror descent on the Shmyrev potential and converges to the Fisher equilibriumfull
Fix buyers with budgets , goods with one unit each, and utilities , where every buyer likes some good and every good is liked by some buyer. Let . The bid set is
with off . For write , and let
with . Let be the bids in that are positive on all of . On every price is positive, because every good is liked by some buyer, and is differentiable with . The algorithm always terminates, since it runs rounds of finite work; the claims below are about the quality of the bids.
Claim 1 (Shmyrev). is convex and continuous on and has a minimum there. A bid matrix minimizes if and only if the prices and the allocation form a Fisher market equilibrium.
Proof. The function is convex and continuous on , is linear in , and the second sum is linear, so is convex and continuous on the compact set and has a minimum.
Let be a minimizer. Suppose some good has , and let like . Move from a positive bid of buyer to . The term changes by , and all other terms change by , so for small the potential goes down, which is impossible. So all prices are positive, is differentiable near in , and the constraints are linear, so minimizes if and only if for each buyer there is with for all , with equality when . Since , this says that for all liked goods, with equality where buyer bids. So the condition says exactly that each buyer bids only on goods of maximum bang per buck.
If this holds, then with every good is fully allocated (), every buyer spends , and she spends only on goods of maximum bang per buck, so her bundle is optimal for her linear utility. That is an equilibrium. Conversely, at an equilibrium every price is positive (a good with price would have unbounded demand), the money lies in (a buyer with positive maximum bang per buck never spends on a good she does not like) and satisfies the condition above, so it is a minimizer.
The equilibrium prices of a linear Fisher market are unique (Eisenberg and Gale). So all minimizers of have the same prices and the same value .
Claim 2 (one round is a mirror step). If , the bids of line L6 are in , and is the unique minimizer over of , where . For every ,
Proof. With , line L4 gives on , so , and line L6 gives on with . So . splits into one strictly convex function per buyer on her simplex of total . Its minimizer satisfies for a constant per buyer, so . Since , this is proportional to , and after scaling to the total it is . So for a constant per buyer. For ,
because removes the constants .
Claim 3 (relative smoothness). For and ,
Proof. The terms with are linear and cancel in . Since , what remains is, with and ,
because . By the log sum inequality, for each good, with and . Summing over goods gives .
Claim 4 (one-step inequality). If and is the next bid matrix, then for every ,
Proof. By Claim 3 with , . Write and use Claim 2; the terms cancel.
Claim 5 (monotonicity and rate). Let , for example the even split of line L1, and let be the bids after rounds. Then , and for every minimizer of , and
Proof. By Claim 2, all are in . Claim 4 with gives . Claim 4 with and the convexity bound give
The left side is at least , so the KL divergence does not go up. Summing over , the right side telescopes to at most , and since does not go up, .
Claim 6 (convergence). The prices converge to the equilibrium prices , and the bids converge to equilibrium bids ; so the allocations of line L4 converge to an equilibrium allocation.
Proof. The bids lie in the compact set , and by Claim 5. Let be a limit point, . By continuity , so is a minimizer and, by Claim 1 and the uniqueness of the prices, . Since every limit point of has the prices and is continuous, .
For the bids, : the terms with are , and the others are continuous at since . By Claim 5 with , does not go up, so it tends to . On each buyer's row, both bid vectors have the total , and Pinsker's inequality gives , so . Then , an equilibrium allocation by Claim 1.
Claim 7 (the check value). For , and budgets , starting from the even split, the prices are in every round and .
Proof. By symmetry of the market and of the start, and , so both prices are and . Buyer 1 has , so . With the formula holds at , and if , then .
The implementation runs in floating point, so the tests compare the inequalities of Claim 5 with a small slack.
Complexity
One round of lines L3 to L6 takes time and space, so rounds take time; only the pairs with matter, so a sparse market costs time linear in the number of such pairs. The number of rounds for a gap of in is at most . From the even split of line L1, . The bound is on the potential, not on the distance to the equilibrium prices, and the prices can approach slowly when a buyer is indifferent at the equilibrium between a good she buys and one she must not buy.
Properties
- Distributed. Each buyer needs only her own utilities and what she received in the last round. Each good needs only the bids on it.
- No step size and no state. The next bids depend only on the current bids, and the step of the mirror descent is fixed at .
- Market clearing in every round. Every good is sold at the sum of its bids, and every buyer spends her whole budget.
- Monotone potential. never goes up, and neither does for any equilibrium bids , which works as a Lyapunov function.
- Rate for linear utilities. In the market , with budgets , the equilibrium prices are and buyer 1 is indifferent between the goods there. The price of good 1 is about after 100 rounds and after 1000 rounds, so the error falls only roughly like .
Variants and improvements
- CES utilities. Zhang proved convergence in Fisher markets with constant elasticity of substitution utilities, with a fast rate for strictly concave ones.
- Spending constraint utilities. Birnbaum, Devanur and Xiao extended both the convex program and the dynamics to spending constraint utilities.
- Exchange markets. The original setting of Wu and Zhang is an exchange of bandwidth between peers, where every agent also sells; proportional response is a tit-for-tat rule there.
- Exact methods. The DPSV algorithm and Orlin's algorithm compute the equilibrium exactly, and the Eisenberg-Gale program gives it as a convex program in the allocation.
- Price dynamics. Tatonnement moves prices by excess demand instead of moving bids; for linear utilities the demand is not unique, which makes it harder to analyze.
When to use it
Use it when the buyers are automated agents that update their own bids, such as budgets in ad auctions or bandwidth in a peer-to-peer network, and no central party can solve the market. It is also a very short way to get approximate equilibrium prices of a large linear Fisher market. When exact prices are needed, use an exact combinatorial algorithm or round the result of the dynamics and check it.
Pitfalls
- Starting line L1 with a zero bid on a good that the buyer likes is a trap: line L6 keeps the bid at zero forever, so the dynamics can converge to the wrong point when the equilibrium needs that bid.
- Dividing by in line L4 for a good that no buyer bids on fails; with positive starting bids on every liked good this cannot happen, because every good is liked by some buyer.
- Dividing in line L6 by anything other than the utility of line L5 for the same allocation, for example by a utility from an older round, breaks the property that the bids of each buyer add up to her budget.
- Stopping when the prices of line L3 look right is wrong: in the example the prices are exactly the equilibrium prices in round 1, but the bids are not.
- Choosing the number of rounds of line L2 as if the rate were geometric gives too few rounds for linear utilities: when a buyer is indifferent at the equilibrium, the error falls roughly like .
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
# Part of https://algorithm.tamnd.com/proportional-response-dynamics/. The authors are listed in prov/M8R35N.jsonl.
"""Proportional response dynamics for a linear Fisher market, in floating point.
Buyers are 0, ..., n - 1 and goods are 0, ..., m - 1, with one unit of each good. u[i][j] >= 0 is
the utility of buyer i for all of good j and e[i] > 0 is her budget. Every buyer likes some good
and every good is liked by some buyer. In each round, every buyer splits her budget over the goods
in proportion to the utility that each good gave her in the last round. The price of a good is
the total money bid on it, and each buyer gets a share of the good equal to her share of the bids.
"""
import math
def round_once(u, e, b):
"""One round of the dynamics: return the prices of the bids b and the next bids."""
n, m = len(u), len(u[0])
p = [sum(b[i][j] for i in range(n)) for j in range(m)] # @line L3
x = [[b[i][j] / p[j] if b[i][j] > 0 else 0.0 for j in range(m)] for i in range(n)] # @line L4
v = [sum(u[i][j] * x[i][j] for j in range(m)) for i in range(n)] # @line L5
nb = [[e[i] * u[i][j] * x[i][j] / v[i] for j in range(m)] for i in range(n)] # @line L6
return p, nb
def proportional_response(u, e, rounds, b0=None):
"""Run the given number of rounds. Return the list of bid matrices b^0, ..., b^rounds."""
n, m = len(u), len(u[0])
if b0 is None: # @line L1
b0 = []
for i in range(n):
liked = [j for j in range(m) if u[i][j] > 0]
b0.append([e[i] / len(liked) if u[i][j] > 0 else 0.0 for j in range(m)])
history = [b0]
b = b0
for _ in range(rounds): # @line L2
_, b = round_once(u, e, b)
history.append(b)
return history # @line L7
def prices(b):
"""The price of each good: the total money bid on it."""
return [sum(row[j] for row in b) for j in range(len(b[0]))]
def shmyrev(u, b):
"""The convex potential of Shmyrev: sum_j p_j log p_j - sum_ij b_ij log u_ij. Proportional
response is mirror descent on it, so it never goes up."""
p = prices(b)
value = sum(q * math.log(q) for q in p if q > 0)
value -= sum(b[i][j] * math.log(u[i][j]) for i in range(len(b)) for j in range(len(b[0])) if b[i][j] > 0)
return value
def kl(a, b):
"""Kullback-Leibler divergence of two bid matrices with the same row sums."""
return sum(a[i][j] * math.log(a[i][j] / b[i][j])
for i in range(len(a)) for j in range(len(a[0])) if a[i][j] > 0)
test_proportional_response_dynamics.py 169 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/proportional-response-dynamics/. The authors are listed in prov/M8R35N.jsonl.
import random
import unittest
from fractions import Fraction
from itertools import combinations
from proportional_response_dynamics import kl, prices, proportional_response, shmyrev
TOL = 1e-9 # slack for floating point rounding in the exact inequalities
def equilibrium_spending(u, e):
"""An exact equilibrium of the market, as money spent b[i][j], found by trying every forest of
spending edges. The forest fixes the prices: equal bang per buck along each buyer's edges, and
on each connected part the prices add up to the budgets."""
n, m = len(u), len(u[0])
all_edges = [(i, j) for i in range(n) for j in range(m) if u[i][j] > 0]
for k in range(1, min(len(all_edges), n + m - 1) + 1):
for H in combinations(all_edges, k):
p = forest_prices(u, e, H)
if p is None:
continue
b = forest_flow(n, m, e, p, H)
if b is not None and is_equilibrium(u, e, p, b):
return p, b
raise AssertionError("no equilibrium found")
def forest_prices(u, e, H):
n, m = len(u), len(u[0])
nbr = {}
for i, j in H:
nbr.setdefault(("b", i), []).append(("g", j))
nbr.setdefault(("g", j), []).append(("b", i))
if len(nbr) != n + m:
return None
rel, p = {}, [None] * m
for j0 in range(m):
if ("g", j0) in rel:
continue
rel[("g", j0)] = Fraction(1)
comp, stack = [("g", j0)], [("g", j0)]
while stack:
a = stack.pop()
for c in nbr[a]:
i, j = (a[1], c[1]) if a[0] == "b" else (c[1], a[1])
val = Fraction(u[i][j]) / rel[a]
if c not in rel:
rel[c] = val
comp.append(c)
stack.append(c)
elif rel[c] != val:
return None
money = sum(e[a[1]] for a in comp if a[0] == "b")
scale = money / sum(rel[a] for a in comp if a[0] == "g")
for a in comp:
if a[0] == "g":
p[a[1]] = rel[a] * scale
return p
def forest_flow(n, m, e, p, H):
left = set(H)
need = {("b", i): Fraction(e[i]) for i in range(n)}
need.update({("g", j): p[j] for j in range(m)})
b = [[Fraction(0)] * m for _ in range(n)]
while left:
deg = {}
for i, j in left:
deg[("b", i)] = deg.get(("b", i), 0) + 1
deg[("g", j)] = deg.get(("g", j), 0) + 1
leaf = next((v for v, d in deg.items() if d == 1), None)
if leaf is None:
return None
i, j = next(ed for ed in left if ("b", ed[0]) == leaf or ("g", ed[1]) == leaf)
amount = need[leaf]
if amount < 0:
return None
b[i][j] = amount
need[("b", i)] -= amount
need[("g", j)] -= amount
left.discard((i, j))
return b if all(v == 0 for v in need.values()) else None
def is_equilibrium(u, e, p, b):
n, m = len(u), len(u[0])
for i in range(n):
best = max(Fraction(u[i][j]) / p[j] for j in range(m))
if sum(b[i]) != e[i]:
return False
if any(b[i][j] > 0 and Fraction(u[i][j]) / p[j] != best for j in range(m)):
return False
return all(sum(b[i][j] for i in range(n)) == p[j] for j in range(m))
def random_market(rng, n, m):
while True:
u = [[rng.choice([0, 1, 2, 3, 4]) for _ in range(m)] for _ in range(n)]
if all(any(r) for r in u) and all(any(u[i][j] for i in range(n)) for j in range(m)):
return u, [rng.randint(1, 3) for _ in range(n)]
class TestProportionalResponse(unittest.TestCase):
def test_check_value(self):
history = proportional_response([[2, 1], [1, 2]], [1, 1], 60)
for t, b in enumerate(history[:20]):
# From an even split, buyer 1 bids 2^t / (2^t + 1) on good 1 in round t.
self.assertAlmostEqual(b[0][0], 2 ** t / (2 ** t + 1), delta=1e-12)
self.assertAlmostEqual(prices(b)[0], 1.0, delta=1e-12)
self.assertAlmostEqual(history[-1][0][0], 1.0, delta=1e-12)
def test_example(self):
# The example of the page: the equilibrium prices are (1, 2).
history = proportional_response([[1, 1], [1, 3]], [1, 2], 50)
expected = {0: (1.5, 1.5), 1: (1.0, 2.0), 2: (34 / 33, 65 / 33)}
for t, (p1, p2) in expected.items():
self.assertAlmostEqual(prices(history[t])[0], p1, delta=1e-12)
self.assertAlmostEqual(prices(history[t])[1], p2, delta=1e-12)
self.assertAlmostEqual(history[2][0][0], 2 / 3, delta=1e-12)
self.assertAlmostEqual(history[2][1][1], 18 / 11, delta=1e-12)
p = prices(history[-1])
self.assertAlmostEqual(p[0], 1.0, delta=1e-4)
self.assertAlmostEqual(p[1], 2.0, delta=1e-4)
def test_degenerate_market_is_slow(self):
# At the prices (2, 1), buyer 1 is indifferent between the goods but must not buy good 2.
history = proportional_response([[2, 1], [1, 2]], [2, 1], 1000)
p = prices(history[-1])
self.assertGreater(abs(p[0] - 2.0), 1e-4)
self.assertLess(abs(p[0] - 2.0), 1e-2)
def test_budgets_and_bound(self):
rng = random.Random(1)
for _ in range(25):
n, m = rng.randint(1, 3), rng.randint(1, 3)
u, e = random_market(rng, n, m)
p_star, b_star = equilibrium_spending(u, e)
b_star = [[float(v) for v in row] for row in b_star]
phi_star = shmyrev(u, b_star)
history = proportional_response(u, [float(v) for v in e], 300)
start = kl(b_star, history[0])
last = None
for t, b in enumerate(history):
for i in range(n):
self.assertAlmostEqual(sum(b[i]), e[i], delta=1e-9)
phi = shmyrev(u, b)
self.assertGreaterEqual(phi, phi_star - TOL)
if last is not None:
self.assertLessEqual(phi, last + TOL)
if t > 0:
self.assertLessEqual(phi - phi_star, start / t + TOL)
last = phi
def test_prices_converge(self):
rng = random.Random(2)
for _ in range(6):
u, e = random_market(rng, 3, 3)
p_star, _ = equilibrium_spending(u, e)
history = proportional_response(u, [float(v) for v in e], 1500)
p = prices(history[-1])
for j in range(3):
self.assertAlmostEqual(p[j], float(p_star[j]), delta=2e-2)
if __name__ == "__main__":
unittest.main()
History
Wu and Zhang introduced proportional response in 2007 to model the tit-for-tat rule of peer-to-peer file sharing, where peers trade upload bandwidth, and proved that it converges to the market equilibrium of that exchange. Zhang then studied the dynamics in the Fisher market. Shmyrev found in 2009 a convex program for the linear Fisher market in terms of the bids, related to the dual of the Eisenberg-Gale program. Birnbaum, Devanur and Xiao rediscovered it in 2011, showed that proportional response is generalized gradient descent on it with the KL divergence, and proved the bound of .
References
- Fang Wu and Li Zhang, Proportional response dynamics leads to market equilibrium, STOC 2007, 354-363, the whole paper (the dynamics and its convergence in an exchange model of bandwidth trading)
- Li Zhang, Proportional response dynamics in the Fisher market, Theoretical Computer Science 412(24), 2691-2698 (2011), the whole paper (convergence in Fisher markets with CES utilities)
- Benjamin Birnbaum, Nikhil R. Devanur and Lin Xiao, Distributed algorithms via gradient descent for Fisher markets, EC 2011, 127-136, Section 2.1 (Shmyrev's convex program, Theorem 1), Section 2.2 and Theorem 3 (the rate of generalized gradient descent), Theorem 6 and Lemma 7 (proportional response is gradient descent with the KL divergence)
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 M8R35N Edit this page History Report an error Markdown