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. This constructor assumes that there are only two possible strategies and two possible actions.
This class will run the game using the players and player types defined in :param group_composition, and will update the vector :param game_payoffs with the resulting payoff of each player.
- nb_roundsint
Number of rounds of the game.
- payoff_matrixnumpy.ndarray[numpy.float64[m, m]]
A payoff matrix of shape (nb_actions, nb_actions).
egttools.games.AbstractGame, egttools.games.AbstractNPlayerGame, egttools.games.CRDGame, egttools.games.CRDGameTU, egttools.behaviors.NormalForm.TwoActions
__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.
This constructor allows you to define any number of strategies by passing a list of pointers to them. All strategies must by of type AbstractNFGStrategy *.
- nb_roundsint
Number of rounds of the game.
- payoff_matrixnumpy.ndarray[float]
A payoff matrix of shape (nb_actions, nb_actions).
- strategiesList[egttools.behaviors.AbstractNFGStrategy]
A list containing references of AbstractNFGStrategy strategies (or child classes).
egttools.games.AbstractGame
Methods
Calculates the rate/level of cooperation in the population at a given population state.
Estimates the fitness for a player_type in the population with state :param strategies.
Estimates the payoffs for each strategy and returns the values in a matrix.
returns the expected payoffs of each strategy vs another
Number of different strategies which are playing the game.
Returns the payoff of a strategy given a strategy pair.
Returns the payoff matrix of the game.
Updates the vector of payoffs with the payoffs of each player after playing the game.
Stores the payoff matrix in a txt file.
Attributes
Number of rounds of the game.
Number of combinations of 2 strategies that can be matched in the game.
A list with pointers to the strategies that are playing 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. This constructor assumes that there are only two possible strategies and two possible actions.
This class will run the game using the players and player types defined in :param group_composition, and will update the vector :param game_payoffs with the resulting payoff of each player.
- nb_roundsint
Number of rounds of the game.
- payoff_matrixnumpy.ndarray[numpy.float64[m, m]]
A payoff matrix of shape (nb_actions, nb_actions).
egttools.games.AbstractGame, egttools.games.AbstractNPlayerGame, egttools.games.CRDGame, egttools.games.CRDGameTU, egttools.behaviors.NormalForm.TwoActions
__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.
This constructor allows you to define any number of strategies by passing a list of pointers to them. All strategies must by of type AbstractNFGStrategy *.
- nb_roundsint
Number of rounds of the game.
- payoff_matrixnumpy.ndarray[float]
A payoff matrix of shape (nb_actions, nb_actions).
- strategiesList[egttools.behaviors.AbstractNFGStrategy]
A list containing references of AbstractNFGStrategy strategies (or child classes).
egttools.games.AbstractGame
- __new__(**kwargs)¶
- __str__(self: egttools.numerical.numerical.games.NormalFormGame) str ¶
- calculate_cooperation_rate(self: egttools.numerical.numerical.games.NormalFormGame, population_size: int, population_state: numpy.ndarray[numpy.uint64[m, 1]]) float ¶
Calculates the rate/level of cooperation in the population at a given population state.
- Parameters
population_size (int) – The size of the population.
population_state (numpy.ndarray[numpy.uint64[m, 1]]) – A vector of counts of each strategy in the population. The current state of the population.
- Returns
The level of cooperation at the population_state.
- 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 ¶
Estimates the fitness for a player_type in the population with state :param strategies.
This function assumes that the player with strategy player_type is not included in the vector of strategy counts strategies.
- Parameters
player_type (int) – The index of the strategy used by the player.
pop_size (int) – The size of the population.
strategies (numpy.ndarray[numpy.uint64[m, 1]]) – A vector of counts of each strategy. The current state of the population.
- Returns
The fitness of the strategy in the population state given by strategies.
- Return type
- calculate_payoffs(self: egttools.numerical.numerical.games.NormalFormGame) numpy.ndarray[numpy.float64[m, n]] ¶
Estimates the payoffs for each strategy and returns the values in a matrix.
Each row of the matrix represents a strategy and each column a game state. E.g., in case of a 2 player game, each entry a_ij gives the payoff for strategy i against strategy j. In case of a group game, each entry a_ij gives the payoff of strategy i for game state j, which represents the group composition.
This method also updates a matrix that stores the cooperation level of each strategy against any other.
- Returns
A matrix with the expected payoffs for each strategy given each possible game state.
- Return type
numpy.ndarray[numpy.float64[m, n]]
- expected_payoffs(self: egttools.numerical.numerical.games.NormalFormGame) numpy.ndarray[numpy.float64[m, n]] ¶
returns the expected payoffs of each strategy vs another
- nb_strategies(self: egttools.numerical.numerical.games.NormalFormGame) int ¶
Number of different strategies which are playing the game.
- payoff(self: egttools.numerical.numerical.games.NormalFormGame, strategy: int, strategy_pair: List[int]) float ¶
Returns the payoff of a strategy given a strategy pair.
If the group composition does not include the strategy, the payoff should be zero.
- payoffs(self: egttools.numerical.numerical.games.NormalFormGame) numpy.ndarray[numpy.float64[m, n]] ¶
Returns the payoff matrix of the game.
- Returns
The payoff matrix.
- Return type
- play(self: egttools.numerical.numerical.games.NormalFormGame, group_composition: List[int], game_payoffs: List[float]) None ¶
Updates the vector of payoffs with the payoffs of each player after playing the game.
This method will run the game using the players and player types defined in :param group_composition, and will update the vector :param game_payoffs with the resulting payoff of each player.
- save_payoffs(self: egttools.numerical.numerical.games.NormalFormGame, arg0: str) None ¶
Stores the payoff matrix in a txt file.
- Parameters
file_name (str) – Name of the file in which the data will be stored.
- type(self: egttools.numerical.numerical.games.NormalFormGame) str ¶
- property nb_rounds¶
Number of rounds of the game.
- property nb_states¶
Number of combinations of 2 strategies that can be matched in the game.
- property strategies¶
A list with pointers to the strategies that are playing the game.