Skip to content

Commit 335a8ed

Browse files
Fix minor typos in the text book. (#228)
Also, include some solution notebooks.
1 parent c29b9f7 commit 335a8ed

File tree

7 files changed

+698
-4
lines changed

7 files changed

+698
-4
lines changed

docs/text-book/best-responses.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ Exercises
357357

358358

359359

360-
1. For the following games identify the best responses:
360+
1. For the following games identify the best responses that are strategies with
361+
support size 1 (i.e. strategies that just play a single action).
361362

362363
1.
363364

docs/text-book/solutions/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This contains notebooks with solutions to the exercises from the text book.

docs/text-book/solutions/best-responses.ipynb

Lines changed: 311 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "7779ca3d-99a8-4014-a001-4b4c9314e39f",
6+
"metadata": {},
7+
"source": [
8+
"> Obtain the full game representations $(A, B)$ for the zero sum games with row play payoff matrix given by:\n",
9+
"\n",
10+
" 1. $A =\\begin{pmatrix}1 & 3\\\\ -1 & 4\\end{pmatrix}\\qquad B =\\begin{pmatrix}-1 & -3\\\\ 1 & -4\\end{pmatrix}$"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 12,
16+
"id": "f365cfb4-38bb-4605-b5cd-e4476bd60978",
17+
"metadata": {},
18+
"outputs": [
19+
{
20+
"data": {
21+
"text/plain": [
22+
"Zero sum game with payoff matrices:\n",
23+
"\n",
24+
"Row player:\n",
25+
"[[ 1 3]\n",
26+
" [-1 4]]\n",
27+
"\n",
28+
"Column player:\n",
29+
"[[-1 -3]\n",
30+
" [ 1 -4]]"
31+
]
32+
},
33+
"execution_count": 12,
34+
"metadata": {},
35+
"output_type": "execute_result"
36+
}
37+
],
38+
"source": [
39+
"import nashpy as nash\n",
40+
"import numpy as np\n",
41+
"\n",
42+
"A = np.array(((1, 3), (-1, 4)))\n",
43+
"game = nash.Game(A)\n",
44+
"game"
45+
]
46+
},
47+
{
48+
"cell_type": "markdown",
49+
"id": "206da237-a337-434b-b5f6-0b29ef992687",
50+
"metadata": {},
51+
"source": [
52+
" 2. $A =\\begin{pmatrix}1 & -2\\\\ -1 & 2\\end{pmatrix}\\qquad B =\\begin{pmatrix}-1 & 2\\\\ 1 & -2\\end{pmatrix}$"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 13,
58+
"id": "a8698c05-a30b-40e9-864b-081fbd31da42",
59+
"metadata": {},
60+
"outputs": [
61+
{
62+
"data": {
63+
"text/plain": [
64+
"Zero sum game with payoff matrices:\n",
65+
"\n",
66+
"Row player:\n",
67+
"[[ 1 -2]\n",
68+
" [-1 2]]\n",
69+
"\n",
70+
"Column player:\n",
71+
"[[-1 2]\n",
72+
" [ 1 -2]]"
73+
]
74+
},
75+
"execution_count": 13,
76+
"metadata": {},
77+
"output_type": "execute_result"
78+
}
79+
],
80+
"source": [
81+
"A = np.array(((1, -2), (-1, 2)))\n",
82+
"B = np.array(((-1, 2), (1, -2)))\n",
83+
"game = nash.Game(A, B)\n",
84+
"game"
85+
]
86+
},
87+
{
88+
"cell_type": "markdown",
89+
"id": "07878c15-fb5d-4840-9c0d-e3fe95f1226a",
90+
"metadata": {},
91+
"source": [
92+
" 3. $A =\\begin{pmatrix}1 & -2 & 4\\\\ 2 & -1 & 2\\\\ 7 & -7 & 6\\end{pmatrix}\\qquad B =\\begin{pmatrix}-1 & 2 & -4\\\\ -2 & 1 & -2\\\\ -7 & 7 & -6\\end{pmatrix}$"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": 14,
98+
"id": "fc5f7b5a-91ba-4358-b9f6-0772033fcb8c",
99+
"metadata": {},
100+
"outputs": [
101+
{
102+
"data": {
103+
"text/plain": [
104+
"Zero sum game with payoff matrices:\n",
105+
"\n",
106+
"Row player:\n",
107+
"[[ 1 -2 4]\n",
108+
" [ 2 -1 2]\n",
109+
" [ 7 -7 6]]\n",
110+
"\n",
111+
"Column player:\n",
112+
"[[-1 2 -4]\n",
113+
" [-2 1 -2]\n",
114+
" [-7 7 -6]]"
115+
]
116+
},
117+
"execution_count": 14,
118+
"metadata": {},
119+
"output_type": "execute_result"
120+
}
121+
],
122+
"source": [
123+
"A = np.array(((1, -2, 4), (2, -1, 2), (7, -7, 6)))\n",
124+
"B = np.array(((-1, 2, -4), (-2, 1, -2), (-7, 7, -6)))\n",
125+
"game = nash.Game(A, B)\n",
126+
"game"
127+
]
128+
},
129+
{
130+
"cell_type": "markdown",
131+
"id": "7bafa50e-ac87-4ad8-a5ed-17a5b550066c",
132+
"metadata": {},
133+
"source": [
134+
"> `3.` Consider the game described as follows:\n",
135+
"\n",
136+
" > An airline loses two suitcases belonging to two different travelers. Both suitcases have the same value. An airline manager tasked to settle the claims of both travelers explains that the airline is liable for a maximum of £5 per suitcase. \n",
137+
"\n",
138+
" > To determine an honest appraised value of the suitcases, the manager separates both travelers and asks them to write down the amount of their value at no less than £2 and no larger than £5 (to the single dollar):\n",
139+
" > - If both write down the same number, that number as the true dollar value of both suitcases and reimburse both travelers that amount. \n",
140+
" > - However, if one writes down a smaller number than the other, this smaller number will be taken as the true dollar value, and both travelers will receive that amount along with a bonus/malus: £2 extra will be paid to the traveler who wrote down the lower value and a £2 deduction will be taken from the person who wrote down the higher amount. \n",
141+
" \n",
142+
" > Represent this as a Normal Form Game.\n",
143+
" \n",
144+
" \n",
145+
"$$\n",
146+
"A = \\begin{pmatrix}\n",
147+
"2 & 4 & 4 & 4\\\\\n",
148+
"0 & 3 & 5 & 5\\\\\n",
149+
"0 & 1 & 4 & 6\\\\\n",
150+
"0 & 1 & 2 & 5\n",
151+
"\\end{pmatrix}\n",
152+
"\\qquad\n",
153+
"B = \\begin{pmatrix}\n",
154+
"2 & 0 & 0 & 0\\\\\n",
155+
"4 & 3 & 1 & 1\\\\\n",
156+
"4 & 5 & 4 & 2\\\\\n",
157+
"4 & 5 & 6 & 5\n",
158+
"\\end{pmatrix}\n",
159+
"$$"
160+
]
161+
},
162+
{
163+
"cell_type": "code",
164+
"execution_count": 15,
165+
"id": "f1922cd9-a1ca-40ca-b1ad-c09de6b46a9d",
166+
"metadata": {},
167+
"outputs": [
168+
{
169+
"data": {
170+
"text/plain": [
171+
"Bi matrix game with payoff matrices:\n",
172+
"\n",
173+
"Row player:\n",
174+
"[[2 4 4 4]\n",
175+
" [0 3 5 5]\n",
176+
" [0 1 4 6]\n",
177+
" [0 1 2 5]]\n",
178+
"\n",
179+
"Column player:\n",
180+
"[[2 0 0 0]\n",
181+
" [4 3 1 1]\n",
182+
" [4 5 4 2]\n",
183+
" [4 5 6 5]]"
184+
]
185+
},
186+
"execution_count": 15,
187+
"metadata": {},
188+
"output_type": "execute_result"
189+
}
190+
],
191+
"source": [
192+
"A = np.array(((2, 4, 4, 4), (0, 3, 5, 5), (0, 1, 4, 6), (0, 1, 2,5)))\n",
193+
"B = np.array(((2, 0, 0, 0), (4, 3, 1, 1), (4, 5, 4, 2), (4, 5, 6, 5)))\n",
194+
"game = nash.Game(A, B)\n",
195+
"game"
196+
]
197+
},
198+
{
199+
"cell_type": "code",
200+
"execution_count": null,
201+
"id": "c8b6f40c-b1c9-4b63-b373-0c42436d8238",
202+
"metadata": {},
203+
"outputs": [],
204+
"source": []
205+
}
206+
],
207+
"metadata": {
208+
"kernelspec": {
209+
"display_name": "Python 3 (ipykernel)",
210+
"language": "python",
211+
"name": "python3"
212+
},
213+
"language_info": {
214+
"codemirror_mode": {
215+
"name": "ipython",
216+
"version": 3
217+
},
218+
"file_extension": ".py",
219+
"mimetype": "text/x-python",
220+
"name": "python",
221+
"nbconvert_exporter": "python",
222+
"pygments_lexer": "ipython3",
223+
"version": "3.11.4"
224+
}
225+
},
226+
"nbformat": 4,
227+
"nbformat_minor": 5
228+
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "f11b56d3-3fc5-40c5-bde2-ff7ad5eb6207",
6+
"metadata": {},
7+
"source": [
8+
"3. Calculate the utilities (for both the row and column player) for the following game for the following strategy pairs:\n",
9+
"\n",
10+
" $$\n",
11+
" A =\n",
12+
" \\begin{pmatrix}\n",
13+
" 1 & -1\\\\\n",
14+
" -3 & 1\\end{pmatrix}\n",
15+
" \\qquad\n",
16+
" B =\n",
17+
" \\begin{pmatrix}\n",
18+
" -1 & 2\\\\\n",
19+
" 1 & -1\\end{pmatrix}\n",
20+
" $$\n",
21+
"\n",
22+
" 1. $\\sigma_r = (.2, .8)\\qquad\\sigma_c = (.6, .4)$\n",
23+
" \n",
24+
" $$u_r(\\sigma_r, \\sigma_c) = \\sigma_r A \\sigma_c ^T = .2\\times.6\\times 1 + .2\\times .4\\times (-1) + .8\\times.6\\times (-3) + .8\\times .4\\times 1=-1.08$$\n",
25+
" \n",
26+
" $$u_c(\\sigma_r, \\sigma_c) = \\sigma_r B \\sigma_c ^T = .2\\times.6\\times (-1) + .2\\times .4\\times 2 + .8\\times.6\\times 1 + .8\\times .4\\times (-1)=0.2 $$\n",
27+
" 2. $\\sigma_r = (.3, .7)\\qquad\\sigma_c = (.2, .8)$\n",
28+
" \n",
29+
" $$u_r(\\sigma_r, \\sigma_c) = -0.04$$\n",
30+
" \n",
31+
" $$u_c(\\sigma_r, \\sigma_c) = 0$$\n",
32+
" 3. $\\sigma_r = (.9, .1)\\qquad\\sigma_c = (.5, .5)$\n",
33+
" \n",
34+
" $$u_r(\\sigma_r, \\sigma_c) = -0.1$$\n",
35+
" \n",
36+
" $$u_c(\\sigma_r, \\sigma_c) = 0.45$$"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 5,
42+
"id": "dffb72f1-8d5c-48ba-bcb9-c875ea7f2731",
43+
"metadata": {},
44+
"outputs": [],
45+
"source": [
46+
"import nashpy as nash\n",
47+
"import numpy as np\n",
48+
"\n",
49+
"A = np.array(((1, -1), (-3, 1)))\n",
50+
"B = np.array(((-1, 2), (1, -1)))\n",
51+
"game = nash.Game(A, B)"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": 6,
57+
"id": "4b1db209-6058-46e1-85b1-df31fe5f010f",
58+
"metadata": {},
59+
"outputs": [
60+
{
61+
"data": {
62+
"text/plain": [
63+
"array([-1.08, 0.2 ])"
64+
]
65+
},
66+
"execution_count": 6,
67+
"metadata": {},
68+
"output_type": "execute_result"
69+
}
70+
],
71+
"source": [
72+
"sigma_r = np.array((.2, .8))\n",
73+
"sigma_c = np.array((.6, .4))\n",
74+
"game[sigma_r, sigma_c]"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": 7,
80+
"id": "df7c6c52-e97a-49a3-ae30-85a0bdd78499",
81+
"metadata": {},
82+
"outputs": [
83+
{
84+
"data": {
85+
"text/plain": [
86+
"array([-4.0000000e-02, 4.4408921e-18])"
87+
]
88+
},
89+
"execution_count": 7,
90+
"metadata": {},
91+
"output_type": "execute_result"
92+
}
93+
],
94+
"source": [
95+
"sigma_r = np.array((.3, .7))\n",
96+
"sigma_c = np.array((.2, .8))\n",
97+
"game[sigma_r, sigma_c]"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": 8,
103+
"id": "0fad9239-66aa-4317-8dae-800d260bb41d",
104+
"metadata": {},
105+
"outputs": [
106+
{
107+
"data": {
108+
"text/plain": [
109+
"array([-0.1 , 0.45])"
110+
]
111+
},
112+
"execution_count": 8,
113+
"metadata": {},
114+
"output_type": "execute_result"
115+
}
116+
],
117+
"source": [
118+
"sigma_r = np.array((.9, .1))\n",
119+
"sigma_c = np.array((.5, .5))\n",
120+
"game[sigma_r, sigma_c]"
121+
]
122+
},
123+
{
124+
"cell_type": "code",
125+
"execution_count": null,
126+
"id": "fa7b3636-02db-4613-bca6-dcf0225a42ba",
127+
"metadata": {},
128+
"outputs": [],
129+
"source": []
130+
}
131+
],
132+
"metadata": {
133+
"kernelspec": {
134+
"display_name": "Python 3 (ipykernel)",
135+
"language": "python",
136+
"name": "python3"
137+
},
138+
"language_info": {
139+
"codemirror_mode": {
140+
"name": "ipython",
141+
"version": 3
142+
},
143+
"file_extension": ".py",
144+
"mimetype": "text/x-python",
145+
"name": "python",
146+
"nbconvert_exporter": "python",
147+
"pygments_lexer": "ipython3",
148+
"version": "3.11.4"
149+
}
150+
},
151+
"nbformat": 4,
152+
"nbformat_minor": 5
153+
}

0 commit comments

Comments
 (0)