egttools.games.NormalFormGame¶
- class NormalFormGame(*args, **kwargs)¶
Bases:
AbstractGame
Overloaded function.
__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.
__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
Computes the fitness of a strategy in a given population state.
Calculates the expected payoff matrix for all strategy pairs.
Returns the matrix of expected payoffs between strategies.
Number of strategies in the game.
Returns the payoff for a given strategy in a specific match-up.
Returns the payoff matrix.
Executes a game round and stores the resulting payoffs.
Saves the payoff matrix to a text file.
Returns the type identifier of the game.
Attributes
Number of rounds per interaction.
Number of unique pairwise strategy combinations.
List of strategies participating in the game.
- __init__(*args, **kwargs)¶
Overloaded function.
__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.
__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:
- 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:
- 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.
- 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:
group_composition (list[int] or numpy.ndarray[int]) – Composition of the pairwise game (usually 2 players).
game_payoffs (list[float] or numpy.ndarray[float]) – Output array to store individual payoffs.
- 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:
- __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.