egttools.games.NormalFormGame

class NormalFormGame(*args, **kwargs)

Bases: AbstractGame

Overloaded function.

  1. __init__(self: egttools.numerical.numerical_.games.NormalFormGame, nb_rounds: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n], flags.c_contiguous]) -> None

    Normal Form Game with two actions.

    Implements a repeated symmetric 2-player game based on a payoff matrix.

    nb_roundsint

    Number of rounds played by each strategy pair.

    payoff_matrixnumpy.ndarray of shape (2, 2)

    Payoff matrix where entry (i, j) gives the payoff of strategy i against j.

  2. __init__(self: egttools.numerical.numerical_.games.NormalFormGame, nb_rounds: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n], flags.c_contiguous], strategies: list) -> None

    Normal Form Game initialized with custom strategy classes.

    This constructor allows using any number of strategies, defined in Python as subclasses of AbstractNFGStrategy.

    nb_roundsint

    Number of rounds in the repeated game.

    payoff_matrixnumpy.ndarray

    Payoff matrix of shape (nb_actions, nb_actions).

    strategieslist[AbstractNFGStrategy]

    List of strategy instances.

Methods

calculate_fitness

Computes the fitness of a strategy in a given population state.

calculate_payoffs

Calculates the expected payoff matrix for all strategy pairs.

expected_payoffs

Returns the matrix of expected payoffs between strategies.

nb_strategies

Number of strategies in the game.

payoff

Returns the payoff for a given strategy in a specific match-up.

payoffs

Returns the payoff matrix.

play

Executes a game round and stores the resulting payoffs.

save_payoffs

Saves the payoff matrix to a text file.

type

Returns the type identifier of the game.

Attributes

nb_rounds

Number of rounds per interaction.

nb_states

Number of unique pairwise strategy combinations.

strategies

List of strategies participating in the game.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: egttools.numerical.numerical_.games.NormalFormGame, nb_rounds: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n], flags.c_contiguous]) -> None

    Normal Form Game with two actions.

    Implements a repeated symmetric 2-player game based on a payoff matrix.

    nb_roundsint

    Number of rounds played by each strategy pair.

    payoff_matrixnumpy.ndarray of shape (2, 2)

    Payoff matrix where entry (i, j) gives the payoff of strategy i against j.

  2. __init__(self: egttools.numerical.numerical_.games.NormalFormGame, nb_rounds: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n], flags.c_contiguous], strategies: list) -> None

    Normal Form Game initialized with custom strategy classes.

    This constructor allows using any number of strategies, defined in Python as subclasses of AbstractNFGStrategy.

    nb_roundsint

    Number of rounds in the repeated game.

    payoff_matrixnumpy.ndarray

    Payoff matrix of shape (nb_actions, nb_actions).

    strategieslist[AbstractNFGStrategy]

    List of strategy instances.

__new__(**kwargs)
__str__(self: egttools.numerical.numerical_.games.NormalFormGame) str

Returns a string representation of the NormalFormGame instance.

Return type:

str

calculate_fitness(self: egttools.numerical.numerical_.games.NormalFormGame, player_strategy: int, population_size: int, population_state: numpy.ndarray[numpy.uint64[m, 1]]) float

Computes the fitness of a strategy in a given population state.

Parameters:
  • player_strategy (int) – Index of the focal strategy.

  • population_size (int) – Total number of individuals (excluding the focal player).

  • population_state (numpy.ndarray[numpy.uint64]) – Strategy counts in the population.

Returns:

Fitness of the focal strategy.

Return type:

float

calculate_payoffs(self: egttools.numerical.numerical_.games.NormalFormGame) numpy.ndarray[numpy.float64[m, n]]

Calculates the expected payoff matrix for all strategy pairs.

Returns:

Matrix of expected payoffs between strategies.

Return type:

numpy.ndarray of shape (nb_strategies, nb_strategies)

expected_payoffs(self: egttools.numerical.numerical_.games.NormalFormGame) numpy.ndarray[numpy.float64[m, n]]

Returns the matrix of expected payoffs between strategies.

nb_strategies(self: egttools.numerical.numerical_.games.NormalFormGame) int

Number of strategies in the game.

payoff(self: egttools.numerical.numerical_.games.NormalFormGame, strategy: int, strategy_pair: list[int]) float

Returns the payoff for a given strategy in a specific match-up.

Parameters:
  • strategy (int) – Index of the strategy used by the player.

  • strategy_pair (list[int]) – List of two integers representing the strategies in the match-up.

Return type:

float

payoffs(self: egttools.numerical.numerical_.games.NormalFormGame) numpy.ndarray[numpy.float64[m, n]]

Returns the payoff matrix.

Return type:

numpy.ndarray of shape (nb_strategies, nb_strategies)

play(self: egttools.numerical.numerical_.games.NormalFormGame, group_composition: list[int], game_payoffs: list[float]) None

Executes a game round and stores the resulting payoffs.

Parameters:
save_payoffs(self: egttools.numerical.numerical_.games.NormalFormGame, arg0: str) None

Saves the payoff matrix to a text file.

Parameters:

file_name (str) – File path where the matrix will be saved.

type(self: egttools.numerical.numerical_.games.NormalFormGame) str

Returns the type identifier of the game.

Return type:

str

__annotations__ = {}
property nb_rounds

Number of rounds per interaction.

property nb_states

Number of unique pairwise strategy combinations.

property strategies

List of strategies participating in the game.