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
  • 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): ExactSetAlgorithm is appropriate
  • Medium-scale (10 < n ≤ 20): FastDPAlgorithm or FastRecursiveAlgorithm 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_banckruptcy-0.1.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

shapley_banckruptcy-0.1.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file shapley_banckruptcy-0.1.0.tar.gz.

File metadata

  • Download URL: shapley_banckruptcy-0.1.0.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

Hashes for shapley_banckruptcy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dfc1a4988c8219e845849791df66a720ea2a17ccce9b73412cc9462806b1b5e7
MD5 50a743ac2e40df03b8b4c671ea97723e
BLAKE2b-256 dc2d0be609ed6f0c46aed67fa464a04b22fbcf00ddbfd02c551fa5270284cd8b

See more details on using hashes here.

File details

Details for the file shapley_banckruptcy-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shapley_banckruptcy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3d4437af0aa2b96e5f91e8e786de4b7940306735407375c9edbc209f865087d
MD5 f42708b75c6047da4f828a85cd1ad7b9
BLAKE2b-256 caf7c0125f4d3ac8c1fee8b17dacb4358a43094af2209ce09747c5567ba1fdc6

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