Nashpy
Nashpy is a Python library providing algorithms for computing Nash equilibria and analyzing 2-player games, including matrix games and repeated games. It is built on top of NumPy and SciPy for efficient numerical computation. Currently at version 0.0.43, the library maintains a frequent release cadence, typically with minor updates and bug fixes.
Warnings
- gotcha Payoff matrices for `nashpy.Game` must be `numpy.ndarray` objects. Passing plain Python lists directly will result in a `TypeError` or unexpected behavior.
- breaking As a `0.0.x` version library, Nashpy's API is subject to change without strict adherence to semantic versioning. Minor version updates (e.g., 0.0.42 to 0.0.43) may introduce breaking changes.
- gotcha Some algorithms, particularly `lemke_howson` and `lemke_howson_lex`, may struggle or fail to converge on degenerate games or games with specific numerical properties. The library's focus is on general case solution.
Install
-
pip install nashpy
Imports
- Game
import nashpy as nash game = nash.Game(A, B)
- VertexEnum
from nashpy.algorithms import support_enumeration
Quickstart
import nashpy as nash
import numpy as np
# Define payoff matrices for player 1 (A) and player 2 (B)
A = np.array([[3, 0], [5, 1]])
B = np.array([[3, 5], [0, 1]])
# Create a Nash game object
game = nash.Game(A, B)
# Compute Nash equilibria using support enumeration
equilibria = game.support_enumeration()
# Print the equilibria (mixed strategies for each player)
print("Nash Equilibria:")
for eq in equilibria:
print(eq)