coopgt
coopgt is a Python library for the study of cooperative game theory. It works
with characteristic function games and provides the Shapley value, checks of
standard properties (validity, monotonicity, superadditivity, convexity), and
core membership.
Installation
python -m pip install coopgt
Where to start
This documentation follows the Diátaxis framework.
- Tutorials. Step-by-step lessons for newcomers. Shapley value regression.
- How-to guides. Practical recipes for common tasks. Calculate the Shapley value and check the core.
- Reference. The complete API reference.
- Explanation. Background on cooperative games.
A first example
A characteristic function is a dictionary mapping each coalition (a tuple of players, numbered from 1) to its value:
>>> import coopgt.shapley_value
>>> characteristic_function = {
... (): 0,
... (1,): 0,
... (2,): 0,
... (1, 2): 10,
... }
>>> shapley = coopgt.shapley_value.calculate(characteristic_function)
>>> [round(float(value), 2) for value in shapley]
[5.0, 5.0]