Skip to main content

Shapley-Numba - computations cooperational games using Numba. Author and compute computational games. Package provides: - Shapley Values - Harsanyi Dividends (a.k.a. synergies)

Project description

Shapley Numba

Pipeline Status Coverage Python Version License: MIT-0 Documentation Code style: ruff

Numba-based computations for cooperative games.

Installation

pip:

pip install --index-url https://gitlab.com/api/v4/groups/shapley-numba/-/packages/pypi/simple shapley-numba

uv

uv add --index-url https://gitlab.com/api/v4/groups/shapley-numba/-/packages/pypi/simple shapley-numba

Dependencies

shapley-numba package depends only on numba and numpy.

Features

  • Fast exact Shapley calculation.
  • Shapley Monte Carlo approximation.
  • Harsanyi Dividends (synergies) computation.
  • Set iteration tools.
  • Game authoring tools and game templates.

Quickstart

See tutorial notebook for quick start.

Usage

This package is intended to compute quantities associated with cooperative games. Currently we want to implement two functions:

  1. Shapley values
  2. Harsanyi dividends, also called synergies.

This package also provides tools to author and modify cooperative games, such as game templates.

A game is a class that implements value method. The value method should accept a numpy array of zeros and ones indicating membership of each element in the subset.

The intended use of the package is for games where each computation of value is relatively cheap. This allows to speed up such computations using numba.

For optimal performance, the game should be written so that it can be compiled using numba.experimental.jitclass compiler. That way, numba compiled functions can be applied. Otherwise, a python fallback will be applied.

The basic usage is as follows:

from shapley_numba.shapley import shapley
from shapley_numba.examples import GloveGame
glove_game = GloveGame(num_left_gloves=1)
shapley(glove_game, num_players=3)

See documentation for detailed reference.

Credits

Dimitry Offengenden participated in development of this code and contributed several game examples.

This code was developed with assistance from Google Gemini Code Assist (version 2.52.0).

This code was developed with assistance from Claude Code.

Alternatives

  • SHAP applies Shapley values to machine learning models but can be used in conjunction with any game.

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_numba-0.0.1.tar.gz (174.9 kB view details)

Uploaded Source

Built Distribution

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

shapley_numba-0.0.1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file shapley_numba-0.0.1.tar.gz.

File metadata

  • Download URL: shapley_numba-0.0.1.tar.gz
  • Upload date:
  • Size: 174.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for shapley_numba-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8b3d21b4c904dee17e02d9f5a7184faa1bd59f5b6f3584db003ad0aae1ab82f5
MD5 5653ded68db7d42ca9560ecfda9fa26d
BLAKE2b-256 bfee311700bee7b2ae84dd2d9610e5261c9fe4e8bda21dfb3c955d9c61306f96

See more details on using hashes here.

File details

Details for the file shapley_numba-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: shapley_numba-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for shapley_numba-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 95745c3574e6e1e097d6cdadbaefcdf10c5be3dd6e2d752141560f9d9c1887fa
MD5 b7b265cb086e0256bf25c84210b8f20d
BLAKE2b-256 46eb35554dca527a6ab6509086d71ac114c75f92f385130762efd57ff40b20bb

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