Skip to content

Commit

Permalink
Add exercises to docs and clean up pdf output.
Browse files Browse the repository at this point in the history
  • Loading branch information
drvinceknight committed Mar 10, 2024
1 parent 64ae181 commit 7ed6125
Show file tree
Hide file tree
Showing 34 changed files with 775 additions and 95 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ build/
env/
.tox/
*.DS_Store
*.aux
*.log
*.fdb_latexmk
*.fls
*.xdv
env*

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source files for an image used in the description of extensive form games.

Compilation instructions:

```
$ latexmk --xelatex main.tex
$ convert -density 300 main.pdf -quality 90 main.png
```
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\node [draw, color=red] (A1) at (0, 0) {\(A_1\)};
\node [draw, color=blue] (B1) at ($(A1) + (-2.5, -2)$) {\(B_1\)};
\node [draw] (O1) at ($(B1) + (-1, -2)$) {\tiny{\(O_1\)}};
\node (SS) at ($(O1) + (0, -.5)$) {\((4, 1)\)};
\node [draw] (O2) at ($(B1) + (1, -2)$) {\tiny{\(O_2\)}};
\node (SC) at ($(O2) + (0, -.5)$) {\((3, 5)\)};
\node [draw, color=blue] (B2) at ($(A1) + (2.5, -2)$) {\(B_2\)};
\node [draw] (O3) at ($(B2) + (-1, -2)$) {\tiny{\(O_3\)}};
\node (CS) at ($(O3) + (0, -.5)$) {\((4, 2)\)};
\node [draw] (O5) at ($(B2) + (1, -2)$) {\tiny{\(O_5\)}};
\node (CC) at ($(O5) + (0, -.5)$) {\((2, 0)\)};

\draw (A1) -- node[left=3mm] {X} (B1);
\draw (A1) -- node[right=3mm] {W} (B2);
\draw (B1) -- node[left=3mm] {a} (O1);
\draw (B1) -- node[right=3mm] {b} (O2);
\draw (B2) -- node[left=3mm] {c} (O3);
\draw (B2) -- node[right=3mm] {d} (O5);
\end{tikzpicture}

\end{document}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source files for an image used in the description of extensive form games.

Compilation instructions:

```
$ latexmk --xelatex main.tex
$ convert -density 300 main.pdf -quality 90 main.png
```
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\node [draw, color=red] (A1) at (0, 0) {\(A_1\)};
\node [draw] (O2) at ($(A1) + (-2.5, -2)$) {\tiny{\(O_2\)}};
\node (SC) at ($(O2) + (0, -.5)$) {\((3, 5)\)};
\node [draw] (O3) at ($(A1) + (2.5, -2)$) {\tiny{\(O_3\)}};
\node (CS) at ($(O3) + (0, -.5)$) {\((4, 2)\)};

\draw (A1) -- node[left=3mm] {X} (O2);
\draw (A1) -- node[right=3mm] {W} (O3);
\end{tikzpicture}

\end{document}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Source files for an image used in the description of extensive form games.

Compilation instructions:

```
$ latexmk --xelatex main.tex
$ convert -density 300 main.pdf -quality 90 main.png
```
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\node [draw, color=red] (A1) at (0, 0) {\(A_1\)};
\node [draw, color=blue] (B1) at ($(A1) + (-2.5, -2)$) {\(B_1\)};
\node [draw] (O1) at ($(B1) + (-1, -2)$) {\tiny{\(O_1\)}};
\node (SS) at ($(O1) + (0, -.5)$) {\((4, 1)\)};
\node [draw] (O2) at ($(B1) + (1, -2)$) {\tiny{\(O_2\)}};
\node (SC) at ($(O2) + (0, -.5)$) {\((3, 5)\)};
\node [draw] (O3) at ($(A1) + (2.5, -2)$) {\tiny{\(O_3\)}};
\node (CS) at ($(O3) + (0, -.5)$) {\((4, 2)\)};

\draw (A1) -- node[left=3mm] {X} (B1);
\draw (A1) -- node[right=3mm] {W} (O3);
\draw (B1) -- node[left=3mm] {a} (O1);
\draw (B1) -- node[right=3mm] {b} (O2);
\end{tikzpicture}

