Skip to main content

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

Install from PyPI

pip install shapley-bankruptcy

Install from source

# Clone the repository
git clone <repository-url>
cd shapley-banckruptcy

# Install dependencies
pip install -e .

Usage

Basic Example

from shapley_bankruptcy.algorithms import (
    DynamicProgrammingAlgorithm,
    MonteCarloAlgorithm,
    ExactAlgorithm
)

# Problem setup
E = 100  # Total estate value
w = [50, 60, 80]  # Claims of each player

# Select an algorithm and compute
algorithm = DynamicProgrammingAlgorithm()
result = algorithm.compute(E, w)

# Get results
shapley_values = result.value
computation_time = result.elapsed_time

print(f"Shapley values: {shapley_values}")
print(f"Computation time: {computation_time} seconds")

Implemented Algorithms

1. ExactAlgorithm

An exact algorithm based on the definition of the Shapley value. It enumerates all subsets to compute the value.

from shapley_bankruptcy.algorithms import ExactAlgorithm

algorithm = ExactAlgorithm()
result = algorithm.compute(E, w)
shapley_values = result.value

Features:

  • Guarantees exact results
  • Time complexity: O(2ⁿ × n)
  • Suitable for small-scale problems

2. DynamicProgrammingAlgorithm

A fast algorithm using dynamic programming.

from shapley_bankruptcy.algorithms import DynamicProgrammingAlgorithm

algorithm = DynamicProgrammingAlgorithm()
result = algorithm.compute(E, w)
shapley_values = result.value

Features:

  • Efficient computation using dynamic programming
  • Suitable for medium to large-scale problems

3. RecursiveAlgorithm

A fast algorithm using recursive formulas.

from shapley_bankruptcy.algorithms import RecursiveAlgorithm

algorithm = RecursiveAlgorithm()
result = algorithm.compute(E, w)
shapley_values = result.value

Features:

  • Fast computation using recursive formulas with memoization
  • Optimized by precomputing characteristic functions

4. RecursiveDualAlgorithm

A fast algorithm using dual recursive formulas.

from shapley_bankruptcy.algorithms import RecursiveDualAlgorithm

algorithm = RecursiveDualAlgorithm()
result = algorithm.compute(E, w)
shapley_values = result.value

Features:

  • Recursive computation using dual characteristic functions
  • Fast computation with memoization

5. MonteCarloAlgorithm

An approximation algorithm using the Monte Carlo method.

from shapley_bankruptcy.algorithms import MonteCarloAlgorithm

# Specify the number of samples (default: 10000)
algorithm = MonteCarloAlgorithm(M=50000, seed=42)
result = algorithm.compute(E, w)
shapley_values = result.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 = DynamicProgrammingAlgorithm(round_digits=3)
result = algorithm.compute(E, w)
shapley_values = result.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): ExactAlgorithm is appropriate
  • Medium-scale (10 < n ≤ 20): DynamicProgrammingAlgorithm or RecursiveAlgorithm is recommended
  • Large-scale (n > 20): MonteCarloAlgorithm is 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

shapley_bankruptcy-0.1.4.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shapley_bankruptcy-0.1.4-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file shapley_bankruptcy-0.1.4.tar.gz.

File metadata

  • Download URL: shapley_bankruptcy-0.1.4.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.9 Windows/10

File hashes

Hashes for shapley_bankruptcy-0.1.4.tar.gz
Algorithm Hash digest
SHA256 d59cd5bc181f8efa58da3d24c6ad15f6a804c5f962ed566ddf60ce643b8e7097
MD5 3d87bd38d1957e0dd43aa880c1f863b6
BLAKE2b-256 e34b7035a1a5b80e6b9b9356c3e1a4cbd187a20986b7eaadb3a82b87d474c41d

See more details on using hashes here.

File details

Details for the file shapley_bankruptcy-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for shapley_bankruptcy-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9d6da9fe8c0426748d480e929cc3935848788e3797fa4fda2f4ef7c0f7ee319a
MD5 3a8045d3318eb8c45e88c0443adf8763
BLAKE2b-256 a18f2dbc9567d4ae0406460931e655b6643fbbedc254ebba7a012604f26399ef

See more details on using hashes here.

Supported by

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