Algorithm Search⌘K

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
Properties
deterministiciterative
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 KL(b∗∥b0)/T\mathrm{KL}(b^* \| b^0) / T after TT 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 nn buyers and mm goods, with one unit of each good. Buyer ii has a budget ei>0e_i > 0 and utility uij≥0u_{ij} \ge 0 for all of good jj, linear in the amount. Every buyer likes some good and every good is liked by some buyer. A bid matrix bb has bij≥0b_{ij} \ge 0, bij=0b_{ij} = 0 when uij=0u_{ij} = 0, and ∑jbij=ei\sum_j b_{ij} = e_i for each buyer. Find bids whose prices pj=∑ibijp_j = \sum_i b_{ij} are the equilibrium prices: with the allocation xij=bij/pjx_{ij} = b_{ij} / p_j, every buyer spends only on goods of maximum bang per buck uij/pju_{ij} / p_j.

The algorithm

  1. PROPORTIONAL-RESPONSE(utilities u, budgets e, rounds T)
  2. 1b_ij ← e_i / (the number of goods that i likes) for every good j with u_ij > 0, else 0
  3. 2for t ← 1 to T do
  4. 3p_j ← Σ_i b_ij for every good j
  5. 4x_ij ← b_ij / p_j for every buyer i and good j
  6. 5v_i ← Σ_j u_ij x_ij for every buyer i
  7. 6b_ij ← e_i u_ij x_ij / v_i for every buyer i and good j
  8. 7return 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 uijxiju_{ij} x_{ij} of that utility. The new bids again add up to eie_i. 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

Φ(b)=∑jpjlog⁡pj−∑i,jbijlog⁡uij,pj=∑ibij,\Phi(b) = \sum_j p_j \log p_j - \sum_{i, j} b_{ij} \log u_{ij}, \qquad p_j = \sum_i b_{ij},

where the second sum is over the pairs with uij>0u_{ij} > 0. It is convex, and its minimizers are exactly the equilibrium bids. Its gradient is ∂Φ/∂bij=log⁡pj+1−log⁡uij\partial \Phi / \partial b_{ij} = \log p_j + 1 - \log u_{ij}, and line L6 equals bijt+1∝bijtexp⁡(−∂Φ/∂bij)b^{t+1}_{ij} \propto b^t_{ij} \exp(-\partial \Phi / \partial b_{ij}), scaled to the budget of buyer ii. This is mirror descent with step 11 and the KL divergence, which is the multiplicative weights form of gradient descent.

Example

Two buyers and two goods, u1=(1,1)u_1 = (1, 1), u2=(1,3)u_2 = (1, 3), budgets e=(1,2)e = (1, 2). At the equilibrium the prices are (1,2)(1, 2): buyer 1 has bang per buck (1,1/2)(1, 1/2) and spends her 11 on good 1, and buyer 2 has bang per buck (1,3/2)(1, 3/2) and spends her 22 on good 2. The minimum of Φ\Phi is 2log⁡2−2log⁡3≈−0.81092 \log 2 - 2 \log 3 \approx -0.8109.

round tt prices pp bids of buyer 1 bids of buyer 2 Φ(bt)\Phi(b^t)
0 (1.5,1.5)(1.5, 1.5) (0.5,0.5)(0.5, 0.5) (1,1)(1, 1) 0.11780.1178
1 (1,2)(1, 2) (0.5,0.5)(0.5, 0.5) (0.5,1.5)(0.5, 1.5) −0.2616-0.2616
2 (1.0303,1.9697)(1.0303, 1.9697) (0.6667,0.3333)(0.6667, 0.3333) (0.3636,1.6364)(0.3636, 1.6364) −0.4318-0.4318
3 (1.0408,1.9592)(1.0408, 1.9592) (0.7927,0.2073)(0.7927, 0.2073) (0.2481,1.7519)(0.2481, 1.7519) −0.5654-0.5654
5 (1.0368,1.9632)(1.0368, 1.9632) (0.9312,0.0688)(0.9312, 0.0688) (0.1056,1.8944)(0.1056, 1.8944) −0.7195-0.7195
10 (1.0094,1.9906)(1.0094, 1.9906) (0.9972,0.0028)(0.9972, 0.0028) (0.0122,1.9878)(0.0122, 1.9878) −0.8040-0.8040
20 (1.0002,1.9998)(1.0002, 1.9998) (1.0000,0.0000)(1.0000, 0.0000) (0.0002,1.9998)(0.0002, 1.9998) −0.8109-0.8109

