]> gitweb.michael.orlitzky.com - dunshire.git/blob - doc/README.rst
Switch to Mathjax for the docs and finish the "Background" section.
[dunshire.git] / doc / README.rst
1 Overview
2 --------
3
4 Dunshire is a `CVXOPT <http://cvxopt.org/>`_-based library for solving
5 linear (cone) games. The notion of a symmetric linear (cone) game was
6 introduced by Gowda and Ravindran [GowdaRav]_, and extended by
7 Orlitzky to asymmetric cones with two interior points.
8
9 The state-of-the-art is that only symmetric games can be solved
10 efficiently, and thus the linear games supported by Dunshire are a
11 bastard of the two: the cones are symmetric, but the players get to
12 choose two interior points.
13
14 In this game, we have two players who are competing for a "payoff."
15 There is a symmetric cone :math:`K`, a linear transformation :math:`L`
16 on the space in which :math:`K` lives, and two points :math:`e_{1}`
17 and :math:`e_{2}` in the interior of :math:`K`. The players make their
18 "moves" by choosing points from two strategy sets. Player one chooses
19 an :math:`\bar{x}` from
20
21 .. math::
22 \Delta_{1} =
23 \left\lbrace
24 x \in K\ \middle|\ \left\langle x,e_{2} \right\rangle = 1
25 \right\rbrace
26
27 and player two chooses a :math:`\bar{y}` from
28
29 .. math::
30 \Delta_{2} &=
31 \left\lbrace
32 y \in K\ \middle|\ \left\langle y,e_{1} \right\rangle = 1
33 \right\rbrace.
34
35 That ends the turn, and player one is paid :math:`\left\langle
36 L\left(\bar{x}\right),\bar{y}\right\rangle` out of player two's
37 pocket. As is usual to assume in game theory, we suppose that player
38 one wants to maximize his worst-case payoff, and that player two wants
39 to minimize his worst-case *payout*. In other words, player one wants
40 to solve the optimization problem,
41
42 .. math::
43 \text{find }
44 \underset{x \in \Delta_{1}}{\max}\
45 \underset{y\in \Delta_{2}}{\min}\
46 \left\langle L\left(x\right),y \right\rangle
47
48 while player two tries to (simultaneously) solve a similar problem,
49
50 .. math::
51 \text{find }
52 \underset{y\in \Delta_{2}}{\min}\
53 \underset{x \in \Delta_{1}}{\max}\
54 \left\langle L\left(x\right),y \right\rangle.
55
56 There is at least one pair :math:`\left(\bar{x},\bar{y}\right)` that
57 solves these problems optimally, and Dunshire can find it. The optimal
58 payoff, called *the value of the game*, is unique. At the moment, the
59 symmetric cone :math:`K` can be either the nonnegative orthant or the
60 Lorentz "ice cream" cone in :math:`\mathbb{R}^{n}`. Here are two of
61 the simplest possible examples, showing off the ability to solve a
62 game over both of those cones.
63
64 First, we use the nonnegative orthant in :math:`\mathbb{R}^{2}`:
65
66 .. doctest::
67
68 >>> from dunshire import *
69 >>> K = NonnegativeOrthant(2)
70 >>> L = [[1,0],[0,1]]
71 >>> e1 = [1,1]
72 >>> e2 = e1
73 >>> G = SymmetricLinearGame(L,K,e1,e2)
74 >>> print(G.solution())
75 Game value: 0.5000000
76 Player 1 optimal:
77 [0.5000000]
78 [0.5000000]
79 Player 2 optimal:
80 [0.5000000]
81 [0.5000000]
82
83 Next we try the Lorentz ice-cream cone in :math:`\mathbb{R}^{2}`:
84
85 .. doctest::
86
87 >>> from dunshire import *
88 >>> K = IceCream(2)
89 >>> L = [[1,0],[0,1]]
90 >>> e1 = [1,1]
91 >>> e2 = e1
92 >>> G = SymmetricLinearGame(L,K,e1,e2)
93 >>> print(G.solution())
94 Game value: 0.5000000
95 Player 1 optimal:
96 [0.8347039]
97 [0.1652961]
98 Player 2 optimal:
99 [0.5000000]
100 [0.5000000]
101
102 Note that these solutions are not unique, although the game values are.
103
104 Requirements
105 ------------
106
107 The only requirement is the CVXOPT library, available for most Linux
108 distributions. Dunshire is targeted at python-3.x, but python-2.x will
109 probably work too.
110
111 Background
112 ----------
113
114 A linear game is a generalization of a two-person zero-sum matrix game
115 [Karlin]_. Classically, such a game involves a matrix :math:`A \in
116 \mathbb{R}^{n \times n}` and a set (the unit simplex) of "strategies"
117 :math:`\Delta = \operatorname{conv}\left( \left\lbrace e_{1}, e_{2},
118 \ldots, e_{n} \right\} \right)` from which two players are free to
119 choose. If the players choose :math:`x,y \in \Delta` respectively,
120 then the game is played by evaluating :math:`y^{T}Ax` as the "payoff"
121 to the first player. His payoff comes from the second player, so that
122 their total sums to zero.
123
124 Each player will try to maximize his payoff in this scenario,
125 or—what is equivalent—try to minimize the payoff of his
126 opponent. In fact, the existence of optimal strategies is
127 guaranteed [Karlin]_ for both players. The *value* of the
128 matrix game :math:`A` is the payoff resulting from optimal play,
129
130 .. math::
131 v\left(A\right)
132 =
133 \underset{x \in \Delta}{\max}\
134 \underset{y\in \Delta}{\min}
135 \left( y^{T}Ax \right)
136 =
137 \underset{y \in \Delta}{\min}\
138 \underset{x \in \Delta}{\max}
139 \left( y^{T}Ax \right).
140
141 The payoff to the first player in this case is
142 :math:`v\left(A\right)`. Corresponding to :math:`v\left(A\right)` is an
143 optimal strategy pair :math:`\left(\xi, \gamma\right) \in \Delta
144 \times \Delta` such that
145
146 .. math::
147 \gamma^{T}Ax
148 \le
149 v\left(A\right)
150 =
151 \gamma^{T}A\xi
152 \le
153 y^{T}A\xi
154 \text{ for all } \left(x,y\right) \in \Delta \times \Delta.
155
156 The relationship between :math:`A`, :math:`\xi`, :math:`\gamma`,
157 and :math:`v\left(A\right)` has been studied extensively [Kaplansky]_
158 [Raghavan]_. Gowda and Ravindran [GowdaRav]_ were motivated by these
159 results to ask if the matrix :math:`A` can be replaced by a linear
160 transformation :math:`L`, and whether or not the unit simplex
161 :math:`\Delta` can be replaced by a more general set—a base of a
162 symmetric cone. In fact, one can go all the way to asymmetric (but
163 still proper) cones. But, since Dunshire can only handle the symmetric
164 case, we will pretend from now on that our cones need to be
165 symmetric. This simplifies some definitions.
166
167 What is a linear game?
168 ~~~~~~~~~~~~~~~~~~~~~~
169
170 In the classical setting, the interpretation of the strategies as
171 probabilities results in a strategy set :math:`\Delta \subseteq
172 \mathbb{R}^{n}_{+}` that is compact, convex, and does not contain the
173 origin. Moreover, any nonzero :math:`x \in \mathbb{R}^{n}_{+}` is a
174 unique positive multiple :math:`x = \lambda b` of some :math:`b \in
175 \Delta`. Several existence and uniqueness results are predicated on
176 those properties.
177
178 **Definition.** Suppose that :math:`K` is a cone and :math:`B
179 \subseteq K` does not contain the origin. If any nonzero :math:`x \in
180 K` can be uniquely represented :math:`x = \lambda b` where
181 :math:`\lambda > 0` and :math:`b \in B`, then :math:`B` is a *base*
182 of :math:`K`.
183
184 The set :math:`\Delta` is a compact convex base for the proper cone
185 :math:`\mathbb{R}^{n}_{+}`. Every :math:`x \in \Delta` also has
186 entries that sum to unity, which can be abbreviated by the condition
187 :math:`\left\langle x,\mathbf{1} \right\rangle = 1` where
188 :math:`\mathbf{1} = \left(1,1,\ldots,1\right)^{T}` happens to lie in
189 the interior of :math:`\mathbb{R}^{n}_{+}`. In fact, the two
190 conditions :math:`x \in \mathbb{R}^{n}_{+}` and :math:`\left\langle
191 x,\mathbf{1} \right\rangle = 1` define :math:`\Delta`. This is no
192 coincidence; whenever :math:`K` is a symmetric cone and :math:`e_{2}
193 \in \operatorname{int}\left(K\right)`, the set :math:`\left\lbrace x
194 \in K \ \middle|\ \left\langle x,e_{2} \right\rangle = 1
195 \right\rbrace` is a compact convex base of :math:`K`. This motivates a
196 generalization where :math:`\mathbb{R}^{n}_{+}` is replaced by a
197 symmetric cone.
198
199 **Definition.** Let :math:`V` be a finite-dimensional real Hilbert
200 space. A *linear game* in :math:`V` is a tuple
201 :math:`\left(L,K,e_{1},e_{2}\right)` where :math:`L : V \rightarrow V`
202 is linear, the set :math:`K` is a symmetric cone in :math:`V`, and the
203 points :math:`e_{1}` and :math:`e_{2}` belong to
204 :math:`\operatorname{int}\left(K\right)`.
205
206 **Definition.** The strategy sets for our linear game are
207
208 .. math::
209 \begin{aligned}
210 \Delta_{1}\left(L,K,e_{1},e_{2}\right) &=
211 \left\lbrace
212 x \in K\ \middle|\ \left\langle x,e_{2} \right\rangle = 1
213 \right\rbrace\\
214 \Delta_{2}\left(L,K,e_{1},e_{2}\right) &=
215 \left\lbrace
216 y \in K\ \middle|\ \left\langle y,e_{1} \right\rangle = 1
217 \right\rbrace.
218 \end{aligned}
219
220 Since :math:`e_{1},e_{2} \in \operatorname{int}\left(K\right)`, these
221 are bases for :math:`K`. We will usually omit the arguments and write
222 :math:`\Delta_{i}` to mean :math:`\Delta_{i}\left(L,K,e_{1},e_{2}\right)`.
223
224 To play the game :math:`\left(L,K,e_{1},e_{2}\right)`, the first
225 player chooses an :math:`x \in \Delta_{1}`, and the second player
226 independently chooses a :math:`y \in \Delta_{2}`. This completes the
227 turn, and the payoffs are determined by applying the payoff operator
228 :math:`\left(x,y\right) \mapsto \left\langle L\left(x\right), y
229 \right\rangle`. The payoff to the first player is :math:`\left\langle
230 L\left(x\right), y \right\rangle`, and since we want the game to be
231 zero-sum, the payoff to the second player is :math:`-\left\langle
232 L\left(x\right), y \right\rangle`.
233
234 The payoff operator is continuous in both arguments because it is
235 bilinear and the ambient space is finite-dimensional. We constructed
236 the strategy sets :math:`\Delta_{1}` and :math:`\Delta_{2}` to be
237 compact and convex; as a result, Karlin's [Karlin]_ general min-max
238 Theorem 1.5.1, guarantees the existence of optimal strategies for both
239 players.
240
241 **Definition.** A pair :math:`\left(\xi,\gamma\right) \in
242 \Delta_{1} \times \Delta_{2}` is an *optimal pair* for the game
243 :math:`\left(L,K,e_{1},e_{2}\right)` if it satisfies the *saddle-point
244 inequality*,
245
246 .. math::
247 \left\langle L\left(x\right),\gamma \right\rangle
248 \le
249 \left\langle L\left( \xi\right), \gamma \right\rangle
250 \le
251 \left\langle L\left(\xi\right),y \right\rangle
252 \text{ for all }
253 \left(x,y\right) \in \Delta_{1} \times \Delta_{2}.
254
255 At an optimal pair, neither player can unilaterally increase his
256 payoff by changing his strategy. The value :math:`\left\langle L
257 \left( \xi \right) , \gamma \right\rangle` is unique (by the same
258 min-max theorem); it is shared by all optimal pairs. There exists at
259 least one optimal pair :math:`\left(\xi,\gamma\right)` of the
260 game :math:`\left(L,K,e_{1},e_{2}\right)` and its *value* is
261 :math:`v\left(L,K,e_{1},e_{2}\right) = \left\langle
262 L\left(\xi\right), \gamma \right\rangle`.
263
264 Thanks to Karlin [Karlin]_, we have an equivalent characterization of
265 a game's value that does not require us to have a particular optimal
266 pair in mind,
267
268 .. math::
269 v\left( L,K,e_{1},e_{2} \right)
270 =
271 \underset{x \in \Delta_{1}}{\max}\
272 \underset{y\in \Delta_{2}}{\min}\
273 \left\langle L\left(x\right),y \right\rangle
274 =
275 \underset{y\in \Delta_{2}}{\min}\
276 \underset{x \in \Delta_{1}}{\max}\
277 \left\langle L\left(x\right),y \right\rangle.
278
279 Linear games reduce to two-person zero-sum matrix games in the
280 right setting.
281
282 **Example.** If :math:`K = \mathbb{R}^{n}_{+}` in :math:`V =
283 \mathbb{R}^{n}` and :math:`e_{1} = e_{2} =
284 \left(1,1,\ldots,1\right)^{T} \in \operatorname{int}\left(K\right)`,
285 then :math:`\Delta_{1} = \Delta_{2} = \Delta`. For any :math:`L \in
286 \mathbb{R}^{n \times n}`, the linear game :math:`\left(
287 L,K,e_{2},e_{2} \right)` is a two-person zero-sum matrix game. Its
288 payoff is :math:`\left(x,y\right) \mapsto y^{T}Lx`, and its value is
289
290 .. math::
291 v\left( L,K,e_{1},e_{2} \right)
292 =
293 \underset{x \in \Delta}{\max}\
294 \underset{y\in \Delta}{\min}\
295 \left( y^{T}Lx \right)
296 =
297 \underset{y\in \Delta}{\min}\
298 \underset{x \in \Delta}{\max}\
299 \left( y^{T}Lx \right).
300
301
302 Cone program formulation
303 ~~~~~~~~~~~~~~~~~~~~~~~~
304
305 As early as 1947, von Neumann knew [Dantzig]_ that a two-person
306 zero-sum matrix game could be expressed as a linear program. It turns
307 out that the two concepts are equivalent, but turning a matrix game
308 into a linear program is the simpler transformation. Cone programs are
309 generalizations of linear programs where the cone is allowed to differ
310 from the nonnegative orthant. We will see that any linear game can be
311 formulated as a cone program, and if we're lucky, be solved.
312
313 Our main tool in formulating our cone program is the following
314 theorem. It closely mimics a similar result in classical game theory
315 where the cone is the nonnegative orthant and the result gives rise to
316 a linear program. The symbols :math:`\preccurlyeq` and
317 :math:`\succcurlyeq` indicate inequality with respect to the cone
318 ordering; that is, :math:`x \succcurlyeq y \iff x - y \in K`.
319
320 **Theorem.** In the game :math:`\left(L,K,e_{1},e_{2}\right)`, we have
321 :math:`L^{*}\left( \gamma \right) \preccurlyeq \nu e_{2}` and
322 :math:`L \left( \xi \right) \succcurlyeq \nu e_{1}` for
323 :math:`\nu \in \mathbb{R}` if and only if :math:`\nu` is the
324 value of the game :math:`\left(L,K,e_{1},e_{2}\right)` and
325 :math:`\left(\xi,\gamma\right)` is optimal for it.
326
327 The proof of this theorem is not difficult, and the version for
328 :math:`e_{1} \ne e_{2}` can easily be deduced from the one given by
329 Gowda and Ravidran [GowdaRav]_. Let us now restate the objectives of
330 the two players in terms of this theorem. Player one would like to,
331
332 .. math::
333 \begin{aligned}
334 &\text{ maximize } &\nu &\\
335 &\text{ subject to }& \xi &\in K&\\
336 & & \left\langle \xi,e_{1} \right\rangle &= 1&\\
337 & & \nu &\in \mathbb{R}&\\
338 & & L\left(\xi\right) &\succcurlyeq \nu e_{1}.&
339 \end{aligned}
340
341 Player two, on the other hand, would like to,
342
343 .. math::
344
345 \begin{aligned}
346 &\text{ minimize } &\omega &\\
347 &\text{ subject to }& \gamma &\in K&\\
348 & & \left\langle \gamma,e_{2} \right\rangle &= 1&\\
349 & & \omega &\in \mathbb{R}&\\
350 & & L^{*}\left(\gamma\right) &\preccurlyeq \omega e_{2}.&
351 \end{aligned}
352
353 The `CVXOPT <http://cvxopt.org/>` library can solve symmetric cone
354 programs in the following primal/dual format:
355
356 .. math::
357 \text{primal} =
358 \left\{
359 \begin{aligned}
360 \text{ minimize } & c^{T}x \\
361 \text{ subject to } & Gx + s = h \\
362 & Ax = b \\
363 & s \in C,
364 \end{aligned}
365 \right.
366
367 .. math::
368 \text{dual}
369 =
370 \left\{
371 \begin{aligned}
372 \text{ maximize } & -h^{T}z - b^{T}y \\
373 \text{ subject to } & G^{T}z + A^{T}y + c = 0 \\
374 & z \in C.
375 \end{aligned}
376 \right.
377
378 We will now pull a rabbit out of the hat, and choose the
379 matrices/vectors in these primal/dual programs so as to reconstruct
380 exactly the goals of the two players. Let,
381
382 .. math::
383 \begin{aligned}
384 C &= K \times K\\
385 x &= \begin{bmatrix} \nu & \xi \end{bmatrix} \\
386 b &= \begin{bmatrix} 1 \end{bmatrix} \\
387 h &= 0 \\
388 c &= \begin{bmatrix} -1 & 0 \end{bmatrix} \\
389 A &= \begin{bmatrix} 0 & e_{2}^{T} \end{bmatrix} \\
390 G &= \begin{bmatrix}
391 0 & -I\\
392 e_{1} & -L
393 \end{bmatrix}.
394 \end{aligned}
395
396 Substituting these values into the primal/dual CVXOPT cone programs
397 recovers the objectives of player one (primal) and player two (dual)
398 exactly. Therefore, we can use this formulation to solve a linear
399 game, and that is precisely what Dunshire does.
400
401
402 References
403 ----------
404
405 .. [Dantzig] G. B. Dantzig. Linear Programming and Extensions.
406 Princeton University Press, Princeton, 1963.
407
408 .. [GowdaRav] M. S. Gowda and G. Ravindran. On the game-theoretic
409 value of a linear transformation relative to a self-dual cone. Linear
410 Algebra and its Applications, 469:440-463, 2015.
411
412 .. [Kaplansky] I. Kaplansky. A contribution to von Neumann’s theory of
413 games. Annals of Mathematics, 46(3):474-479, 1945.
414
415 .. [Karlin] S. Karlin. Mathematical Methods and Theory in Games,
416 Programming, and Economics. Addison-Wesley Publishing Company,
417 Reading, Massachusetts, 1959.
418
419 .. [Raghavan] T. Raghavan. Completely mixed games and M-matrices. Linear
420 Algebra and its Applications, 21:35-45, 1978.