Skip to main content

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

  1. Fork the repository.
  2. Make your changes.
  3. Commit your changes.
  4. Open a pull request.

Authors

  • newbie

Version History

  • 0.0.2: Initial release

Project details


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)

Uploaded Source

Built Distribution

shapley_value-0.0.3-py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page