egttools.games.CRDGame¶
- class CRDGame(self: egttools.numerical.numerical.games.CRDGame, endowment: int, threshold: int, nb_rounds: int, group_size: int, risk: float, enhancement_factor: float, strategies: list)¶
Bases:
AbstractGame
Collective Risk Dilemma.
This allows you to define any number of strategies by passing them as a list. All strategies must be of type AbstractCRDStrategy *.
The CRD dilemma implemented here follows the description of: Milinski, M., Sommerfeld, R. D., Krambeck, H.-J., Reed, F. A., & Marotzke, J. (2008). The collective-risk social dilemma and the prevention of simulated dangerous climate change. Proceedings of the National Academy of Sciences of the United States of America, 105(7), 2291–2294. https://doi.org/10.1073/pnas.0709546105
- Parameters
endowment (int) – Initial endowment for all players.
threshold (int) – Collective target that the group must reach.
nb_rounds (int) – Number of rounds of the game.
group_size (int) – Size of the group that will play the CRD.
risk (float) – The probability that all members will lose their remaining endowment if the threshold is not achieved.
enhancement_factor (float) – The payoffs of each strategy are multiplied by this factor if the target is reached (this may enables the inclusion of a surplus for achieving the goal).
strategies (List[egttools.behaviors.CRD.AbstractCRDStrategy]) – A list containing references of AbstractCRDStrategy strategies (or child classes).
See also
egttools.games.AbstractGame
,egttools.games.NormalFormGame
,egttools.behaviors.CRD.AbstractCRDStrategy
Methods
Estimates the fitness for a player_type in the population with state :param strategies.
calculates the group achievement for a given stationary distribution.
Estimates the payoffs for each strategy and returns the values in a matrix.
calculates the fraction of players that contribute above, below or equal to the fair contribution (E/2)in a give population state.
calculates the fraction of players (from successful groups)) that contribute above, below or equal to the fair contribution (E/2)in a give population state.
calculates the group achievement in the population at a given state.
Number of different strategies which are playing the game.
Returns the payoff of a strategy given a group composition.
Returns the expected payoffs of each strategy vs each possible game state.
Updates the vector of payoffs with the payoffs of each player after playing the game.
Saves the payoff matrix in a txt file.
Attributes
Initial endowment for all players.
The payoffs of each strategy are multiplied by this factor if the target is reached (this may enables the inclusion of a surplus for achieving the goal).
Size of the group which will play the game.
Number of rounds of the game.
Number of combinations of 2 strategies that can be matched in the game.
Probability that all players will lose their remaining endowment if the target si not achieved.
A list with pointers to the strategies that are playing the game.
Collective target which needs to be achieved by the group.
- __init__(self: egttools.numerical.numerical.games.CRDGame, endowment: int, threshold: int, nb_rounds: int, group_size: int, risk: float, enhancement_factor: float, strategies: list) None ¶
Collective Risk Dilemma.
This allows you to define any number of strategies by passing them as a list. All strategies must be of type AbstractCRDStrategy *.
The CRD dilemma implemented here follows the description of: Milinski, M., Sommerfeld, R. D., Krambeck, H.-J., Reed, F. A., & Marotzke, J. (2008). The collective-risk social dilemma and the prevention of simulated dangerous climate change. Proceedings of the National Academy of Sciences of the United States of America, 105(7), 2291–2294. https://doi.org/10.1073/pnas.0709546105
- Parameters
endowment (int) – Initial endowment for all players.
threshold (int) – Collective target that the group must reach.
nb_rounds (int) – Number of rounds of the game.
group_size (int) – Size of the group that will play the CRD.
risk (float) – The probability that all members will lose their remaining endowment if the threshold is not achieved.
enhancement_factor (float) – The payoffs of each strategy are multiplied by this factor if the target is reached (this may enables the inclusion of a surplus for achieving the goal).
strategies (List[egttools.behaviors.CRD.AbstractCRDStrategy]) – A list containing references of AbstractCRDStrategy strategies (or child classes).
- __new__(**kwargs)¶
- __str__(self: egttools.numerical.numerical.games.CRDGame) str ¶
- calculate_fitness(self: egttools.numerical.numerical.games.CRDGame, player_strategy: int, pop_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_strategy (int) – The index of the strategy used by the player.
pop_size (int) – The size of the population.
population_state (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_group_achievement(self: egttools.numerical.numerical.games.CRDGame, population_size: int, stationary_distribution: numpy.ndarray[numpy.float64[m, 1]]) float ¶
calculates the group achievement for a given stationary distribution.
- calculate_payoffs(self: egttools.numerical.numerical.games.CRDGame) 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. Therefore, each entry a_ij gives the payoff of strategy i for game state j, which represents the group composition.
It also updates the coop_level matrices by calculating level of cooperation at any given population state
- Returns
A matrix with the expected payoffs for each strategy given each possible game state.
- Return type
numpy.ndarray[numpy.float64[m, n]]
- calculate_polarization(self: egttools.numerical.numerical.games.CRDGame, population_size: int, population_state: numpy.ndarray[numpy.float64[m, 1]]) numpy.ndarray[numpy.float64[3, 1]] ¶
calculates the fraction of players that contribute above, below or equal to the fair contribution (E/2)in a give population state.
- calculate_polarization_success(self: egttools.numerical.numerical.games.CRDGame, population_size: int, population_state: numpy.ndarray[numpy.float64[m, 1]]) numpy.ndarray[numpy.float64[3, 1]] ¶
calculates the fraction of players (from successful groups)) that contribute above, below or equal to the fair contribution (E/2)in a give population state.
- calculate_population_group_achievement(self: egttools.numerical.numerical.games.CRDGame, population_size: int, population_state: numpy.ndarray[numpy.uint64[m, 1]]) float ¶
calculates the group achievement in the population at a given state.
- nb_strategies(self: egttools.numerical.numerical.games.CRDGame) int ¶
Number of different strategies which are playing the game.
- payoff(self: egttools.numerical.numerical.games.CRDGame, 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.CRDGame) numpy.ndarray[numpy.float64[m, n]] ¶
Returns the expected payoffs of each strategy vs each possible game state.
- Returns
The payoff matrix.
- Return type
numpy.ndarray[np.float64[m,n]]
- play(self: egttools.numerical.numerical.games.CRDGame, arg0: List[int], arg1: 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.CRDGame, arg0: str) None ¶
Saves the payoff matrix in a txt file.
- type(self: egttools.numerical.numerical.games.CRDGame) str ¶
- property endowment¶
Initial endowment for all players.
- property enhancement_factor¶
The payoffs of each strategy are multiplied by this factor if the target is reached (this may enables the inclusion of a surplus for achieving the goal).
- property group_achievement_per_group¶
- property group_size¶
Size of the group which will play the game.
- 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 risk¶
Probability that all players will lose their remaining endowment if the target si not achieved.
- property strategies¶
A list with pointers to the strategies that are playing the game.
- property target¶
Collective target which needs to be achieved by the group.