egttools.games.NPlayerStagHunt¶
- class NPlayerStagHunt(self: egttools.numerical.numerical.games.AbstractNPlayerGame, nb_strategies: int, group_size: int)[source]¶
Bases:
AbstractNPlayerGame
This game is based on the article Pacheco et al., ‘Evolutionary Dynamics of Collective Action in N -Person Stag Hunt Dilemmas’.
Abstract N-Player Game.
This abstract Game class can be used in most scenarios where the fitness of a strategy is calculated as its expected payoff given the population state.
It assumes that the game is N player, since the fitness of a strategy given a population state is calculated as the expected payoff of that strategy over all possible group combinations in the given state.
Notes
It might be a good idea to overwrite the methods
__str__
,type
, andsave_payoffs
to adapt to your given game implementationIt assumes that you have at least the following attributes: 1. And an attribute
self.nb_strategies_
which contains the number of strategies that you are going to analyse for the given game. 2.self.payoffs_
which must be a numpy.ndarray and contain the payoff matrix of the game. This array must be of shape (self.nb_strategies_, nb_group_configurations), where nb_group_configurations is the number of possible combinations of strategies in the group. Thus, each row should give the (expected) payoff of the row strategy when playing in a group with the column configuration. Thepayoff
method provides an easy way to access the payoffs for any group composition, by taking as arguments the index of the row strategy and a List with the count of each possible strategy in the group.You must still implement the methods
play
andcalculate_payoffs
which should define how the game assigns payoffs to each strategy for each possible game context. In particular,calculate_payoffs
should fill the arrayself.payoffs_
with the correct values as explained above. We recommend that you run this method in the__init__
(initialization of the object) since, these values must be set before passing the game object to the numerical simulator (e.g., egttools.numerical.PairwiseComparisonNumerical).- Parameters
See also
Methods
Estimates the fitness for a player_type in the population with state :param strategies.
Estimates the payoffs for each strategy and returns the values in a matrix.
Size of the group.
Number of different group configurations.
Number of different strategies playing the game.
Returns the payoff of a strategy given a group composition.
Returns the payoff matrix of the game.
Calculate the payoff of each strategy inside the group.
Stores the payoff matrix in a txt file.
returns the type of game.
update an entry of the payoff matrix
- __init__(self: egttools.numerical.numerical.games.AbstractNPlayerGame, nb_strategies: int, group_size: int) None [source]¶
Abstract N-Player Game.
This abstract Game class can be used in most scenarios where the fitness of a strategy is calculated as its expected payoff given the population state.
It assumes that the game is N player, since the fitness of a strategy given a population state is calculated as the expected payoff of that strategy over all possible group combinations in the given state.
Notes
It might be a good idea to overwrite the methods
__str__
,type
, andsave_payoffs
to adapt to your given game implementationIt assumes that you have at least the following attributes: 1. And an attribute
self.nb_strategies_
which contains the number of strategies that you are going to analyse for the given game. 2.self.payoffs_
which must be a numpy.ndarray and contain the payoff matrix of the game. This array must be of shape (self.nb_strategies_, nb_group_configurations), where nb_group_configurations is the number of possible combinations of strategies in the group. Thus, each row should give the (expected) payoff of the row strategy when playing in a group with the column configuration. Thepayoff
method provides an easy way to access the payoffs for any group composition, by taking as arguments the index of the row strategy and a List with the count of each possible strategy in the group.You must still implement the methods
play
andcalculate_payoffs
which should define how the game assigns payoffs to each strategy for each possible game context. In particular,calculate_payoffs
should fill the arrayself.payoffs_
with the correct values as explained above. We recommend that you run this method in the__init__
(initialization of the object) since, these values must be set before passing the game object to the numerical simulator (e.g., egttools.numerical.PairwiseComparisonNumerical).- Parameters
See also
- __new__(**kwargs)¶
- 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
- 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]]
- 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.
- 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
- play(group_composition, game_payoffs)[source]¶
Calculate the payoff of each strategy inside the group.
$Pi_{D}(k) = (kFc) heta(k-M)$ $Pi_{C}(k) = Pi_{D}(k) - c$
- Parameters
group_composition (Union[List[int], numpy.ndarray]) – counts of each strategy inside the group.
game_payoffs (numpy.ndarray) – container for the payoffs of each strategy
- Return type