egttools.games.pgg.PGG¶
- class PGG(group_size, cost, multiplying_factor, strategies)[source]¶
Bases:
AbstractNPlayerGameClassical 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[PGGOneShotStrategy]) – A list of strategies that will play the game.
Methods
Computes the fitness of a given strategy in a population state.
Computes and returns the full payoff matrix.
Returns the payoff of a strategy in a given group context.
Returns the payoff matrix.
Executes the game for a given group composition and fills the payoff vector.
Saves the payoff matrix to a text file.
Updates an entry in the payoff matrix.
- classmethod __new__(*args, **kwargs)¶
- __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[PGGOneShotStrategy]) – A list of strategies that will play the game.
- __str__(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) str[source]¶
- Return type:
- calculate_fitness(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, strategy_index: SupportsInt | SupportsIndex, pop_size: SupportsInt | SupportsIndex, strategies: Annotated[numpy.typing.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.
strategies (numpy.ndarray) – Population state as a strategy count vector.
- Returns:
Fitness of the focal strategy in the given state.
- Return type:
- calculate_payoffs(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) Annotated[numpy.typing.NDArray[numpy.float64], '[m, n]'][source]¶
Computes and returns the full payoff matrix.
- Returns:
A matrix with expected payoffs. Each row represents a strategy, and each column a group configuration.
- Return type:
- group_size(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int¶
- nb_group_configurations(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int¶
- nb_strategies(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int¶
- payoff(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, strategy: SupportsInt | SupportsIndex, group_composition: collections.abc.Sequence[SupportsInt | SupportsIndex]) float¶
Returns the payoff of a strategy in a given group context.
- Parameters:
strategy (int) – The strategy index.
group_composition (numpy.ndarray) – The group configuration.
- Returns:
The corresponding payoff.
- Return type:
- payoffs(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) Annotated[numpy.typing.NDArray[numpy.float64], '[m, n]']¶
Returns the payoff matrix.
- Returns:
Matrix of shape (nb_strategies, nb_group_configurations).
- Return type:
- play(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, group_composition: collections.abc.Sequence[SupportsInt | SupportsIndex], game_payoffs: collections.abc.Sequence[SupportsFloat | SupportsIndex]) None[source]¶
Executes the game for a given group composition and fills the payoff vector.
- save_payoffs(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, file_name: str) None[source]¶
Saves the payoff matrix to a text file.
- type(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) str[source]¶
- Return type:
- update_payoff(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, strategy_index: SupportsInt | SupportsIndex, group_configuration_index: SupportsInt | SupportsIndex, value: SupportsFloat | SupportsIndex) None¶
Updates an entry in the payoff matrix.
- __annotations__ = {}¶