egttools.games.OneShotCRD

class OneShotCRD(self: egttools.numerical.numerical_.games.OneShotCRD, endowment: float, cost: float, risk: float, group_size: int, min_nb_cooperators: int)

Bases: AbstractGame

One-Shot Collective Risk Dilemma (CRD).

This implementation models the one-shot version of the CRD introduced in: Santos, F. C., & Pacheco, J. M. (2011). “Risk of collective failure provides an escape from the tragedy of the commons.” PNAS, 108(26), 10421–10425.

A single group of group_size players must decide whether to contribute to a public good. Cooperators (Cs) contribute a fraction cost of their endowment, while Defectors (Ds) contribute nothing. If the number of cooperators is greater than or equal to min_nb_cooperators, all players avoid the risk and receive their remaining endowment. Otherwise, each player loses their remaining endowment with probability risk.

Parameters:
  • endowment (float) – The initial endowment received by all players.

  • cost (float) – The fraction of the endowment that Cooperators contribute (in [0, 1]).

  • risk (float) – Probability of collective loss if the group fails to reach the threshold.

  • group_size (int) – Number of players in the group.

  • min_nb_cooperators (int) – Minimum number of cooperators needed to avoid risk.

Methods

calculate_fitness

Calculates the fitness of a strategy given a population state.

calculate_group_achievement

Computes group achievement from a stationary distribution.

calculate_payoffs

Updates the payoff matrix and cooperation level matrix for all strategy pairs.

calculate_population_group_achievement

Computes the group achievement for the given population state.

nb_strategies

Number of strategies in the game.

payoff

Returns the payoff for a given strategy and group composition.

payoffs

Returns the expected payoff matrix.

play

Executes a one-shot CRD round and updates payoffs for the given group composition.

save_payoffs

Saves the payoff matrix to a text file.

type

Attributes

cost

Fraction of endowment contributed by cooperators.

endowment

Initial endowment per player.

group_achievement_per_group

group_size

Number of players per group.

min_nb_cooperators

Minimum number of cooperators required to avoid risk.

nb_states

Number of distinct group compositions.

risk

Probability of collective failure.

__init__(self: egttools.numerical.numerical_.games.OneShotCRD, endowment: float, cost: float, risk: float, group_size: int, min_nb_cooperators: int) None

One-Shot Collective Risk Dilemma (CRD).

This implementation models the one-shot version of the CRD introduced in: Santos, F. C., & Pacheco, J. M. (2011). “Risk of collective failure provides an escape from the tragedy of the commons.” PNAS, 108(26), 10421–10425.

A single group of group_size players must decide whether to contribute to a public good. Cooperators (Cs) contribute a fraction cost of their endowment, while Defectors (Ds) contribute nothing. If the number of cooperators is greater than or equal to min_nb_cooperators, all players avoid the risk and receive their remaining endowment. Otherwise, each player loses their remaining endowment with probability risk.

Parameters:
  • endowment (float) – The initial endowment received by all players.

  • cost (float) – The fraction of the endowment that Cooperators contribute (in [0, 1]).

  • risk (float) – Probability of collective loss if the group fails to reach the threshold.

  • group_size (int) – Number of players in the group.

  • min_nb_cooperators (int) – Minimum number of cooperators needed to avoid risk.

__new__(**kwargs)
__str__(self: egttools.numerical.numerical_.games.OneShotCRD) str
calculate_fitness(self: egttools.numerical.numerical_.games.OneShotCRD, 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.

Assumes the focal player is excluded from the population state.

Parameters:
  • player_strategy (int) – Index of the focal strategy.

  • pop_size (int) – Population size.

  • population_state (numpy.ndarray) – Vector of strategy counts in the population.

Return type:

float

calculate_group_achievement(self: egttools.numerical.numerical_.games.OneShotCRD, population_size: int, stationary_distribution: numpy.ndarray[numpy.float64[m, 1]]) float

Computes group achievement from a stationary distribution.

This method evaluates the probability that a group avoids risk across all states weighted by their probability in the stationary distribution.

Parameters:
  • population_size (int) – Total population size.

  • stationary_distribution (numpy.ndarray[float]) – Stationary distribution over population states.

Returns:

Weighted average group success probability.

Return type:

float

calculate_payoffs(self: egttools.numerical.numerical_.games.OneShotCRD) numpy.ndarray[numpy.float64[m, n]]

Updates the payoff matrix and cooperation level matrix for all strategy pairs.

This method precomputes and stores the expected payoff for each strategy given every possible group composition, allowing for faster access in subsequent simulations.

calculate_population_group_achievement(self: egttools.numerical.numerical_.games.OneShotCRD, population_size: int, population_state: numpy.ndarray[numpy.uint64[m, 1]]) float

Computes the group achievement for the given population state.

This metric captures the expected probability that a randomly formed group from the population will reach the collective contribution threshold.

Parameters:
  • population_size (int) – Total number of individuals.

  • population_state (numpy.ndarray) – Vector of counts of each strategy in the population.

Returns:

The probability that a randomly formed group avoids the collective risk.

Return type:

float

nb_strategies(self: egttools.numerical.numerical_.games.OneShotCRD) int

Number of strategies in the game.

payoff(self: egttools.numerical.numerical_.games.OneShotCRD, strategy: int, strategy pair: list[int]) float

Returns the payoff for a given strategy and group composition.

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

Returns the expected payoff matrix.

play(self: egttools.numerical.numerical_.games.OneShotCRD, arg0: list[int], arg1: list[float]) None

Executes a one-shot CRD round and updates payoffs for the given group composition.

Assumes two strategies: Defectors (index 0) and Cooperators (index 1).

The payoffs are computed as follows:

\[ \begin{align}\begin{aligned}\Pi_{D}(k) = b\{\theta(k-M)+ (1-r)[1 - \theta(k-M)]\}\\\Pi_{C}(k) = \Pi_{D}(k) - cb\\\begin{split}\text{where } \theta(x) = \begin{cases} 0 & x < 0 \\ 1 & x \geq 0 \end{cases}\end{split}\end{aligned}\end{align} \]
Parameters:
save_payoffs(self: egttools.numerical.numerical_.games.OneShotCRD, arg0: str) None

Saves the payoff matrix to a text file.

type(self: egttools.numerical.numerical_.games.OneShotCRD) str
__annotations__ = {}
property cost

Fraction of endowment contributed by cooperators.

property endowment

Initial endowment per player.

property group_achievement_per_group
property group_size

Number of players per group.

property min_nb_cooperators

Minimum number of cooperators required to avoid risk.

property nb_states

Number of distinct group compositions.

property risk

Probability of collective failure.