Skip to main content

A package for computing semivalues.

Project description

This package offers tools for computing semivalues, with the Shapley value being the most prominent example. It places special emphasis on graph-based games, without being restricted to it.

Broad Functionality:

  • Compute Shapley/Banzhaf value exact or approximately
  • Compute decomposition matrices

Detailed Functionality:

  • Compute Shapley/Banzhaf value (exact and approximately)
  • Compute Shapley/Banzhaf value decomposition by size (exact and approximately) (n x n matrix where each entry is aggregated over the respective subset size)
  • Compute Shapley value of a player to another player (exact and approximately) (Hausken, Kjell, and Matthias Mohr. "The value of a player in n-person games." Social Choice and Welfare 18 (2001): 465-483.)

For the approximation methods of the Shapley value we refer to https://arxiv.org/pdf/1306.4265

How To Use

You need to have a utility function mapping an arbitrary set of players to a real number. Players names should be {0, ..., n-1}, i.e. the utility function should return values for all subsets of {0, ..., n-1}. We will use the example introduced here

def utility_game_function(S):
    GAME_VALUES = {
        frozenset(): 0,
        frozenset({0}): 180,
        frozenset({1}): 0,
        frozenset({2}): 0,
        frozenset({1, 2}): 0,
        frozenset({0, 1}): 360,
        frozenset({0, 2}): 540,
        frozenset({0, 1, 2}): 540,
    }

    def game_utility(coalition: set) -> int:
        return GAME_VALUES.get(frozenset(coalition), 0)

    return game_utility(S)


num_players = 3

from semivalues import shapley, banzhaf
# (n-vector)
shapley.exact(utility_game_function=utility_game_function, num_players=num_players)
shapley.strata_sampling(utility_game_function=utility_game_function, num_players=num_players, num_samples=100000)

banzhaf.exact(utility_game_function=utility_game_function, num_players=num_players)
banzhaf.sampling(utility_game_function=utility_game_function, num_players=num_players, num_samples=100000)


from semivalues.decompositions.shapley import by_size
# (n x n matrix)
by_size.exact(utility_game_function=utility_game_function, num_players=num_players)
by_size.strata_sampling(utility_game_function=utility_game_function, num_players=num_players, num_samples=100000)

from semivalues.decompositions.banzhaf import by_size
# (n x n matrix)
by_size.exact(utility_game_function=utility_game_function, num_players=num_players)
by_size.monte_carlo_sampling(utility_game_function=utility_game_function, num_players=num_players, num_samples=100000)


from semivalues.decompositions.shapley import player_to_player
# (n x n matrix)
player_to_player.exact(utility_game_function=utility_game_function, num_players=num_players)
player_to_player.monte_carlo_sampling(utility_game_function=utility_game_function, num_players=num_players, num_samples=100000)

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

semivalues-0.0.13.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

semivalues-0.0.13-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file semivalues-0.0.13.tar.gz.

File metadata

  • Download URL: semivalues-0.0.13.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for semivalues-0.0.13.tar.gz
Algorithm Hash digest
SHA256 bd3f637397efed23b9d7749c0901d6ffa0a8fd2b672ebf34ae1daa4d429559ec
MD5 6c338efb5eb5b9f22d8e1f432a4b76d4
BLAKE2b-256 f2f2a9507e8c861920cf2875b692e242d7a122e08db271f931d7788fb881bd69

See more details on using hashes here.

File details

Details for the file semivalues-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: semivalues-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.4

File hashes

Hashes for semivalues-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 d3cb3d26a0f8df521600966f038cac8362d23924ad43cff18d641656dd007793
MD5 d0db41da52ade2c5803f7d35fccebc81
BLAKE2b-256 c7bedd70b6793a3397c69bbff3daf662307964326ab5f460d32fe81f38bd5b1a

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