Skip to content

Commit

Permalink
Add docs to index.
Browse files Browse the repository at this point in the history
  • Loading branch information
drvinceknight committed Mar 25, 2024
1 parent 08bd7fb commit 33d5613
Show file tree
Hide file tree
Showing 7 changed files with 645 additions and 0 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
File renamed without changes.
File renamed without changes.
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

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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "f11b56d3-3fc5-40c5-bde2-ff7ad5eb6207",
"metadata": {},
"source": [
"3. Calculate the utilities (for both the row and column player) for the following game for the following strategy pairs:\n",
"\n",
" $$\n",
" A =\n",
" \\begin{pmatrix}\n",
" 1 & -1\\\\\n",
" -3 & 1\\end{pmatrix}\n",
" \\qquad\n",
" B =\n",
" \\begin{pmatrix}\n",
" -1 & 2\\\\\n",
" 1 & -1\\end{pmatrix}\n",
" $$\n",
"\n",
" 1. $\\sigma_r = (.2, .8)\\qquad\\sigma_c = (.6, .4)$\n",
" \n",
" $$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",
" \n",
" $$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",
" 2. $\\sigma_r = (.3, .7)\\qquad\\sigma_c = (.2, .8)$\n",
" \n",
" $$u_r(\\sigma_r, \\sigma_c) = -0.04$$\n",
" \n",
" $$u_c(\\sigma_r, \\sigma_c) = 0$$\n",
" 3. $\\sigma_r = (.9, .1)\\qquad\\sigma_c = (.5, .5)$\n",
" \n",
" $$u_r(\\sigma_r, \\sigma_c) = -0.1$$\n",
" \n",
" $$u_c(\\sigma_r, \\sigma_c) = 0.45$$"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "dffb72f1-8d5c-48ba-bcb9-c875ea7f2731",
"metadata": {},
"outputs": [],
"source": [
"import nashpy as nash\n",
"import numpy as np\n",
"\n",
"A = np.array(((1, -1), (-3, 1)))\n",
"B = np.array(((-1, 2), (1, -1)))\n",
"game = nash.Game(A, B)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "4b1db209-6058-46e1-85b1-df31fe5f010f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([-1.08, 0.2 ])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sigma_r = np.array((.2, .8))\n",
"sigma_c = np.array((.6, .4))\n",
"game[sigma_r, sigma_c]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "df7c6c52-e97a-49a3-ae30-85a0bdd78499",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([-4.0000000e-02, 4.4408921e-18])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sigma_r = np.array((.3, .7))\n",
"sigma_c = np.array((.2, .8))\n",
"game[sigma_r, sigma_c]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0fad9239-66aa-4317-8dae-800d260bb41d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([-0.1 , 0.45])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sigma_r = np.array((.9, .1))\n",
"sigma_c = np.array((.5, .5))\n",
"game[sigma_r, sigma_c]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa7b3636-02db-4613-bca6-dcf0225a42ba",
"metadata": {},
"outputs": [],
"source": []
}
],
"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 33d5613

Please sign in to comment.