nash_cp

jlgametheory.nash_cp(g, *, init=None, full_output=False, **options)[source]

Compute one mixed-action Nash equilibrium of an N-player normal form game by solving the complementarity problem formulation as a nonlinear program.

This function calls nash_cp of StrategicGames.jl, which solves the nonlinear program with Ipopt.

Parameters

gNormalFormGame

NormalFormGame instance with N >= 2 players.

initarray_like(array_like(float, ndim=1)), optional(default=None)

Initial mixed-action profile, an array of N arrays of floats. If None, the uniform mixed action is used for every player.

full_outputbool, optional(default=False)

If False, only the computed Nash equilibrium is returned. If True, the return value is (NE, res), where res is a NashResult object.

options :

Optional keyword arguments to pass to StrategicGames.nash_cp. See the StrategicGames.jl documentation for details.

Returns

NEtuple(ndarray(float, ndim=1))

Tuple of computed Nash equilibrium mixed actions. None if the solver did not return a solution.

resNashResult

Object containing the information about the result, returned only when full_output is True, with the following attributes: NE (same as NE above), status (termination status of the solver as a string), and expected_payoffs (ndarray of the payoffs of the players at NE, empty if NE is None).

Examples

Consider the 3-player 2-action game with 9 Nash equilibria in McKelvey and McLennan (1996) “Computation of Equilibria in Finite Games”:

>>> import numpy as np
>>> import quantecon.game_theory as gt
>>> import jlgametheory as jgt
>>> np.set_printoptions(precision=3)  # Reduce the digits printed
>>> g = gt.NormalFormGame((2, 2, 2))
>>> g[0, 0, 0] = 9, 8, 12
>>> g[1, 1, 0] = 9, 8, 2
>>> g[0, 1, 1] = 3, 4, 6
>>> g[1, 0, 1] = 3, 4, 4
>>> NE = jgt.nash_cp(g)
>>> NE
(array([0.5, 0.5]), array([0.5, 0.5]), array([ 1.000e+00, -1.353e-32]))
>>> g.is_nash(NE, tol=1e-5)  # Relax tolerance
True