egttools.games.MatrixNPlayerGameHolder¶
- class MatrixNPlayerGameHolder(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder, nb_strategies: int, group_size: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n]])¶
Bases:
AbstractGame
Holder class for N-player games for which the expected payoff between strategies has already been calculated.
This class is useful to store the matrix of expected payoffs between strategies in an N-player game and keep the methods to calculate the fitness between these strategies.
- Parameters
nb_strategies (int) – number of strategies in the game
group_size (int) – size of the group
payoff_matrix (numpy.ndarray) – matrix of shape (nb_strategies, nb_group_configurations) containing the payoffs of each strategy against any other strategy.
Methods
Calculates the fitness of a strategy given a population state.
Calculates the payoffs of every strategy in each possible group composition.
Size of the group.
Number of different group configurations.
Number of different strategies which are playing the game.
returns the payoff of a strategy given a group composition.
returns the expected payoffs of each strategy vs each possible game state
Plays the One-shop CRD and update the game_payoffs given the group_composition.
Saves the payoff matrix in a txt file.
updates the values of the payoff matrix.
- __init__(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder, nb_strategies: int, group_size: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n]]) None ¶
Holder class for N-player games for which the expected payoff between strategies has already been calculated.
This class is useful to store the matrix of expected payoffs between strategies in an N-player game and keep the methods to calculate the fitness between these strategies.
- Parameters
nb_strategies (int) – number of strategies in the game
group_size (int) – size of the group
payoff_matrix (numpy.ndarray) – matrix of shape (nb_strategies, nb_group_configurations) containing the payoffs of each strategy against any other strategy.
- __new__(**kwargs)¶
- __str__(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder) str ¶
- calculate_fitness(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder, player_strategy: int, pop_size: int, population_state: numpy.ndarray[numpy.uint64[m, 1]]) float ¶
Calculates the fitness of a strategy given a population state.
- Parameters
player_type (int) – The index of the strategy whose fitness will be calculated.
pop_size (int) – The size of the population (Z).
population_state (numpy.ndarray) – A vector containing the counts of each strategy in the population.
- Returns
The fitness of the strategy in the current population state.
- Return type
- calculate_payoffs(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder) numpy.ndarray[numpy.float64[m, n]] ¶
Calculates the payoffs of every strategy in each possible group composition.
- Returns
A matrix containing the payoff of each strategy in every possible group composition.
- Return type
- group_size(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder) int ¶
Size of the group.
- nb_group_configurations(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder) int ¶
Number of different group configurations.
- nb_strategies(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder) int ¶
Number of different strategies which are playing the game.
- payoff(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder, strategy: int, strategy pair: List[int]) float ¶
returns the payoff of a strategy given a group composition.
- payoffs(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder) numpy.ndarray[numpy.float64[m, n]] ¶
returns the expected payoffs of each strategy vs each possible game state
- play(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder, arg0: List[int], arg1: List[float]) None ¶
Plays the One-shop CRD and update the game_payoffs given the group_composition.
We always assume that strategy 0 is D and strategy 1 is C.
The payoffs of Defectors and Cooperators are described by the following equations:
\[ \begin{align}\begin{aligned}\Pi_{D}(k) = b\{\theta(k-M)+ (1-r)[1 - \theta(k-M)]\}\\\Pi_{C}(k) = \Pi_{D}(k) - cb\\\text{where } \theta(x) = 0 \text{if } x < 0 \text{ and 1 otherwise.}\end{aligned}\end{align} \]- Parameters
group_composition (Union[List[int], numpy.ndarray]) – A list or array containing the counts of how many members of each strategy are present in the group.
game_payoffs (numpy.ndarray) – A vector in which the payoffs of the game will be stored.
- save_payoffs(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder, arg0: str) None ¶
Saves the payoff matrix in a txt file.
- update_payoff_matrix(self: egttools.numerical.numerical.games.MatrixNPlayerGameHolder, payoff_matrix: numpy.ndarray[numpy.float64[m, n]]) None ¶
updates the values of the payoff matrix.