Shapley Value Calculator
Project description
Shapley Value Calculator
Overview
This Python package calculates Shapley values for cooperative game theory. Shapley values provide a fair way to distribute the total payoff among players in a cooperative game, based on their individual contributions.
Installation
Using pip:
pip install shapley-value
Usage
Basic Example
from shapley_value import ShapleyCombinations
players = ['A', 'B', 'C']
coalition_values = {
('A',): 10,
('B',): 20,
('C',): 30,
('A', 'B'): 50,
('A', 'C'): 60,
('B', 'C'): 70,
('A', 'B', 'C'): 100
}
shapley_combinations = ShapleyCombinations(players)
shapley_values = shapley_combinations.calculate_shapley_values(coalition_values)
print(shapley_values)
from shapley_value import ShapleyValueCalculator
# Example usage
def evaluation_function(coalition):
# Example evaluation function: sum of player values
return sum(value for value in coalition)
players = [10, 20, 30]
calculator = ShapleyValueCalculator(evaluation_function, players, num_jobs=-1)
shapley_values = calculator.calculate_shapley_values()
print(shapley_values)
raw_data = calculator.get_raw_data()
print(raw_data)
calculator.save_raw_data('sample_shapley_raw_data.csv')
Features
- Calculates Shapley values for cooperative games
- Supports any number of players
- Handles coalition values as a dictionary
- Includes example usage
Requirements
- Python 3.x
itertools
module
License
MIT License
Contributing
- Fork the repository.
- Make your changes.
- Commit your changes.
- Open a pull request.
Authors
- newbie
Version History
- 0.0.2: Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
shapley-value-0.0.3.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for shapley_value-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93a43af7bbbf5012cfeb71edee4415e84d308d3a2abd22b065f8adf2b05aecf7 |
|
MD5 | cdc9eeaa94b8bc7b7fc0b83bcbc5ae4f |
|
BLAKE2b-256 | ecf79158bd95b78dcf005037f1b29583b8abf9700c0140c610cd4a87c0831fee |