Source files¶
Subpackages¶
Submodules¶
nashpy.game module¶
A class for a normal form game
-
class
nashpy.game.
Game
(*args)[source]¶ Bases:
object
A class for a normal form game.
- Parameters
A (-) – non zero sum games.
B (2 dimensional list/arrays representing the payoff matrices for) – non zero sum games.
A – zero sum game.
-
fictitious_play
(iterations, play_counts=None)[source]¶ Return a given sequence of actions through fictitious play. The implementation corresponds to the description of chapter 2 of [Fudenberg1998].
1. Players have a belief of the strategy of the other player: a vector representing the number of times the player has chosen a given strategy. 2. Players choose a best response to the belief. 3. Players update their belief based on the latest choice of the opponent.
- Parameters
iterations (int) –
play_counts (iterator) –
- Returns
plays
- Return type
A generator
-
lemke_howson
(initial_dropped_label)[source]¶ Obtain the Nash equilibria using the Lemke Howson algorithm implemented using integer pivoting.
Algorithm implemented here is Algorithm 3.6 of [Nisan2007].
Start at the artificial equilibrium (which is fully labeled)
Choose an initial label to drop and move in the polytope for which the vertex has that label to the edge that does not share that label. (This is implemented using integer pivoting)
A label will now be duplicated in the other polytope, drop it in a similar way.
Repeat steps 2 and 3 until have Nash Equilibrium.
- Parameters
initial_dropped_label (int) –
- Returns
equilibria
- Return type
A tuple.
-
lemke_howson_enumeration
()[source]¶ Obtain Nash equilibria for all possible starting dropped labels using the lemke howson algorithm. See Game.lemke_howson for more information.
Note: this is not guaranteed to find all equilibria.
- Returns
equilibria
- Return type
A generator
-
replicator_dynamics
(y0=None, timepoints=None)[source]¶ Implement replicator dynamics Return an array showing probability of each strategy being played over time. The total population is constant. Strategies can either stay constant if equilibria is achieved, replicate or die.
- Parameters
A (nxm array, where n=m) –
y0 (array) –
timepoints (array) –
- Returns
xs
- Return type
array
-
support_enumeration
(non_degenerate=False, tol=1e-16)[source]¶ Obtain the Nash equilibria using support enumeration.
Algorithm implemented here is Algorithm 3.4 of [Nisan2007].
For each k in 1…min(size of strategy sets)
For each I,J supports of size k
Solve indifference conditions
Check that have Nash Equilibrium.
- Returns
equilibria
- Return type
A generator.
-
vertex_enumeration
()[source]¶ Obtain the Nash equilibria using enumeration of the vertices of the best response polytopes.
Algorithm implemented here is Algorithm 3.5 of [Nisan2007].
Build best responses polytopes of both players
For each vertex pair of both polytopes
Check if pair is fully labelled
Return the normalised pair
- Returns
equilibria
- Return type
A generator.