-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 183-make-games-be-also-callable-with-a-tuple…
…list-of-tuples
- Loading branch information
Showing
13 changed files
with
397 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
p { | ||
text-align: justify; | ||
} | ||
img { | ||
display: block; | ||
max-width: 100%; | ||
height: auto; | ||
margin: auto; | ||
float: none!important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,308 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"# The Core: A different view on explanation\n", | ||
"\n", | ||
"On this page another game theoretic concept *the core* is introduced and how it can be applied for explanation.\n", | ||
"Mainly applied in the field of economics the core is a newly introduced concept in the field of explanation for AI researchers." | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"## Example: Writing a Paper\n", | ||
"Let us consider three AI researchers Alice, Bob and Charlie which work together on a paper.\n", | ||
"The paper is about a new method to explain AI models and would win the best paper award at the next conference.\n", | ||
"Winning the best paper award would grant them a \\$500 price.\n", | ||
"Despite their long friendship they would like to have a fair share of the prize money.\n" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"As they are AI researchers they are familiar with the concept of *Shapley values*, being a fair way to distribute the prize money.\n", | ||
"They have previously recorded their best paper award prizes:\n", | ||
"\n", | ||
"\n", | ||
"| Authos | Award |\n", | ||
"|-----------------|----------|\n", | ||
"| | \\$ $0$ |\n", | ||
"| Alice | \\$ $0$ |\n", | ||
"| Bob | \\$ $0$ |\n", | ||
"| Charlie | \\$ $0$ |\n", | ||
"| Alice, Bob | \\$ $500$ |\n", | ||
"| Alice, Charlie | \\$ $400$ |\n", | ||
"| Bob, Charlie | \\$ $350$ |\n", | ||
"| Alice, Bob, Charlie | \\$ $500$ |\n", | ||
"\n", | ||
"Based on these values they would like to distribute the prize money in a fair way via the Shapley values.\n", | ||
"Running the calculations they get the following values:\n", | ||
"\n", | ||
"| Authos | Shapley Value |\n", | ||
"|-----------------|---------------|\n", | ||
"| Alice | \\$ $200$ |\n", | ||
"| Bob | \\$ $175$ |\n", | ||
"| Charlie | \\$ $125$ |\n", | ||
"\n", | ||
"An inherent assumption when computing the Shapley value is that Alice, Bob and Charlie really work together.\n", | ||
"Yet it might be the case that Alice and Bob realize they would get a higher payoff if they would exclude Charlie, namely \\$250 each.\n", | ||
"The concept of the core is now introduced to prevent such behavior." | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"## The Core\n", | ||
"The main idea of the core is to distribute the money in such a way, that there is no incentive for anybody to leave the group.\n", | ||
"In our example the core would be the set of all possible distributions of the prize money, where Alice, Bob and Charlie will work together.\n", | ||
"The underlying concept capturing \"leave the group\" is *stability*.\n", | ||
"We say a payoff distribution $\\psi(N,\\nu)$ of a game $(N,\\nu)$ is stable iff.\n", | ||
"\n", | ||
"$$\n", | ||
"\\forall S\\subseteq N. \\sum_{i \\in S} \\psi(S,\\nu)_i \\geq v(S)\n", | ||
"$$\n", | ||
"\n", | ||
"where $\\psi(S,\\nu)_i$ is the payoff of player $i$ in the coalition $S$.\n", | ||
"Stability induces no need to leave the group as each player gets what he would get in a smaller\n", | ||
"group.\n", | ||
"The core is then defined as the set of all stable payoff distributions.\n", | ||
"\n", | ||
"$$\n", | ||
" \\mathcal{C} := \\{ \\psi(N,\\nu) | \\forall S\\subseteq N. \\sum_{i \\in S} \\psi(N,\\nu)_i \\geq v(S) \\land \\sum_{i \\in N} \\psi(N,\\nu)_i = \\nu(N) \\}\n", | ||
"$$\n", | ||
"\n" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"## The Core of Writing a Paper\n", | ||
"Let us now compute the core for our example.\n", | ||
"To do so we must find at least one payoff distribution, which is stable.\n", | ||
"Let us abbreviate the authors payoffs as $a$,$b$ and $c$.\n", | ||
"\n", | ||
"$$\n", | ||
" (I): a + b \\geq 500 \\\\\n", | ||
" (II): a + c \\geq 400 \\\\\n", | ||
" (III): b + c \\geq 350 \\\\\n", | ||
" (IV): a + b + c = 500\n", | ||
"$$\n", | ||
"\n", | ||
"From (I) and (IV) we get $c \\leq 0$ from which $c = 0$ must follow, due to $c \\geq \\nu(\\{c\\})=0$.\n", | ||
"Now we can substitute $c=0$ into (II) and (III) to get $a \\geq 400$ and $b \\geq 350$.\n", | ||
"Thus $a + b \\geq 750$ which is a contradiction to (IV), showing the **core is empty**.\n", | ||
"This can be seen visually in the following plot.\n", | ||
"\n", | ||
".. image:: _static/paper_game.pdf\n", | ||
"\n", | ||
"Notice that the line of equality (I) corresponds exactly to those payoff distributions which have $c=0$.\n", | ||
"Due to that (I), (II) and (III) do not enclose an area, which is why the core is empty." | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"## The least-Core\n", | ||
"Due to the core being empty, we introduce a related concept **the least-core**.\n", | ||
"Firstly lets define the **e-core** to be the payoff distributions, which are stable up to a given $e$.\n", | ||
"\n", | ||
"$$\n", | ||
" \\mathcal{C_e} := \\{ \\psi(N,\\nu) | \\forall S\\subseteq N. \\sum_{i \\in S} \\psi(N,\\nu)_i + e \\geq v(S) \\land \\sum_{i \\in N} \\psi(N,\\nu)_i = \\nu(N) \\}\n", | ||
"$$\n", | ||
"\n", | ||
"Then the least-core is the minimal $e$ such that $\\mathcal{C_e}$ is not empty.\n", | ||
"We can think of this subsidy $e$ as an external payment for cooperating.\n", | ||
"In our example the professor may encourage the Alice and Bob to include Charlie in their work by giving everybody an incentive \\$$e$.\n", | ||
"In comparison to the Shapley value the (least-)core may contain multiple payoff distributions.\n", | ||
"Often we are interested in a single payoff distribution, for which we choose the **egalitarian-least-core**.\n", | ||
"Given the least-core $C_{e^*}$ the egalitarian-least-core is $x \\in C_{e^*}$ with minimal $||x||_2$.\n", | ||
"It is important to note that the least-core **always exists** whereas the core is potentially empty.\n" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"## The least-Core of Writing a Paper\n", | ||
"Computing the least-core for our example can become quite tedious as solving linear inequalities is required.\n", | ||
"To simplify the process we use the *ExactComputer* from the *shapiq* package.\n" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"from shapiq.exact import ExactComputer\n", | ||
"from shapiq.games.base import Game\n", | ||
"\n", | ||
"\n", | ||
"# Define the PaperGame as described above\n", | ||
"class PaperGame(Game):\n", | ||
"\n", | ||
" def __init__(self) -> None:\n", | ||
" super().__init__(n_players=3, normalize=True, normalization_value=0)\n", | ||
"\n", | ||
" def value_function(self, coalitions: np.ndarray) -> np.ndarray:\n", | ||
" coalition_values = {\n", | ||
" (): 0,\n", | ||
" (0,): 0,\n", | ||
" (1,): 0,\n", | ||
" (2,): 0,\n", | ||
" (0, 1): 500,\n", | ||
" (0, 2): 400,\n", | ||
" (1, 2): 350,\n", | ||
" (0, 1, 2): 500,\n", | ||
" }\n", | ||
"\n", | ||
" values = np.array([coalition_values[tuple(np.where(x)[0])] for x in coalitions])\n", | ||
"\n", | ||
" return values\n", | ||
"\n", | ||
"\n", | ||
"paper_game = PaperGame()\n", | ||
"\n", | ||
"# Initialize the ExactComputer with the PaperGame\n", | ||
"exact_computer = ExactComputer(n_players=3, game_fun=paper_game)\n", | ||
"# Compute the egalitarian least core abbreviated to \"ELC\"\n", | ||
"egalitarian_least_core = exact_computer(\"ELC\")" | ||
], | ||
"metadata": { | ||
"collapsed": false, | ||
"ExecuteTime": { | ||
"end_time": "2024-10-04T17:04:48.123115Z", | ||
"start_time": "2024-10-04T17:04:48.116174Z" | ||
} | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"The egalitarian least core values can then be viewed with `.dict_values`." | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": "{(0,): 233.3333333333333, (1,): 183.33333333333337, (2,): 83.33333333333334}" | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"egalitarian_least_core.dict_values" | ||
], | ||
"metadata": { | ||
"collapsed": false, | ||
"ExecuteTime": { | ||
"end_time": "2024-10-04T17:04:48.128619Z", | ||
"start_time": "2024-10-04T17:04:48.123472Z" | ||
} | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"These values then correspond to the following payoff distribution:\n", | ||
"\n", | ||
"| Authos | egalitarian least-core |\n", | ||
"|-----------------|---------------|\n", | ||
"| Alice | \\$ $233.\\bar{3}$ |\n", | ||
"| Bob | \\$ $183.\\bar{3}$ |\n", | ||
"| Charlie | \\$ $83.\\bar{3}$ |\n", | ||
"\n", | ||
"The minimal $e$ is stored in `exact_computer._elc_stability_subsidy`." | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": "83.33333333333334" | ||
}, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"exact_computer._elc_stability_subsidy" | ||
], | ||
"metadata": { | ||
"collapsed": false, | ||
"ExecuteTime": { | ||
"end_time": "2024-10-04T17:04:48.128991Z", | ||
"start_time": "2024-10-04T17:04:48.128403Z" | ||
} | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Visualizing the egalitarian least-core in the plot we get the following:\n", | ||
"\n", | ||
".. image:: _static/elc_paper_game.pdf" | ||
], | ||
"metadata": { | ||
"collapsed": false | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
# this requirements.txt file is maintained and bumbped by dependabot | ||
# this file is used to see weather new versions of the libraries are available and break shapiq | ||
black==24.8.0 | ||
black==24.10.0 | ||
colour==0.1.5 | ||
coverage==7.6.1 | ||
coverage==7.6.3 | ||
matplotlib==3.9.2 | ||
networkx==3.3.0 | ||
networkx==3.4.1 | ||
pandas==2.2.3 | ||
pytest==8.3.3 | ||
ruff==0.6.9 | ||
ruff==0.7.0 | ||
scikit-image==0.24.0 | ||
scikit-learn==1.5.2 | ||
scipy==1.14.1 | ||
shap==0.46.0 | ||
tqdm==4.66.5 | ||
torch==2.4.0 | ||
torchvision==0.19.0 | ||
transformers==4.44.2 | ||
torch==2.5.0 | ||
torchvision==0.20.0 | ||
transformers==4.45.2 | ||
xgboost==2.1.1 | ||
numpy==1.26.4 | ||
requests==2.32.3 |
Oops, something went wrong.