Skip to main content

Teaching toolkit for the ELTE Game Theory course: solvers, game library, and Jupyter-friendly visualizations.

Project description

gtlab - Game Theory Lab

CI PyPI Python License: MIT

A teaching toolkit for the ELTE Game Theory course. It consolidates the solvers, example games, and Jupyter visualizations that previously lived (duplicated) in six separate Colab notebooks into one installable, extensible package.

Install

pip install -e ".[full]"     # full = nashpy + pulp extras (recommended in Colab)
pip install -e .             # core only (numpy / scipy / matplotlib / pandas)

Quick start

import gtlab
gtlab.apply_rc()                         # shared matplotlib styling (call once)

from gtlab.games import prisoners_dilemma
prisoners_dilemma().solve()              # annotated bimatrix in a Jupyter cell

Build your own game:

import numpy as np
from gtlab import NormalFormGame

g = NormalFormGame(
    A=np.array([[3, 0], [5, 1]]),
    B=np.array([[3, 5], [0, 1]]),
    row_actions=["Cooperate", "Defect"],
    col_actions=["Cooperate", "Defect"],
    name="My Game",
)
g.explain()

Architecture

The design separates the three concerns that were tangled together in the notebooks:

gtlab/
├── core/      game classes - hold data, expose a thin API
│   ├── normal_form.py      NormalFormGame
│   ├── zero_sum.py         ZeroSumGame
│   ├── correlated.py       CorrelatedGame
│   ├── stochastic.py       StochasticGame
│   ├── extensive_form.py   ExtensiveFormGame
│   └── bayesian.py         PostedPrice, FirstPriceAuction, SecondPriceAuction
├── solvers/   pure algorithms - numpy in, numpy/dict out, no display
│   ├── best_response.py    nash.py          dominance.py
│   ├── pareto.py           linprog.py       value_iteration.py
│   ├── welfare.py          learning.py      correlated.py
├── viz/       display layer - ONE theme, formatters, HTML, plots
│   ├── theme.py  format.py  html.py  plots.py
└── games/     ready-made example games + REGISTRY

Rule of thumb: math goes in solvers/, rendering goes in viz/, and the classes in core/ just wire them together. A theme tweak is one edit in viz/theme.py; a new algorithm is one file in solvers/; a new example is one factory in games/.

Extending

To add… …do this
a new example game write a factory in games/, add it to REGISTRY
a new algorithm add a pure function in solvers/, export it
a new game type add a class in core/ that calls solvers + viz
restyle output edit viz/theme.py (colors / CSS / rcParams)

Tests

pip install -e ".[dev]"
pytest

The solver layer has golden-value tests so refactors stay behavior-preserving.

Notebook migration

Each lecture notebook drops its ~2,000-line engine class and imports from gtlab instead, keeping only narrative and example-specific calls. As of 0.2.0 the package covers the full notebook surface: every solver, plot (plot_tree, plot_mixed, plot_frontier, ...), parameter sweep, styled walkthrough (explain, iesds_explain, *_detail, verify_*), Monte-Carlo simulate, and the GeneralSumSG / CheapTalkGame models. The methods the notebooks relied on (.summary(), .solve(), .explain(), .plot_*()) are preserved on the core classes.

# old: 1,800 lines of NormalFormGame defined inline
# new:
from gtlab.games import prisoners_dilemma
prisoners_dilemma().solve(show_br=True, show_ne=True)

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

gtlab-0.2.5.tar.gz (102.5 kB view details)

Uploaded Source

Built Distribution

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

gtlab-0.2.5-py3-none-any.whl (108.3 kB view details)

Uploaded Python 3

File details

Details for the file gtlab-0.2.5.tar.gz.

File metadata

  • Download URL: gtlab-0.2.5.tar.gz
  • Upload date:
  • Size: 102.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gtlab-0.2.5.tar.gz
Algorithm Hash digest
SHA256 69336074777a8c3d8e81b816baddc450ff3851d06db3068eae51cae101ef0985
MD5 ee4a9e7b07c32645d3e6c4d153624516
BLAKE2b-256 03c90e80a67c0a9749bc8331a36b5c5a1a42e9da1d79e86d0f5f93ca449f9d03

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtlab-0.2.5.tar.gz:

Publisher: publish.yml on tamastheactual/gtlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gtlab-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: gtlab-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 108.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gtlab-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 64cc1c010bab79db44199aa56cb25f50781e39b39d014eb1891cf977c92c0aea
MD5 497d657dd90ef4fccb35af975e9f5d3f
BLAKE2b-256 9d744994b353ecd9b4a817c8938b0ec2cb866435896e24fb888e4308bd89fcfd

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtlab-0.2.5-py3-none-any.whl:

Publisher: publish.yml on tamastheactual/gtlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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