\end{document}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions docs/_static/discussion/extensive-form-game-exercise-four/main.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
\documentclass[tikz]{standalone}
\usepackage{tikz,amsmath}
\begin{document}
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]
\tikzstyle{player} = [text width=5em, draw, text centered, rectangle, fill=blue!20, inner sep=1pt]
\tikzstyle{nature} = [minimum width=3pt,circle, draw, fill=red!20, inner sep=1pt]
\tikzstyle{end} = [circle, minimum width=3pt, fill, inner sep=0pt, right]
\begin{tikzpicture}[grow=right, sloped]
\node[player]{a: 1}
child {node (C2) [player] {b: 1}
child {node[end] {} node[right] {$(3,2)$} edge from parent node[below] {A}}
child {node[end] {} node[right] {$(1,1)$} edge from parent node[below] {B}} edge from parent node[below] {A}}
child {node (1stC) (C1) [player] {c: 2}
child {node[end] {} node[right] {$(0,0)$} edge from parent node[below] {A}}
child {node[end] {} node[right] {$(4,0)$} edge from parent node[below] {B}}
child {node[end] {} node[right] {$(2,3)$} edge from parent node[below] {C}} edge from parent node[below] {B}};
\end{tikzpicture}
\end{document}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions docs/_static/discussion/extensive-form-game-exercise-one/main.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
\documentclass[tikz]{standalone}
\usepackage{tikz,amsmath}
\begin{document}
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]
\tikzstyle{player} = [text width=5em, draw, text centered, rectangle, fill=blue!20, inner sep=1pt]
\tikzstyle{nature} = [minimum width=3pt,circle, draw, fill=red!20, inner sep=1pt]
\tikzstyle{end} = [circle, minimum width=3pt, fill, inner sep=0pt, right]
\begin{tikzpicture}[grow=right, sloped]
\node[player]{a: 1}
child {node[player] {b: 2}
child {node[player] {c: 1}
child {node[player] {d: 2}
child {node[player] {e: 1}
child {node[end] {} node [right] {$(2,17)$} edge from parent node[below] {W}}
child {node[end] {} node [right] {$(6,4)$} edge from parent node[below] {Y}}
edge from parent node[below] {J}
}
child {node[end] {} node [right] {$(7,30)$} edge from parent node[below] {X}}
edge from parent node[below] {F}}
child {node[end] {} node [right] {$(70,3)$} edge from parent node[below] {Z}}
edge from parent node[below] {D}
edge from parent node[below] {D}}
child {node[end] {} node [right] {$(1,6)$}
edge from parent node[below] {C}}
edge from parent node[below] {B}}
child {node[end] {} node [right] {$(3,2)$} edge from parent node[below] {A}};
\end{tikzpicture}
\end{document}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
\documentclass[tikz]{standalone}
\usepackage{tikz,amsmath}
\begin{document}
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=1cm]
\tikzstyle{player} = [text width=5em, draw, text centered, rectangle, fill=blue!20, inner sep=1pt]
\tikzstyle{nature} = [minimum width=3pt,circle, draw, fill=red!20, inner sep=1pt]
\tikzstyle{end} = [circle, minimum width=3pt, fill, inner sep=0pt, right]
\begin{tikzpicture}[grow=right, sloped]
\node[player]{a: 1}
child {node (C2) [player] {b: 2}
child {node[end] {} node[right] {$(3,2,1)$} edge from parent node[below] {B}}
child {node (C3)[player] {e: 3}
child {node [end] {} node[right] {$(60,1,53)$}
edge from parent node[below] {B}}
child {node [end] {} node[right] {$(6,0,2)$}
edge from parent node[below] {A}}
edge from parent node[below] {A}
}
edge from parent node[below] {B}}
child {node (1stC) (C1) [player] {c: 2}
child {node (C4) [player] {d: 3}
child {node [end] {} node[right] {$(20,50,80)$}
edge from parent node[below] {B}}
child {node [end] {} node[right] {$(30,40,50)$}
edge from parent node[below] {A}}
edge from parent node[below] {B}
}
child {node[end] {} node[right] {$(4,0,3)$} edge from parent node[below] {A}}
edge from parent node[below] {A}};
\draw [dashed] (C2) -- (C1);
\draw [dashed] (C3) -- (C4);
\end{tikzpicture}
\end{document}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions docs/_static/discussion/extensive-form-game-exercise-two/main.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
\documentclass[tikz]{standalone}
\usepackage{tikz,amsmath}
\begin{document}
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]
\tikzstyle{level 3}=[level distance=3.5cm, sibling distance=1cm]
\tikzstyle{player} = [text width=5em, draw, text centered, rectangle, fill=blue!20, inner sep=1pt]
\tikzstyle{nature} = [minimum width=3pt,circle, draw, fill=red!20, inner sep=1pt]
\tikzstyle{end} = [circle, minimum width=3pt, fill, inner sep=0pt, right]
\begin{tikzpicture}[grow=right, sloped]
\node[player]{a: 1}
child {node[player] {c: 2}
child {node[player] {g: 1}
child{node[end] {} node[right]{$(3,2)$} edge from parent node[below]{K}}
child{node [end] {} node[right]{$(6,7)$} edge from parent node[below]{L}}edge from parent node[below] {B}}
child {node[player] {f: 1}
child{node[end] {} node[right]{$(1,3)$} edge from parent node[below]{K}}
child{node [end] {} node[right]{$(5,10)$} edge from parent node[below]{L}}edge from parent node[below] {A}}
edge from parent node[below] {W}}
child {node[player] {b: 2}
child {node[player] {e: 1}
child {node[end] {} node [right] {$(2,3)$} edge from parent node[below] {Y}}
child {node[end] {} node [right] {$(1,2)$} edge from parent node[below] {Z}}
edge from parent node[below] {C}}
child {node [player] {d: 1}
child{node[end] {} node [right] {$(10,1)$} edge from parent node[below] {M}}
child{node[end] {} node [right] {$(5,2)$} edge from parent node[below] {N}}
edge from parent node[below] {D}}
edge from parent node[below] {Y}};
\end{tikzpicture}
\end{document}
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
.. _degenerate-games-discussion:

