Skip to content

Commit

Permalink
Fix a minor typo and add new documentation. (#230)
Browse files Browse the repository at this point in the history
* Fix a minor typo.

* Add docs to index.
  • Loading branch information
drvinceknight committed Mar 25, 2024
1 parent a3fb697 commit ebae5f1
Show file tree
Hide file tree
Showing 10 changed files with 656 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/how-to/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ How to:
obtain-a-repeated-game.rst
use-moran-process-on-replacement-graph.rst
use-moran-process-on-interaction-graph.rst
use-imitation-dynamics.rst
use-regret-minimization.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _how-to-use-imitation-dynamics:

Solve with Imitation Dynamics
==============================
Use Imitation Dynamics
======================

One of the algorithms implemented in :code:`Nashpy` is called
:code:`imitation_dynamics()`, this is implemented as a method on the :code:`Game`
Expand Down Expand Up @@ -33,4 +33,4 @@ of the imitation dynamics algorithm::
>>> threshold=0.3
>>> ne_imitation_dynamics = rps.imitation_dynamics(population_size=population_size,iterations=iterations,random_seed=random_seed,threshold=threshold)
>>> list(ne_imitation_dynamics)
[(array([0., 1., 0.]), array([1., 0., 1.]))]
[(array([0., 1., 0.]), array([1., 0., 1.]))]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _how-to-use-regret-minimization:

Solve with Regret Minimization
==============================
Use with Regret Minimization
============================

One of the algorithms implemented in :code:`Nashpy` is called
:code:`regret_minimization()`, this is implemented as a method on the :code:`Game`
Expand Down
2 changes: 1 addition & 1 deletion docs/text-book/best-responses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ response to a row players' strategy :math:`\sigma_r` if and only if:
The row player's best response to either of the actions of the column player
is :math:`\sigma_r^*=(1,0)`. This can be expressed as:
is :math:`\sigma_r^*=(0,1)`. This can be expressed as:

.. math::
Expand Down
6 changes: 3 additions & 3 deletions docs/text-book/imitation-dynamics.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Detailed Mathematical Model of Imitation Dynamics
==================================================
Imitation Dynamics
==================

Introduction
------------
Expand Down Expand Up @@ -62,4 +62,4 @@ Using Nashpy
------------

See :ref:`how-to-use-imitation-dynamics` for guidance of how to use Nashpy to
simulation Imitation Dynamics.
simulation Imitation Dynamics.
2 changes: 2 additions & 0 deletions docs/text-book/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ Nashpy Game Theory Text book
replicator-dynamics.rst
asymmetric-replicator-dynamics.rst
moran-process.rst
imitation-dynamics.rst
regret_minimization.rst
4 changes: 2 additions & 2 deletions docs/text-book/regret_minimization.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Regret Minimization in Game Theory
==================================
Regret Minimization
===================

Introduction
------------
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "7779ca3d-99a8-4014-a001-4b4c9314e39f",
"metadata": {},
"source": [
"> Obtain the full game representations $(A, B)$ for the zero sum games with row play payoff matrix given by:\n",
"\n",
" 1. $A =\\begin{pmatrix}1 & 3\\\\ -1 & 4\\end{pmatrix}\\qquad B =\\begin{pmatrix}-1 & -3\\\\ 1 & -4\\end{pmatrix}$"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f365cfb4-38bb-4605-b5cd-e4476bd60978",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Zero sum game with payoff matrices:\n",
"\n",
"Row player:\n",
"[[ 1 3]\n",
" [-1 4]]\n",
"\n",
"Column player:\n",
"[[-1 -3]\n",
" [ 1 -4]]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import nashpy as nash\n",
"import numpy as np\n",
"\n",
"A = np.array(((1, 3), (-1, 4)))\n",
"B = np.array(((-1, -3), (1, -4)))\n",
"game = nash.Game(A, B)\n",
"game"
]
},
{
"cell_type": "markdown",
"id": "206da237-a337-434b-b5f6-0b29ef992687",
"metadata": {},
"source": [
" 2. $A =\\begin{pmatrix}1 & -2\\\\ -1 & 2\\end{pmatrix}\\qquad B =\\begin{pmatrix}-1 & 2\\\\ 1 & -2\\end{pmatrix}$"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a8698c05-a30b-40e9-864b-081fbd31da42",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Zero sum game with payoff matrices:\n",
"\n",
"Row player:\n",
"[[ 1 -2]\n",
" [-1 2]]\n",
"\n",
"Column player:\n",
"[[-1 2]\n",
" [ 1 -2]]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = np.array(((1, -2), (-1, 2)))\n",
"B = np.array(((-1, 2), (1, -2)))\n",
"game = nash.Game(A, B)\n",
"game"
]
},
{
"cell_type": "markdown",
"id": "07878c15-fb5d-4840-9c0d-e3fe95f1226a",
"metadata": {},
"source": [
" 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}$"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "fc5f7b5a-91ba-4358-b9f6-0772033fcb8c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Zero sum game with payoff matrices:\n",
"\n",
"Row player:\n",
"[[ 1 -2 4]\n",
" [ 2 -1 2]\n",
" [ 7 -7 6]]\n",
"\n",
"Column player:\n",
"[[-1 2 -4]\n",
" [-2 1 -2]\n",
" [-7 7 -6]]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = np.array(((1, -2, 4), (2, -1, 2), (7, -7, 6)))\n",
"B = np.array(((-1, 2, -4), (-2, 1, -2), (-7, 7, -6)))\n",
"game = nash.Game(A, B)\n",
"game"
]
},
{
"cell_type": "markdown",
"id": "7bafa50e-ac87-4ad8-a5ed-17a5b550066c",
"metadata": {},
"source": [
"> `3.` Consider the game described as follows:\n",
"\n",
" > 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",
"\n",
" > 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",
" > - If both write down the same number, that number as the true dollar value of both suitcases and reimburse both travelers that amount. \n",
" > - 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",
" \n",
" > Represent this as a Normal Form Game.\n",
" \n",
" \n",
"$$\n",
"A = \\begin{pmatrix}\n",
"2 & 4 & 4 & 4\\\\\n",
"0 & 3 & 5 & 5\\\\\n",
"0 & 1 & 4 & 6\\\\\n",
"0 & 1 & 2 & 5\n",
"\\end{pmatrix}\n",
"\\qquad\n",
"B = \\begin{pmatrix}\n",
"2 & 0 & 0 & 0\\\\\n",
"4 & 3 & 1 & 1\\\\\n",
"4 & 5 & 4 & 2\\\\\n",
"4 & 5 & 6 & 5\n",
"\\end{pmatrix}\n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f1922cd9-a1ca-40ca-b1ad-c09de6b46a9d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Bi matrix game with payoff matrices:\n",
"\n",
"Row player:\n",
"[[2 4 4 4]\n",
" [0 3 5 5]\n",
" [0 1 4 6]\n",
" [0 1 2 5]]\n",
"\n",
"Column player:\n",
"[[2 0 0 0]\n",
" [4 3 1 1]\n",
" [4 5 4 2]\n",
" [4 5 6 5]]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = np.array(((2, 4, 4, 4), (0, 3, 5, 5), (0, 1, 4, 6), (0, 1, 2,5)))\n",
"B = np.array(((2, 0, 0, 0), (4, 3, 1, 1), (4, 5, 4, 2), (4, 5, 6, 5)))\n",
"game = nash.Game(A, B)\n",
"game"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit ebae5f1

Please sign in to comment.