egttools.games.CRDGameTU

class CRDGameTU(self: egttools.numerical.numerical.games.CRDGameTU, endowment: int, threshold: int, min_rounds: int, group_size: int, risk: float, tu: egttools.numerical.numerical.distributions.TimingUncertainty, strategies: list)

Bases: AbstractGame

This class implements a One-Shot Collective Risk Dilemma.

This N-player game was first introduced in “Santos, F. C., & Pacheco, J. M. (2011). Risk of collective failure provides an escape from the tragedy of the commons. Proceedings of the National Academy of Sciences of the United States of America, 108(26), 10421–10425.”.

The game consists of a group of size group_size (N) which can be composed of Cooperators (Cs) who will contribute a fraction cost (c) of their endowment (b) to the public good. And of Defectors (Ds) who contribute 0.

If the total contribution of the group is equal or surpasses the collective target Mcb, with M being the min_nb_cooperators, then all participants will receive as payoff their remaining endowment. Which is, Cs receive b - cb and Ds receive b. Otherwise, all participants receive 0 endowment with a probability equal to risk (r), and will keep their endowment with probability 1-r. This means that each group must have at least M Cs for the collective target to be achieved.

Parameters
  • endowment (float) – The initial endowment (b) received by all participants

  • cost (float) – The fraction of the endowment that Cooperators contribute to the public good. This value must be in the interval [0, 1]

  • risk (float) – The risk that all members of the group will lose their remaining endowment if the collective target is not achieved.

  • group_size (int) – The size of the group (N)

  • min_nb_cooperators (int) – The minimum number of cooperators (M) required to reach the collective target. In other words, the collective target is reached if the collective effort is at least Mcb. This value must be in the discrete interval [[0, N]].

Methods

calculate_fitness

Calculates the fitness of a strategy given a population state.

calculate_group_achievement

calculates the group achievement for a given stationary distribution.

calculate_payoffs

Calculates the payoffs of every strategy in each possible group composition.

calculate_polarization

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

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

calculates the group achievement in the population at a given state.

nb_strategies

Number of different strategies which are playing the game.

payoff

returns the payoff of a strategy given a group composition.

payoffs

returns the expected payoffs of each strategy vs each possible game state

play

Plays the One-shop CRD and update the game_payoffs given the group_composition.

save_payoffs

Saves the payoff matrix in a txt file.

type

Attributes

endowment

Initial endowment for all players.

group_size

Size of the group which will play the game.

min_rounds

Minimum number of rounds of the game.

nb_states

Number of combinations of 2 strategies that can be matched in the game.

risk

Probability that all players will lose their remaining endowment if the target si not achieved.

strategies

A list with pointers to the strategies that are playing the game.

target

Collective target which needs to be achieved by the group.

__init__(self: egttools.numerical.numerical.games.CRDGameTU, endowment: int, threshold: int, min_rounds: int, group_size: int, risk: float, tu: egttools.numerical.numerical.distributions.TimingUncertainty, strategies: list) None

This class implements a One-Shot Collective Risk Dilemma.

This N-player game was first introduced in “Santos, F. C., & Pacheco, J. M. (2011). Risk of collective failure provides an escape from the tragedy of the commons. Proceedings of the National Academy of Sciences of the United States of America, 108(26), 10421–10425.”.

The game consists of a group of size group_size (N) which can be composed of Cooperators (Cs) who will contribute a fraction cost (c) of their endowment (b) to the public good. And of Defectors (Ds) who contribute 0.

If the total contribution of the group is equal or surpasses the collective target Mcb, with M being the min_nb_cooperators, then all participants will receive as payoff their remaining endowment. Which is, Cs receive b - cb and Ds receive b. Otherwise, all participants receive 0 endowment with a probability equal to risk (r), and will keep their endowment with probability 1-r. This means that each group must have at least M Cs for the collective target to be achieved.

Parameters
  • endowment (float) – The initial endowment (b) received by all participants

  • cost (float) – The fraction of the endowment that Cooperators contribute to the public good. This value must be in the interval [0, 1]

  • risk (float) – The risk that all members of the group will lose their remaining endowment if the collective target is not achieved.

  • group_size (int) – The size of the group (N)

  • min_nb_cooperators (int) – The minimum number of cooperators (M) required to reach the collective target. In other words, the collective target is reached if the collective effort is at least Mcb. This value must be in the discrete interval [[0, N]].

__new__(**kwargs)
__str__(self: egttools.numerical.numerical.games.CRDGameTU) str
calculate_fitness(self: egttools.numerical.numerical.games.CRDGameTU, player_strategy: int, pop_size: int, population_state: numpy.ndarray[numpy.uint64[m, 1]]) float

Calculates the fitness of a strategy given a population state.

Parameters
  • player_type (int) – The index of the strategy whose fitness will be calculated.

  • pop_size (int) – The size of the population (Z).

  • population_state (numpy.ndarray) – A vector containing the counts of each strategy in the population.

Returns

The fitness of the strategy in the current population state.

Return type

float

calculate_group_achievement(self: egttools.numerical.numerical.games.CRDGameTU, 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.CRDGameTU) numpy.ndarray[numpy.float64[m, n]]

Calculates the payoffs of every strategy in each possible group composition.

Returns

A matrix containing the payoff of each strategy in every possible group composition.

Return type

numpy.ndarray

calculate_polarization(self: egttools.numerical.numerical.games.CRDGameTU, 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.CRDGameTU, 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.CRDGameTU, 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.CRDGameTU) int

Number of different strategies which are playing the game.

payoff(self: egttools.numerical.numerical.games.CRDGameTU, strategy: int, strategy pair: List[int]) float

returns the payoff of a strategy given a group composition.

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

returns the expected payoffs of each strategy vs each possible game state

play(self: egttools.numerical.numerical.games.CRDGameTU, arg0: List[int], arg1: List[float]) None

Plays the One-shop CRD and update the game_payoffs given the group_composition.

We always assume that strategy 0 is D and strategy 1 is C.

The payoffs of Defectors and Cooperators are described by the following equations:

\[ \begin{align}\begin{aligned}\Pi_{D}(k) = b\{\theta(k-M)+ (1-r)[1 - \theta(k-M)]\}\\\Pi_{C}(k) = \Pi_{D}(k) - cb\\\text{where } \theta(x) = 0 \text{if } x < 0 \text{ and 1 otherwise.}\end{aligned}\end{align} \]
Parameters
  • group_composition (Union[List[int], numpy.ndarray]) – A list or array containing the counts of how many members of each strategy are present in the group.

  • game_payoffs (numpy.ndarray) – A vector in which the payoffs of the game will be stored.

save_payoffs(self: egttools.numerical.numerical.games.CRDGameTU, arg0: str) None

Saves the payoff matrix in a txt file.

type(self: egttools.numerical.numerical.games.CRDGameTU) str
property endowment

Initial endowment for all players.

property group_size

Size of the group which will play the game.

property min_rounds

Minimum 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.