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.3.tar.gz (99.0 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.3-py3-none-any.whl (105.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gtlab-0.2.3.tar.gz
  • Upload date:
  • Size: 99.0 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.3.tar.gz
Algorithm Hash digest
SHA256 6ba94a0632d6222f48d4c57eb5914ce7a50be85eedc486941f847c8bb5d61c8b
MD5 ce94e2346b0e4d78b1af3a12e850b00d
BLAKE2b-256 aa9eb1db4d8433d8d7cc7ddad48dd46d0561374da62d95e1eb5bd4f48741d68c

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtlab-0.2.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: gtlab-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 105.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 16f254b6d79f276496d15ae746c86c73a2cd89aaffd608ab472f2e6ac5ad6827
MD5 aa6a0c38af97b5cfaf7477a2c9d7a9df
BLAKE2b-256 4d5010fd49aeeb727227b3fe1aa4eadbdc837ef0c544c41441f2a95607cb7e3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtlab-0.2.3-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