<commit_before>"""
Author: <NAME>

Compute mixed Nash equilibria of an N-player normal form game by
applying the imitation game algorithm by McLennan and Tourky to the best
response correspondence.

"""
import numbers
import numpy as np
from ..compute_fp import _compute_fixed_point_ig
from .normal_form_game import pure2mixed
from .utilities import NashResult


def mclennan_tourky(g, init=None, epsilon=1e-3, max_iter=200,
                    full_output=False):
    r"""
    Find one mixed-action epsilon-Nash equilibrium of an N-player normal
    form game by the fixed point computation algorithm by McLennan and
    Tourky [1]_.

    Parameters
    ----------
    g : NormalFormGame
        NormalFormGame instance.

    init : array_like(int or array_like(float, ndim=1)),
           optional(default=None)
        Initial action profile, an array of N objects, where each object
        must be an iteger (pure action) or an array of floats (mixed
        action). If None, default to an array of zeros (the zero-th
        action for each player).

    epsilon : scalar(float), optional(default=1e-3)
        Value of epsilon-optimality.

    max_iter : scalar(int), optional(default=100)
        Maximum number of iterations.

    full_output : bool, optional(default=False)
        If False, only the computed Nash equilibrium is returned. If
        True, the return value is `(NE, res)`, where `NE` is the Nash
        equilibrium and `res` is a `NashResult` object.

    Returns
    -------
    NE : tuple(ndarray(float, ndim=1))
        Tuple of computed Nash equilibrium mixed actions.

    res : NashResult
        Object containing information about the computation. Returned
        only when `full_output` is True. See `NashResult` for details.

    Examples
    --------
    Consider the following version of 3-player "anti-coordination" game,
    where action 0 is a safe action which yields payoff 1, while action
    1 yields payoff :math:`v` if no other player plays 1 and payoff 0
    otherwise:

    >>> N = 3
    >>> v = 2
    >>> payoff_array = np.empty((2,)*n)
    >>> payoff_array[0, :] = 1
    >>> payoff_array[1, :] = 0
    >>> payoff_array[1].flat[0] = v
    >>> g = NormalFormGame((Player(payoff_array),)*N)
    >>> print(g)
    3-player NormalFormGame with payoff profile array:
    [[[[ 1.,  1.,  1.],   [ 1.,  1.,  2.]],
      [[ 1.,  2.,  1.],   [ 1.,  0.,  0.]]],

     [[[ 2.,  1.,  1.],   [ 0.,  1.,  0.]],
      [[ 0.,  0.,  1.],   [ 0.,  0.,  0.]]]]

    This game has a unique symmetric Nash equilibrium, where the<commit_msg>DOC: Remove a blank line from Examples<commit_after>"""
Author: <NAME>

Compute mixed Nash equilibria of an N-player normal form game by
applying the imitation game algorithm by McLennan and Tourky to the best
response correspondence.

"""
import numbers
import numpy as np
from ..compute_fp import _compute_fixed_point_ig
from .normal_form_game import pure2mixed
from .utilities import NashResult


def mclennan_tourky(g, init=None, epsilon=1e-3, max_iter=200,
                    full_output=False):
    r"""
    Find one mixed-action epsilon-Nash equilibrium of an N-player normal
    form game by the fixed point computation algorithm by McLennan and
    Tourky [1]_.

    Parameters
    ----------
    g : NormalFormGame
        NormalFormGame instance.

    init : array_like(int or array_like(float, ndim=1)),
           optional(default=None)
        Initial action profile, an array of N objects, where each object
        must be an iteger (pure action) or an array of floats (mixed
        action). If None, default to an array of zeros (the zero-th
        action for each player).

    epsilon : scalar(float), optional(default=1e-3)
        Value of epsilon-optimality.

    max_iter : scalar(int), optional(default=100)
        Maximum number of iterations.

    full_output : bool, optional(default=False)
        If False, only the computed Nash equilibrium is returned. If
        True, the return value is `(NE, res)`, where `NE` is the Nash
        equilibrium and `res` is a `NashResult` object.

    Returns
    -------
    NE : tuple(ndarray(float, ndim=1))
        Tuple of computed Nash equilibrium mixed actions.

    res : NashResult
        Object containing information about the computation. Returned
        only when `full_output` is True. See `NashResult` for details.

    Examples
    --------
    Consider the following version of 3-player "anti-coordination" game,
    where action 0 is a safe action which yields payoff 1, while action
    1 yields payoff :math:`v` if no other player plays 1 and payoff 0
    otherwise:

    >>> N = 3
    >>> v = 2
    >>> payoff_array = np.empty((2,)*n)
    >>> payoff_array[0, :] = 1
    >>> payoff_array[1, :] = 0
    >>> payoff_array[1].flat[0] = v
    >>> g = NormalFormGame((Player(payoff_array),)*N)
    >>> print(g)
    3-player NormalFormGame with payoff profile array:
    [[[[ 1.,  1.,  1.],   [ 1.,  1.,  2.]],
      [[ 1.,  2.,  1.],   [ 1.,  0.,  0.]]],
     [[[ 2.,  1.,  1.],   [ 0.,  1.,  0.]],
      [[ 0.,  0.,  1.],   [ 0.,  0.,  0.]]]]

    This game has a unique symmetric Nash equilibrium, where the
{'fraction_non_alphanumeric': 0.11478900503290747, 'fraction_numerical': 0.020905923344947737, 'mean_word_length': 2.563448275862069, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4810702', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1539, 'n_words': 583}