Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/pypa/gh-action-pyp…
Browse files Browse the repository at this point in the history
…i-publish-1.10.3
  • Loading branch information
mmschlk authored Oct 18, 2024
2 parents f71ddd7 + 5da33bc commit 5c6a2b3
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/source/_static/css/custom.css
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;
}
3 changes: 3 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = "furo"
html_static_path = ["_static"]
html_css_files = [
"css/custom.css",
]
html_favicon = "_static/shapiq.ico"
pygments_dark_style = "monokai"
html_theme_options = {
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Contents
notebooks/conditional_imputer
notebooks/parallel_computation
notebooks/benchmark_approximators
notebooks/core

.. toctree::
:maxdepth: 2
Expand Down
Binary file added docs/source/notebooks/_static/elc_paper_game.pdf
Binary file not shown.
Binary file added docs/source/notebooks/_static/paper_game.pdf
Binary file not shown.
308 changes: 308 additions & 0 deletions docs/source/notebooks/core.ipynb
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
}

0 comments on commit 5c6a2b3

Please sign in to comment.