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.1.tar.gz (96.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.1-py3-none-any.whl (102.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gtlab-0.2.1.tar.gz
  • Upload date:
  • Size: 96.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.1.tar.gz
Algorithm Hash digest
SHA256 49c6d5e62d0068539f4bc2bdfeaa9d28f30bfe89feebd7c7354cc7dde00c5dc0
MD5 9d41a921c4b0229398226ec86321b9f9
BLAKE2b-256 e9121e7f93b9ad2fa9bd1b8e810b1e44a74838e9b18a13b2beb337c149cfcfee

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: gtlab-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 102.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb8ecf8bf0041d41576b0ea501a7853d503197b626a5358598e669c276942a92
MD5 fe23aec942e11eae30f5cd35c813da92
BLAKE2b-256 0fa4f5fbfdeaa9fc6e4c6fb81b1570b3996d0ee6e430825aff26777a09a265b3

See more details on using hashes here.

Provenance

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