Degenerate games
================

A two player game is called nondegenerate if no mixed strategy of support size
:math:`k` has more than :math:`k` pure best responses.

For example, the zero sum game defined by the following matrix is degenerate:

.. math::
A =
\begin{pmatrix}
0 & -1 & 1\\
-1 & 0 & 1\\
-1 & 1 & 0
\end{pmatrix}
The third column has two pure best responses.
Handle Degenerate games
=======================

When dealing with *degenerate* games unexpected results can occur::

Expand Down
1 change: 1 addition & 0 deletions docs/how-to/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ How to:
create-a-game.rst
calculate-utilities.rst
check-best-responses.rst
handle-degenerate-games.rst
use-minimax.rst
solve-with-support-enumeration.rst
solve-with-vertex-enumeration.rst
Expand Down
115 changes: 115 additions & 0 deletions docs/text-book/best-responses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,33 @@ response to a row players' strategy :math:`\sigma_r` if and only if:
\text{argmax}_{i\in\mathcal{A}_1}A_{ij}=2\text{ for all }j\in\mathcal{A}_2
.. _definition_of_a_degenerate_game:

Definition of a degenerate game
-------------------------------

A two player game is called non degenerate if no mixed strategy of support size
:math:`k` has more than :math:`k` pure best responses.

.. admonition:: Question
:class: note

Show that the following game is degenerate:

.. math::
A =
\begin{pmatrix}
0 & -1 & 1\\
-1 & 0 & 1\\
-1 & 1 & 0
\end{pmatrix}
.. admonition:: Answer
:class: caution, dropdown

The third column has two pure best responses.

.. _best_responses_in_2_by_2_games:

Generic best responses in 2 by 2 games
Expand Down Expand Up @@ -325,6 +352,94 @@ In a two player game :math:`(A, B)\in {\mathbb{R}^{m \times n}} ^ 2`,
response to :math:`\sigma_c` and :math:`\sigma_c` is a best response to
:math:`\sigma_r`.

Exercises
---------



1. For the following games identify the best responses:

1.

.. math::
A =
\begin{pmatrix}
2 & 1\\
1 & 1\end{pmatrix}
\qquad
B =
\begin{pmatrix}
1 & 1\\
1 & 3\end{pmatrix}
2.

.. math::
A =
\begin{pmatrix}
2 & 1 & 3 & 17\\
27 & 3 & 1 & 1\\
4 & 6 & 7 & 18
\end{pmatrix}
\qquad
B =
\begin{pmatrix}
11 & 9 & 10 & 22\\
0 & 1 & 1 & 0\\
2 & 10 & 12 & 0
\end{pmatrix}
3.

.. math::
A =
\begin{pmatrix}
3 & 3 & 2 \\
2 & 1 & 3
\end{pmatrix}
\qquad
B =
\begin{pmatrix}
2 & 1 & 3 \\
2 & 3 & 2
\end{pmatrix}
4.

.. math::
A =
\begin{pmatrix}
3 & -1\\
2 & 7\end{pmatrix}
\qquad
B =
\begin{pmatrix}
-3 & 1\\
1 & -6\end{pmatrix}
2. Represent the following game in normal form:

Assume two neighbouring countries have at their disposal very
destructive armies. If both countries attack each other the
countries’ civilian population will suffer 10 thousand casualties.
If one country attacks whilst the other remains peaceful, the
peaceful country will lose 15 thousand casualties but would also
retaliate causing the offensive country 13 thousand casualties. If
both countries remain peaceful then there are no casualties.

1. Clearly state the players and strategy sets.
2. Plot the utilities to both countries assuming that they play a
mixed strategy while the other country remains peaceful.
3. Plot the utilities to both countries assuming that they play a
mixed strategy while the other country attacks.
4. Obtain the best responses of each player.

3. Construct a degenerate :math:`3\times 3` game.

Using Nashpy
------------

Expand Down
Loading

0 comments on commit 7ed6125

Please sign in to comment.