egttools.games.pgg.PGG

class PGG(group_size, cost, multiplying_factor, strategies)[source]

Bases: AbstractNPlayerGame

Classical Public Goods game with only 2 possible contributions (o or cost).

Parameters:
  • group_size (int) – Size of the group playing the game.

  • cost (float) – Cost of cooperation.

  • multiplying_factor (float) – The sum of contributions to the public good is multiplied by this factor before being divided equally among all players.

  • strategies (List[egttools.behaviors.pgg_behaviors.PGGOneShotStrategy]) – A list of strategies that will play the game.

Methods

calculate_fitness

Computes the fitness of a given strategy in a population state.

calculate_payoffs

Computes and returns the full payoff matrix.

group_size

Returns the size of the group.

nb_group_configurations

Returns the number of distinct group configurations.

nb_strategies

Returns the number of strategies in the game.

payoff

Returns the payoff of a strategy in a given group context.

payoffs

Returns the payoff matrix.

play

Executes the game for a given group composition and fills the payoff vector.

save_payoffs

Saves the payoff matrix to a text file.

type

Returns the string identifier for the game.

update_payoff

Updates an entry in the payoff matrix.

__init__(group_size, cost, multiplying_factor, strategies)[source]

Classical Public Goods game with only 2 possible contributions (o or cost).

Parameters:
  • group_size (int) – Size of the group playing the game.

  • cost (float) – Cost of cooperation.

  • multiplying_factor (float) – The sum of contributions to the public good is multiplied by this factor before being divided equally among all players.

  • strategies (List[egttools.behaviors.pgg_behaviors.PGGOneShotStrategy]) – A list of strategies that will play the game.

__new__(**kwargs)
__str__()[source]

Returns a string representation of the game.

Return type:

str

calculate_fitness(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, strategy_index: int, pop_size: int, strategies: numpy.ndarray[numpy.uint64[m, 1]]) float

Computes the fitness of a given strategy in a population state.

Parameters:
  • strategy_index (int) – The strategy of the focal player.

  • pop_size (int) – Total population size (excluding the focal player).

  • strategies (numpy.ndarray[uint64]) – The population state as a strategy count vector.

Returns:

Fitness of the focal strategy in the given state.

Return type:

float

calculate_payoffs()[source]

Computes and returns the full payoff matrix.

Returns:

A matrix with expected payoffs. Each row represents a strategy, each column a group configuration.

Return type:

numpy.ndarray

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

Returns the size of the group.

Return type:

int

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

Returns the number of distinct group configurations.

Return type:

int

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

Returns the number of strategies in the game.

Return type:

int

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

Returns the payoff of a strategy in a given group context.

Parameters:
Returns:

The corresponding payoff.

Return type:

float

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

Returns the payoff matrix.

Returns:

The matrix of shape (nb_strategies, nb_group_configurations).

Return type:

numpy.ndarray

play(group_composition, game_payoffs)[source]

Executes the game for a given group composition and fills the payoff vector.

Parameters:
  • group_composition (List[int] | numpy.ndarray[int]) – The number of players of each strategy in the group.

  • game_payoffs (List[float] | numpy.ndarray[float]) – Output container where the payoff of each player will be written.

Return type:

None

save_payoffs(file_name)[source]

Saves the payoff matrix to a text file.

Parameters:

file_name (str) – Destination file path.

Return type:

None

type()[source]

Returns the string identifier for the game.

Return type:

str

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

Updates an entry in the payoff matrix.

Parameters:
  • strategy_index (int) – Index of the strategy (row).

  • group_configuration_index (int) – Index of the group composition (column).

  • value (float | numpy.float64) – The new payoff value.

__annotations__ = {}