Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1005 Bytes

calculate-the-shapley-value.rst

File metadata and controls

44 lines (33 loc) · 1005 Bytes

Calculate the Shapley value

To find the :ref:`Shapley value <definition-of-shapley-value>` for a game G=(N, v) use coopgt.shapley_value.calculate.

For example for G=(3, v):

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}

First :ref:`create the characteristic function <create_a_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
>>> coopgt.shapley_value.calculate(characteristic_function=characteristic_function)
array([ 2.,  5., 35.])