egttools.games.AbstractGame¶
- class AbstractGame(self: egttools.numerical.numerical.games.AbstractGame)¶
Bases:
pybind11_object
Abstract class which must be implemented by any new game.
This class provides a common interface for Games, so that they can be passed to the methods (both analytical and numerical) implemented in
egttools
.You must implement the following methods: - play(group_composition: List[int], game_payoffs: List[float]) -> None - calculate_payoffs() -> numpy.ndarray[numpy.float64[m, n]] - calculate_fitness(strategy_index: int, pop_size: int, strategies: numpy.ndarray[numpy.uint64[m, 1]]) -> float - __str__ - type() -> str - payoffs() -> numpy.ndarray[numpy.float64[m, n]] - payoff(strategy: int, group_composition: List[int]) -> float - nb_strategies() -> int - save_payoffs(file_name: str) -> None
See also
Methods
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.
Number of different strategies playing the game.
Returns the payoff of a strategy given a group composition.
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.
returns the type of game.
- __init__(self: egttools.numerical.numerical.games.AbstractGame) None ¶
Abstract class which must be implemented by any new game.
This class provides a common interface for Games, so that they can be passed to the methods (both analytical and numerical) implemented in
egttools
.You must implement the following methods: - play(group_composition: List[int], game_payoffs: List[float]) -> None - calculate_payoffs() -> numpy.ndarray[numpy.float64[m, n]] - calculate_fitness(strategy_index: int, pop_size: int, strategies: numpy.ndarray[numpy.uint64[m, 1]]) -> float - __str__ - type() -> str - payoffs() -> numpy.ndarray[numpy.float64[m, n]] - payoff(strategy: int, group_composition: List[int]) -> float - nb_strategies() -> int - save_payoffs(file_name: str) -> None
See also
- __new__(**kwargs)¶
- __str__(self: egttools.numerical.numerical.games.AbstractGame) str ¶
- calculate_fitness(self: egttools.numerical.numerical.games.AbstractGame, strategy_index: int, pop_size: int, strategies: 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
strategy_index (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.AbstractGame) 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.
- Returns
A matrix with the expected payoffs for each strategy given each possible game state.
- Return type
numpy.ndarray[numpy.float64[m, n]]
- nb_strategies(self: egttools.numerical.numerical.games.AbstractGame) int ¶
Number of different strategies playing the game.
- payoff(self: egttools.numerical.numerical.games.AbstractGame, strategy: int, group_composition: List[int]) float ¶
Returns the payoff of a strategy given a group composition.
If the group composition does not include the strategy, the payoff should be zero.
- payoffs(self: egttools.numerical.numerical.games.AbstractGame) 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.AbstractGame, 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.AbstractGame, file_name: 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.AbstractGame) str ¶
returns the type of game.