Skip to content

Commit

Permalink
Add exercises to text book and clean up pdf output. (#226)
Browse files Browse the repository at this point in the history
* Add exercises to docs and clean up pdf output.

* Run black.
  • Loading branch information
drvinceknight committed Mar 10, 2024
1 parent 64ae181 commit fbb567a
Show file tree
Hide file tree
Showing 68 changed files with 827 additions and 104 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*

12 changes: 11 additions & 1 deletion benchmarks/test_support_enumeration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Benchmarks for support enumeration
"""

import unittest

import numpy as np
Expand All @@ -13,12 +14,21 @@ def test_support_enumeration_on_two_by_two_game(benchmark):
eqs = support_enumeration(A, -A)
benchmark(tuple, eqs)


def test_support_enumeration_on_three_by_three_game(benchmark):
A = np.array(((0, 1, -1), (-1, 0, 1), (1, -1, 0)))
eqs = support_enumeration(A, -A)
benchmark(tuple, eqs)


def test_support_enumeration_on_four_by_four_game(benchmark):
A = np.array(((0, 1, -1, 1/4), (-1, 0, 1, 1/4), (1, -1, 0, 1/4), (1/4, 1/4, 1/4, 1/4)))
A = np.array(
(
(0, 1, -1, 1 / 4),
(-1, 0, 1, 1 / 4),
(1, -1, 0, 1 / 4),
(1 / 4, 1 / 4, 1 / 4, 1 / 4),
)
)
eqs = support_enumeration(A, -A)
benchmark(tuple, eqs)
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
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.
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.
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.
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}
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}
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}
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}
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
Expand Up @@ -5,6 +5,7 @@
The code should match the reference code in the documentation.
"""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
The code should match the reference code in the documentation.
"""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
The code should match the reference code in the documentation.
"""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
The code should match the reference code in the documentation.
"""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
)
plt.figure()
probabilities = [
row_play_counts / np.sum(row_play_counts)
if np.sum(row_play_counts) != 0
else row_play_counts + 1 / len(row_play_counts)
(
row_play_counts / np.sum(row_play_counts)
if np.sum(row_play_counts) != 0
else row_play_counts + 1 / len(row_play_counts)
)
for (row_play_counts, col_play_counts), _ in play_counts_and_distribuions
]
for number, strategy in enumerate(zip(*probabilities)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

plt.figure()
probabilities = [
row_play_counts / np.sum(row_play_counts)
if np.sum(row_play_counts) != 0
else row_play_counts + 1 / len(row_play_counts)
(
row_play_counts / np.sum(row_play_counts)
if np.sum(row_play_counts) != 0
else row_play_counts + 1 / len(row_play_counts)
)
for (row_play_counts, col_play_counts), _ in play_counts_and_distribuions
]
for number, strategy in enumerate(zip(*probabilities)):
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
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

0 comments on commit fbb567a

Please sign in to comment.