Source files

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.

asymmetric_replicator_dynamics(x0=None, y0=None, timepoints=None)[source]

Returns two arrays, corresponding to the two players, showing the probability of each strategy being played over time using the asymmetric replicator dynamics algorithm.

Parameters
  • x0 (array, optional) –

  • y0 (array, optional) –

  • timepoints (array, optional) –

Returns

  • xs1 (array)

  • xs2 (array)

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].

  1. Start at the artificial equilibrium (which is fully labeled)

  2. 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)

  3. A label will now be duplicated in the other polytope, drop it in a similar way.

  4. 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

stochastic_fictitious_play(iterations, play_counts=None, etha=0.1, epsilon_bar=0.01)[source]

Return a given sequence of actions and mixed strategies through stochastic fictitious play. The implementation corresponds to the description given in [Hofbauer2002].

Parameters
  • iterations (int) –

  • play_counts (iterator) –

  • etha (float) –

  • epsilon_bar (float) –

Returns

plays

Return type

A generator

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].

  1. For each k in 1…min(size of strategy sets)

  2. For each I,J supports of size k

  3. Solve indifference conditions

  4. 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].

  1. Build best responses polytopes of both players

  2. For each vertex pair of both polytopes

  3. Check if pair is fully labelled

  4. Return the normalised pair

Returns

equilibria

Return type

A generator.

Module contents

A library to compute equilibria of 2 player normal form games