Algorithms for computing the Shapley value in bankruptcy games
Project description
Shapley-Bankruptcy
Implementation of algorithms for computing the Shapley value in bankruptcy games. This repository contains implementations of algorithms proposed in the paper "On Computing the Shapley Value in Bankruptcy Games".
Overview
A bankruptcy game is a cooperative game where an estate of value E must be divided among creditors with claims w = (w₁, w₂, ..., wₙ). This implementation provides multiple efficient algorithms for computing the Shapley value in such games.
Installation
Requirements
- Python 3.11 or higher
- Poetry (for package management)
Setup
# Clone the repository
git clone <repository-url>
cd shapley-banckruptcy
# Install dependencies
poetry install
Usage
Basic Example
from algorithms import FastDPAlgorithm, MonteCarloAlgorithm, ExactSetAlgorithm
# Problem setup
E = 100 # Total estate value
w = [50, 60, 80] # Claims of each player
# Select an algorithm and compute
algorithm = FastDPAlgorithm()
algorithm.compute(E, w)
# Get results
shapley_values = algorithm.return_value()
computation_time = algorithm.return_time()
print(f"Shapley values: {shapley_values}")
print(f"Computation time: {computation_time} seconds")
Implemented Algorithms
1. ExactSetAlgorithm
An exact algorithm based on the definition of the Shapley value. It enumerates all subsets to compute the value.
from algorithms import ExactSetAlgorithm
algorithm = ExactSetAlgorithm()
algorithm.compute(E, w)
result = algorithm.return_value()
Features:
- Guarantees exact results
- Time complexity: O(2ⁿ × n)
- Suitable for small-scale problems
2. FastDPAlgorithm
A fast algorithm using dynamic programming.
from algorithms import FastDPAlgorithm
algorithm = FastDPAlgorithm()
algorithm.compute(E, w)
result = algorithm.return_value()
Features:
- Efficient computation using dynamic programming
- Suitable for medium to large-scale problems
3. FastRecursiveAlgorithm
A fast algorithm using recursive formulas.
from algorithms import FastRecursiveAlgorithm
algorithm = FastRecursiveAlgorithm()
algorithm.compute(E, w)
result = algorithm.return_value()
Features:
- Fast computation using recursive formulas with memoization
- Optimized by precomputing characteristic functions
4. FastDualRecursiveAlgorithm
A fast algorithm using dual recursive formulas.
from algorithms import FastDualRecursiveAlgorithm
algorithm = FastDualRecursiveAlgorithm()
algorithm.compute(E, w)
result = algorithm.return_value()
Features:
- Recursive computation using dual characteristic functions
- Fast computation with memoization
5. MonteCarloAlgorithm
An approximation algorithm using the Monte Carlo method.
from algorithms import MonteCarloAlgorithm
# Specify the number of samples (default: 10000)
algorithm = MonteCarloAlgorithm(M=50000, seed=42)
algorithm.compute(E, w)
result = algorithm.return_value()
Features:
- Fast computation even for large-scale problems
- Adjustable balance between accuracy and speed via the number of samples M
- Reproducible results with seed setting
Output Rounding
All algorithms can round results to a specified number of decimal places (default: 5 digits).
algorithm = FastDPAlgorithm(round_digits=3)
algorithm.compute(E, w)
result = algorithm.return_value() # Results rounded to 3 decimal places
Algorithm Details
For detailed descriptions and theoretical background of each algorithm, please refer to the paper "On Computing the Shapley Value in Bankruptcy Games".
Characteristic Function of Bankruptcy Games
The characteristic function v(S) of a bankruptcy game is defined as:
v(S) = max(0, E - Σ_{j∉S} wⱼ)
where E is the total estate value and wⱼ is the claim of player j.
Shapley Value
The Shapley value φᵢ for player i is defined as:
φᵢ = Σ_{S⊆N\{i}} (|S|!(n-|S|-1)!/n!) × [v(S∪{i}) - v(S)]
Performance
Choose an algorithm based on the problem size and accuracy requirements:
- Small-scale (n ≤ 10):
ExactSetAlgorithmis appropriate - Medium-scale (10 < n ≤ 20):
FastDPAlgorithmorFastRecursiveAlgorithmis recommended - Large-scale (n > 20):
MonteCarloAlgorithmis practical
License
See the LICENSE file for license information.
Author
ShuntaYamazaki (shuntaweb@gmail.com)
References
This is an implementation of algorithms proposed in the paper "On Computing the Shapley Value in Bankruptcy Games".
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shapley_bankruptcy-0.1.1.tar.gz.
File metadata
- Download URL: shapley_bankruptcy-0.1.1.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.11.9 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79f64713af74c7b8565d75b517377e0a30eb375681c9d19f5b689d5471ce5b69
|
|
| MD5 |
b4c95769b0e0dc3cfea9e658f8cf7cd7
|
|
| BLAKE2b-256 |
7026522c636c230cf091b5b8dc502c29a801c5f4f8907af0892dbe7dc47bef60
|
File details
Details for the file shapley_bankruptcy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: shapley_bankruptcy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.11.9 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10a3228b049af039a393cb79d9cda8cc8b057af4048635a92b9fe257d985c4ec
|
|
| MD5 |
7f64d1732be53281ea8052e2b6f72811
|
|
| BLAKE2b-256 |
b5dd640363e164899e24851387fa3ebfec5c95da7a41798581deda0886f260b8
|