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.4.tar.gz (99.2 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.4-py3-none-any.whl (105.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gtlab-0.2.4.tar.gz
  • Upload date:
  • Size: 99.2 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.4.tar.gz
Algorithm Hash digest
SHA256 8f663d3f75d146b93b0db47be73e8c79255cbeae993976ff6d5ac9e7a61f3d71
MD5 bf2832ae902fbfd5eabf0c350417f795
BLAKE2b-256 4767337cacf9f70d06e938360f931e01c39d08a33df595be0c4b48d458441402

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: gtlab-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 105.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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 322e4674d4a9aecc9f54f60f36355a2b2b9cbf1c9df0253e675b6ed04c4e8646
MD5 014507a2caae222c7861ce182b50ddb6
BLAKE2b-256 fad307bae19b508d1e5dd1cc41e5e054677891051c4bf60a3a8a82bd1939f5b6

See more details on using hashes here.

Provenance

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