In round 0, buyer 1 gets 1/31/3 of each good and utility 2/32/3, half of it from each good, so she keeps her split. Buyer 2 gets 2/32/3 of each good, with utility 2/32/3 from good 1 and 22 from good 2, so she moves to the split (0.5,1.5)(0.5, 1.5). In round 1 the prices are already (1,2)(1, 2), 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. Φ\Phi goes down in every round.

For the market u1=(2,1)u_1 = (2, 1), u2=(1,2)u_2 = (1, 2) with budgets (1,1)(1, 1), the prices stay at (1,1)(1, 1) and buyer 1 bids exactly 2t/(2t+1)2^t / (2^t + 1) on good 1 in round tt.

Correctness

The proof is in proofs/correctness.md. The minimizers of Φ\Phi over the bid matrices are the equilibrium bids, by the optimality conditions. Line L6 is the mirror descent step, and Φ\Phi is smooth relative to the KL divergence with constant 11: the gap Φ(a)−Φ(b)−∇Φ(b)⋅(a−b)\Phi(a) - \Phi(b) - \nabla \Phi(b) \cdot (a - b) 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 Φ\Phi never goes up, that KL(b∗∥bt)\mathrm{KL}(b^* \| b^t) never goes up, and that Φ(bT)−Φ(b∗)≤KL(b∗∥b0)/T\Phi(b^T) - \Phi(b^*) \le \mathrm{KL}(b^* \| b^0) / T. 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 nn buyers with budgets ei>0e_i > 0, mm goods with one unit each, and utilities uij≥0u_{ij} \ge 0, where every buyer likes some good and every good is liked by some buyer. Let E={(i,j):uij>0}E = \{(i, j) : u_{ij} > 0\}. The bid set is

S={b≥0 on E:∑jbij=ei for every buyer},S = \{b \ge 0 \text{ on } E : \textstyle\sum_j b_{ij} = e_i \text{ for every buyer}\},

with bij=0b_{ij} = 0 off EE. For b∈Sb \in S write pj(b)=∑ibijp_j(b) = \sum_i b_{ij}, and let

Φ(b)=∑jpjlog⁡pj−∑(i,j)∈Ebijlog⁡uij,KL(a∥b)=∑(i,j)∈Eaijlog⁡aijbij,\Phi(b) = \sum_j p_j \log p_j - \sum_{(i, j) \in E} b_{ij} \log u_{ij}, \qquad \mathrm{KL}(a \| b) = \sum_{(i, j) \in E} a_{ij} \log \frac{a_{ij}}{b_{ij}},

with 0log⁡0=00 \log 0 = 0. Let S+S^+ be the bids in SS that are positive on all of EE. On S+S^+ every price is positive, because every good is liked by some buyer, and Φ\Phi is differentiable with gij=∂Φ/∂bij=log⁡pj+1−log⁡uijg_{ij} = \partial \Phi / \partial b_{ij} = \log p_j + 1 - \log u_{ij}. The algorithm always terminates, since it runs TT rounds of finite work; the claims below are about the quality of the bids.

Claim 1 (Shmyrev). Φ\Phi is convex and continuous on SS and has a minimum there. A bid matrix b∈Sb \in S minimizes Φ\Phi if and only if the prices p=p(b)p = p(b) and the allocation xij=bij/pjx_{ij} = b_{ij} / p_j form a Fisher market equilibrium.

Proof. The function tlog⁡tt \log t is convex and continuous on [0,∞)[0, \infty), pjp_j is linear in bb, and the second sum is linear, so Φ\Phi is convex and continuous on the compact set SS and has a minimum.

Let bb be a minimizer. Suppose some good jj has pj=0p_j = 0, and let ii like jj. Move ε\varepsilon from a positive bid bikb_{ik} of buyer ii to bijb_{ij}. The term pjlog⁡pjp_j \log p_j changes by εlog⁡ε\varepsilon \log \varepsilon, and all other terms change by O(ε)O(\varepsilon), so for small ε\varepsilon the potential goes down, which is impossible. So all prices are positive, Φ\Phi is differentiable near bb in SS, and the constraints are linear, so bb minimizes Φ\Phi if and only if for each buyer ii there is λi\lambda_i with gij≥λig_{ij} \ge \lambda_i for all (i,j)∈E(i, j) \in E, with equality when bij>0b_{ij} > 0. Since gij=log⁡(pj/uij)+1g_{ij} = \log(p_j / u_{ij}) + 1, this says that uij/pj≤e1−λiu_{ij} / p_j \le e^{1 - \lambda_i} for all liked goods, with equality where buyer ii bids. So the condition says exactly that each buyer bids only on goods of maximum bang per buck.

