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 base class represents a symmetric N-player game in which each strategy’s fitness is computed as the expected payoff over all group compositions in a population.
Notes
Subclasses must implement the play and calculate_payoffs methods. The following attributes are expected: - self.nb_strategies_ (int): number of strategies. - self.payoffs_ (numpy.ndarray): of shape (nb_strategies, nb_group_configurations).
- Parameters:
Methods
Computes the fitness of a given strategy in a population state.
Computes and returns the full payoff matrix.
Returns the size of the group.
Returns the number of distinct group configurations.
Returns the number of strategies in the game.
Returns the payoff of a strategy in a given group context.
Returns the payoff matrix.
Calculate the payoff of each strategy inside the group.
Saves the payoff matrix to a text file.
Returns the string identifier for the game.
Updates an entry in the payoff matrix.
- __init__(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, nb_strategies: int, group_size: int) None [source]¶
Abstract N-Player Game.
This abstract base class represents a symmetric N-player game in which each strategy’s fitness is computed as the expected payoff over all group compositions in a population.
Notes
Subclasses must implement the play and calculate_payoffs methods. The following attributes are expected: - self.nb_strategies_ (int): number of strategies. - self.payoffs_ (numpy.ndarray): of shape (nb_strategies, nb_group_configurations).
- __new__(**kwargs)¶
- 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:
- 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:
- group_size(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int ¶
Returns the size of the group.
- Return type:
- nb_group_configurations(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int ¶
Returns the number of distinct group configurations.
- Return type:
- nb_strategies(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int ¶
Returns the number of strategies in the game.
- Return type:
- 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.
- 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:
- 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:
- 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.
- __annotations__ = {}¶