egttools.games.nonlinear_games.CommonPoolResourceDilemmaCommitment

class CommonPoolResourceDilemmaCommitment(group_size, a, b, cost, fine, strategies)[source]

Bases: AbstractNPlayerGame

Common Pool resource game with commitment, but the threshold is set as another strategy :type group_size: int :param group_size: Size of the group playing the game. :type group_size: int :param a and b: Both a and b are the parameters of the game, if a>>b, then it’s attractive to invest in the CPR :type a and b: flaot :type cost: float :param cost: cost of making the commitment for commitment proposing strategy :type fine: float :param fine: fine for defection when accepting the commitment :type fine: float :type strategies: List[AbstractCPRStrategy] :param strategies: List of strategies which will play the game :type strategies: Lit[int]

Methods

add_group_extraction

calculate_expected_consumption

rtype

float

calculate_fitness

Estimates the fitness for a player_type in the population with state :param strategies.

calculate_payoffs

Estimates the payoffs for each strategy and returns the values in a matrix.

calculate_total_extraction

rtype

float

check_if_commitment_validated

rtype

None

get_nb_committed

rtype

int

group_size

Size of the group.

nb_group_configurations

Number of different group configurations.

nb_strategies

Number of different strategies playing the game.

payoff

Returns the payoff of a strategy given a group composition.

payoffs

Returns the payoff matrix of the game.

play

Updates the vector of payoffs with the payoffs of each player after playing the game.

save_payoffs

Stores the payoff matrix in a txt file.

type

returns the type of game.

update_payoff

update an entry of the payoff matrix

__init__(group_size, a, b, cost, fine, strategies)[source]

Common Pool resource game with commitment, but the threshold is set as another strategy :type group_size: int :param group_size: Size of the group playing the game. :type group_size: int :param a and b: Both a and b are the parameters of the game, if a>>b, then it’s attractive to invest in the CPR :type a and b: flaot :type cost: float :param cost: cost of making the commitment for commitment proposing strategy :type fine: float :param fine: fine for defection when accepting the commitment :type fine: float :type strategies: List[AbstractCPRStrategy] :param strategies: List of strategies which will play the game :type strategies: Lit[int]

__new__(**kwargs)
__str__(self: egttools.numerical.numerical.games.AbstractNPlayerGame) str
add_group_extraction(group_extraction, group_composition)[source]
calculate_expected_consumption(population_state)[source]
Return type

float

calculate_fitness(self: egttools.numerical.numerical.games.AbstractNPlayerGame, 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

float

calculate_payoffs()[source]

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]]

calculate_total_extraction(commitment_accepted, group_composition)[source]
Return type

float

check_if_commitment_validated(nb_committed, group_composition, commitment_accepted)[source]
Return type

None

get_nb_committed(group_composition)[source]
Return type

int

group_size(self: egttools.numerical.numerical.games.AbstractNPlayerGame) int

Size of the group.

nb_group_configurations(self: egttools.numerical.numerical.games.AbstractNPlayerGame) int

Number of different group configurations.

nb_strategies(self: egttools.numerical.numerical.games.AbstractNPlayerGame) int

Number of different strategies playing the game.

payoff(self: egttools.numerical.numerical.games.AbstractNPlayerGame, 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.

Parameters
  • strategy (int) – The index of the strategy used by the player.

  • group_composition (List[int]) – List with the group composition. The structure of this list depends on the particular implementation of this abstract method.

Returns

The payoff value.

Return type

float

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

Returns the payoff matrix of the game.

Returns

The payoff matrix.

Return type

numpy.ndarray

play(group_composition, game_payoffs)[source]

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.

Parameters
  • group_composition (List[int]) – A list with counts of the number of players of each strategy in the group.

  • game_payoffs (List[float]) – A list used as container for the payoffs of each player

Return type

None

save_payoffs(self: egttools.numerical.numerical.games.AbstractNPlayerGame, 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.AbstractNPlayerGame) str

returns the type of game.

update_payoff(self: egttools.numerical.numerical.games.AbstractNPlayerGame, strategy_index: int, group_configuration_index: int, value: float) None

update an entry of the payoff matrix