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.6.tar.gz (106.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.6-py3-none-any.whl (110.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gtlab-0.2.6.tar.gz
  • Upload date:
  • Size: 106.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.6.tar.gz
Algorithm Hash digest
SHA256 f5691142aeba44db553a6be1048a46bc6bcb92bb489b8b8a1a5070aa8d4878c6
MD5 e12f070b9496208426cfb205fd46334f
BLAKE2b-256 e79bcc17836e1ab903a507d8b65ea5844053fa7b665106e595ebf883101f940b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: gtlab-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 110.7 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9ef8f829681bd3ce872d37c0525f502f124ccf19fe286a1c5e535f948337752d
MD5 b281e823482a26e91187775b20a48034
BLAKE2b-256 cbab443035d1858eae9603a3d31219098a0daebe6bb0c64a9726d48448a0a1b9

See more details on using hashes here.

Provenance

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