Calculate the marginal contribution of a playerΒΆ

To find the marginal contribution \(\Delta_\pi^G(i)\) of a player \(i\) for a permutation \(\pi\) in a game \(G=(N, v)\) use coopgt.shapley_value.marginal_contribution.

For example for \(G=(3, v)\) and \(\pi=(3, 2, 1)\) to find \(\Delta_\pi^G(i)(1)\):

\[\begin{split}v(C)=\begin{cases} 0,&\text{if }C=\emptyset\\ 6,&\text{if }C=\{1\}\\ 12,&\text{if }C=\{2\}\\ 42,&\text{if }C=\{3\}\\ 12,&\text{if }C=\{1,2\}\\ 42,&\text{if }C=\{2,3\}\\ 42,&\text{if }C=\{1,2,3\}\\ \end{cases}\end{split}\]

First create the characteristic function:

>>> characteristic_function = {
...     (): 0,
...     (1,): 6,
...     (2,): 12,
...     (3,): 42,
...     (1, 2): 12,
...     (1, 3): 42,
...     (2, 3): 42,
...     (1, 2, 3): 42,
... }

Then:

>>> import coopgt.shapley_value
>>> pi = (3, 2, 1)
>>> coopgt.shapley_value.marginal_contribution(
...     characteristic_function=characteristic_function, permutation=pi, i=1
... )
0