.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/game_theory/plot_core.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_game_theory_plot_core.py: The Core: A Different View on Explanation ========================================= This example introduces the game-theoretic concept of the *core* and the *egalitarian least core* (ELC), and shows how to compute them with :class:`~shapiq.ExactComputer`. .. GENERATED FROM PYTHON SOURCE LINES 9-16 .. code-block:: Python from __future__ import annotations import numpy as np import shapiq .. GENERATED FROM PYTHON SOURCE LINES 17-44 The Paper Game -------------- Three AI researchers (Alice, Bob, Charlie) co-author a paper that wins a $500 best-paper award. We model their joint productivity as a cooperative game: ========================= ===== Coalition Award ========================= ===== {} $0 {Alice} $0 {Bob} $0 {Charlie} $0 {Alice, Bob} $500 {Alice, Charlie} $400 {Bob, Charlie} $350 {Alice, Bob, Charlie} $500 ========================= ===== Shapley values give: Alice=$200, Bob=$175, Charlie=$125. But Alice and Bob could earn $250 each by excluding Charlie -- so the **core is empty**. The Least Core and ELC ~~~~~~~~~~~~~~~~~~~~~~ The *least core* finds the minimum subsidy :math:`e` that makes cooperation stable. The *egalitarian least core* picks the distribution with minimum :math:`\|x\|_2` from the least core. .. GENERATED FROM PYTHON SOURCE LINES 44-66 .. code-block:: Python class PaperGame(shapiq.Game): def __init__(self) -> None: super().__init__(n_players=3, normalize=True, normalization_value=0) def value_function(self, coalitions: np.ndarray) -> np.ndarray: values = { (): 0, (0,): 0, (1,): 0, (2,): 0, (0, 1): 500, (0, 2): 400, (1, 2): 350, (0, 1, 2): 500, } return np.array([values[tuple(np.where(x)[0])] for x in coalitions]) paper_game = PaperGame() .. GENERATED FROM PYTHON SOURCE LINES 67-69 Computing the Egalitarian Least Core ------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 69-75 .. code-block:: Python exact_computer = shapiq.ExactComputer(n_players=3, game=paper_game) elc = exact_computer("ELC") print("ELC payoffs:", elc.dict_values) print("Stability subsidy e*:", exact_computer._elc_stability_subsidy) .. rst-class:: sphx-glr-script-out .. code-block:: none ELC payoffs: {(0,): 233.33333333333323, (1,): 183.33333333333337, (2,): 83.33333333333336} Stability subsidy e*: 83.33333333333341 .. GENERATED FROM PYTHON SOURCE LINES 76-78 The ELC distributes approximately: Alice $233, Bob $183, Charlie $83, with a stability subsidy of about $83. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.017 seconds) .. _sphx_glr_download_auto_examples_game_theory_plot_core.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_core.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_core.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_core.zip `