If this holds, then with xij=bij/pjx_{ij} = b_{ij} / p_j every good is fully allocated (∑ixij=1\sum_i x_{ij} = 1), every buyer spends ∑jpjxij=ei\sum_j p_j x_{ij} = e_i, 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 00 would have unbounded demand), the money bij=pjxijb_{ij} = p_j x_{ij} lies in SS (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. □\square

The equilibrium prices of a linear Fisher market are unique (Eisenberg and Gale). So all minimizers of Φ\Phi have the same prices p∗p^* and the same value Φ∗\Phi^*.

Claim 2 (one round is a mirror step). If b∈S+b \in S^+, the bids b′b' of line L6 are in S+S^+, and b′b' is the unique minimizer over SS of Ψ(y)=g⋅y+KL(y∥b)\Psi(y) = g \cdot y + \mathrm{KL}(y \| b), where g=∇Φ(b)g = \nabla \Phi(b). For every z∈Sz \in S,

g⋅(b′−z)=KL(z∥b)−KL(z∥b′)−KL(b′∥b).g \cdot (b' - z) = \mathrm{KL}(z \| b) - \mathrm{KL}(z \| b') - \mathrm{KL}(b' \| b).

Proof. With pj>0p_j > 0, line L4 gives xij=bij/pj>0x_{ij} = b_{ij} / p_j > 0 on EE, so vi>0v_i > 0, and line L6 gives bij′=eiuijxij/vi>0b'_{ij} = e_i u_{ij} x_{ij} / v_i > 0 on EE with ∑jbij′=ei\sum_j b'_{ij} = e_i. So b′∈S+b' \in S^+. Ψ\Psi splits into one strictly convex function per buyer on her simplex of total eie_i. Its minimizer satisfies gij+log⁡(yij/bij)+1=μig_{ij} + \log(y_{ij} / b_{ij}) + 1 = \mu_i for a constant μi\mu_i per buyer, so yij∝bijexp⁡(−gij)y_{ij} \propto b_{ij} \exp(-g_{ij}). Since exp⁡(−gij)=exp⁡(−1) uij/pj\exp(-g_{ij}) = \exp(-1) \, u_{ij} / p_j, this is proportional to uijbij/pj=uijxiju_{ij} b_{ij} / p_j = u_{ij} x_{ij}, and after scaling to the total eie_i it is bij′b'_{ij}. So log⁡(bij′/bij)=ci−gij\log(b'_{ij} / b_{ij}) = c_i - g_{ij} for a constant cic_i per buyer. For z∈Sz \in S,

KL(z∥b)−KL(z∥b′)−KL(b′∥b)=∑(i,j)∈E(zij−bij′)log⁡bij′bij=∑(i,j)∈E(zij−bij′)(ci−gij)=g⋅(b′−z),\mathrm{KL}(z \| b) - \mathrm{KL}(z \| b') - \mathrm{KL}(b' \| b) = \sum_{(i, j) \in E} (z_{ij} - b'_{ij}) \log \frac{b'_{ij}}{b_{ij}} = \sum_{(i, j) \in E} (z_{ij} - b'_{ij}) (c_i - g_{ij}) = g \cdot (b' - z),

because ∑j(zij−bij′)=ei−ei=0\sum_j (z_{ij} - b'_{ij}) = e_i - e_i = 0 removes the constants cic_i. □\square

Claim 3 (relative smoothness). For a∈Sa \in S and b∈S+b \in S^+,

Φ(a)≤Φ(b)+∇Φ(b)⋅(a−b)+KL(a∥b).\Phi(a) \le \Phi(b) + \nabla \Phi(b) \cdot (a - b) + \mathrm{KL}(a \| b).

Proof. The terms with log⁡uij\log u_{ij} are linear and cancel in Φ(a)−Φ(b)−∇Φ(b)⋅(a−b)\Phi(a) - \Phi(b) - \nabla \Phi(b) \cdot (a - b). Since ∑i(aij−bij)=pj(a)−pj(b)\sum_i (a_{ij} - b_{ij}) = p_j(a) - p_j(b), what remains is, with Pj=pj(a)P_j = p_j(a) and Qj=pj(b)Q_j = p_j(b),

∑j(Pjlog⁡Pj−Qjlog⁡Qj−(log⁡Qj+1)(Pj−Qj))=∑j(Pjlog⁡PjQj−Pj+Qj)=∑jPjlog⁡PjQj,\sum_j \big(P_j \log P_j - Q_j \log Q_j - (\log Q_j + 1)(P_j - Q_j)\big) = \sum_j \Big(P_j \log \frac{P_j}{Q_j} - P_j + Q_j\Big) = \sum_j P_j \log \frac{P_j}{Q_j},

because ∑jPj=∑iei=∑jQj\sum_j P_j = \sum_i e_i = \sum_j Q_j. By the log sum inequality, Pjlog⁡(Pj/Qj)≤∑iaijlog⁡(aij/bij)P_j \log (P_j / Q_j) \le \sum_i a_{ij} \log (a_{ij} / b_{ij}) for each good, with Pj=∑iaijP_j = \sum_i a_{ij} and Qj=∑ibijQ_j = \sum_i b_{ij}. Summing over goods gives KL(a∥b)\mathrm{KL}(a \| b). □\square

Claim 4 (one-step inequality). If b∈S+b \in S^+ and b′b' is the next bid matrix, then for every z∈Sz \in S,

Φ(b′)≤Φ(b)+∇Φ(b)⋅(z−b)+KL(z∥b)−KL(z∥b′).\Phi(b') \le \Phi(b) + \nabla \Phi(b) \cdot (z - b) + \mathrm{KL}(z \| b) - \mathrm{KL}(z \| b').

Proof. By Claim 3 with a=b′a = b', Φ(b′)≤Φ(b)+g⋅(b′−b)+KL(b′∥b)\Phi(b') \le \Phi(b) + g \cdot (b' - b) + \mathrm{KL}(b' \| b). Write g⋅(b′−b)=g⋅(z−b)+g⋅(b′−z)g \cdot (b' - b) = g \cdot (z - b) + g \cdot (b' - z) and use Claim 2; the terms KL(b′∥b)\mathrm{KL}(b' \| b) cancel. □\square

Claim 5 (monotonicity and rate). Let b0∈S+b^0 \in S^+, for example the even split of line L1, and let btb^t be the bids after tt rounds. Then Φ(bt+1)≤Φ(bt)\Phi(b^{t+1}) \le \Phi(b^t), and for every minimizer b∗b^* of Φ\Phi, KL(b∗∥bt+1)≤KL(b∗∥bt)\mathrm{KL}(b^* \| b^{t+1}) \le \mathrm{KL}(b^* \| b^t) and

Φ(bT)−Φ∗≤KL(b∗∥b0)Tfor T≥1.\Phi(b^T) - \Phi^* \le \frac{\mathrm{KL}(b^* \| b^0)}{T} \quad \text{for } T \ge 1 .

Proof. By Claim 2, all btb^t are in S+S^+. Claim 4 with z=btz = b^t gives Φ(bt+1)≤Φ(bt)−KL(bt∥bt+1)≤Φ(bt)\Phi(b^{t+1}) \le \Phi(b^t) - \mathrm{KL}(b^t \| b^{t+1}) \le \Phi(b^t). Claim 4 with z=b∗z = b^* and the convexity bound Φ(bt)+∇Φ(bt)⋅(b∗−bt)≤Φ∗\Phi(b^t) + \nabla \Phi(b^t) \cdot (b^* - b^t) \le \Phi^* give

Φ(bt+1)−Φ∗≤KL(b∗∥bt)−KL(b∗∥bt+1).\Phi(b^{t+1}) - \Phi^* \le \mathrm{KL}(b^* \| b^t) - \mathrm{KL}(b^* \| b^{t+1}).

The left side is at least 00, so the KL divergence does not go up. Summing over t=0,…,T−1t = 0, \ldots, T - 1, the right side telescopes to at most KL(b∗∥b0)\mathrm{KL}(b^* \| b^0), and since Φ(bt)\Phi(b^t) does not go up, T(Φ(bT)−Φ∗)≤∑t=1T(Φ(bt)−Φ∗)≤KL(b∗∥b0)T (\Phi(b^T) - \Phi^*) \le \sum_{t=1}^{T} (\Phi(b^t) - \Phi^*) \le \mathrm{KL}(b^* \| b^0). □\square

Claim 6 (convergence). The prices p(bt)p(b^t) converge to the equilibrium prices p∗p^*, and the bids btb^t converge to equilibrium bids bˉ\bar{b}; so the allocations xtx^t of line L4 converge to an equilibrium allocation.

Proof. The bids lie in the compact set SS, and Φ(bt)→Φ∗\Phi(b^t) \to \Phi^* by Claim 5. Let bˉ\bar{b} be a limit point, btk→bˉb^{t_k} \to \bar{b}. By continuity Φ(bˉ)=Φ∗\Phi(\bar{b}) = \Phi^*, so bˉ\bar{b} is a minimizer and, by Claim 1 and the uniqueness of the prices, p(bˉ)=p∗p(\bar{b}) = p^*. Since every limit point of btb^t has the prices p∗p^* and pp is continuous, p(bt)→p∗p(b^t) \to p^*.

For the bids, KL(bˉ∥btk)→0\mathrm{KL}(\bar{b} \| b^{t_k}) \to 0: the terms with bˉij=0\bar{b}_{ij} = 0 are 00, and the others are continuous at bˉ\bar{b} since bˉij>0\bar{b}_{ij} > 0. By Claim 5 with b∗=bˉb^* = \bar{b}, KL(bˉ∥bt)\mathrm{KL}(\bar{b} \| b^t) does not go up, so it tends to 00. On each buyer's row, both bid vectors have the total eie_i, and Pinsker's inequality gives ∥bˉi−bit∥12≤2ei KL(bˉi∥bit)\|\bar{b}_i - b^t_i\|_1^2 \le 2 e_i \, \mathrm{KL}(\bar{b}_i \| b^t_i), so bt→bˉb^t \to \bar{b}. Then xijt=bijt/pj(bt)→bˉij/pj∗x^t_{ij} = b^t_{ij} / p_j(b^t) \to \bar{b}_{ij} / p^*_j, an equilibrium allocation by Claim 1. □\square

Claim 7 (the check value). For u1=(2,1)u_1 = (2, 1), u2=(1,2)u_2 = (1, 2) and budgets (1,1)(1, 1), starting from the even split, the prices are (1,1)(1, 1) in every round and b11t=2t/(2t+1)b^t_{11} = 2^t / (2^t + 1).

Proof. By symmetry of the market and of the start, b11t=b22t=atb^t_{11} = b^t_{22} = a_t and b12t=b21t=1−atb^t_{12} = b^t_{21} = 1 - a_t, so both prices are at+(1−at)=1a_t + (1 - a_t) = 1 and xt=btx^t = b^t. Buyer 1 has v1=2at+(1−at)=1+atv_1 = 2 a_t + (1 - a_t) = 1 + a_t, so at+1=2at/(1+at)a_{t+1} = 2 a_t / (1 + a_t). With a0=1/2a_0 = 1/2 the formula holds at t=0t = 0, and if at=2t/(2t+1)a_t = 2^t / (2^t + 1), then at+1=(2t+1/(2t+1))/((2t+1+1)/(2t+1))=2t+1/(2t+1+1)a_{t+1} = (2^{t+1} / (2^t + 1)) / ((2^{t+1} + 1) / (2^t + 1)) = 2^{t+1} / (2^{t+1} + 1). ■\blacksquare

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 O(nm)O(nm) time and O(nm)O(nm) space, so TT rounds take O(Tnm)O(Tnm) time; only the pairs with uij>0u_{ij} > 0 matter, so a sparse market costs time linear in the number of such pairs. The number of rounds for a gap of ε\varepsilon in Φ\Phi is at most KL(b∗∥b0)/ε\mathrm{KL}(b^* \| b^0) / \varepsilon. From the even split of line L1, KL(b∗∥b0)≤∑ieilog⁡m\mathrm{KL}(b^* \| b^0) \le \sum_i e_i \log m. 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 11.
  • Market clearing in every round. Every good is sold at the sum of its bids, and every buyer spends her whole budget.
  • Monotone potential. Φ(bt)\Phi(b^t) never goes up, and neither does KL(b∗∥bt)\mathrm{KL}(b^* \| b^t) for any equilibrium bids b∗b^*, which works as a Lyapunov function.
  • Rate 1/T1/T for linear utilities. In the market u1=(2,1)u_1 = (2, 1), u2=(1,2)u_2 = (1, 2) with budgets (2,1)(2, 1), the equilibrium prices are (2,1)(2, 1) and buyer 1 is indifferent between the goods there. The price of good 1 is about 1.99321.9932 after 100 rounds and 1.99931.9993 after 1000 rounds, so the error falls only roughly like 1/T1/T.

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 pjp_j 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 viv_i 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 TT 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 1/T1/T.

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.

proportional_response_dynamics.pyI0RawGitHub
# 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 KL(b∗∥b0)/T\mathrm{KL}(b^* \| b^0) / T.

References

  1. 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)
  2. 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)
  3. 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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example