egttools.games.Matrix2PlayerGameHolder¶
- class Matrix2PlayerGameHolder(self: egttools.numerical.numerical.games.Matrix2PlayerGameHolder, nb_strategies: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n]])¶
Bases:
AbstractGame
Holder class for 2-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 2-player game and keep the methods to calculate the fitness between these strategies.
- Parameters
nb_strategies (int) – number of strategies in the game
payoff_matrix (numpy.ndarray) – matrix of shape (nb_strategies, nb_strategies) containing the payoffs of each strategy against any other strategy.
See also
egttools.games.Matrix2NlayerGameHolder
,egttools.games.AbstractGame
Methods
Calculates the fitness of a strategy given a population state.
Calculates the payoffs of every strategy in each possible group composition.
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.Matrix2PlayerGameHolder, nb_strategies: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n]]) None ¶
Holder class for 2-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 2-player game and keep the methods to calculate the fitness between these strategies.
- Parameters
nb_strategies (int) – number of strategies in the game
payoff_matrix (numpy.ndarray) – matrix of shape (nb_strategies, nb_strategies) containing the payoffs of each strategy against any other strategy.
See also
egttools.games.Matrix2NlayerGameHolder
,egttools.games.AbstractGame
- __new__(**kwargs)¶
- __str__(self: egttools.numerical.numerical.games.Matrix2PlayerGameHolder) str ¶
- calculate_fitness(self: egttools.numerical.numerical.games.Matrix2PlayerGameHolder, 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.Matrix2PlayerGameHolder) 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
- nb_strategies(self: egttools.numerical.numerical.games.Matrix2PlayerGameHolder) int ¶
Number of different strategies which are playing the game.
- payoff(self: egttools.numerical.numerical.games.Matrix2PlayerGameHolder, strategy: int, strategy pair: List[int]) float ¶
returns the payoff of a strategy given a group composition.
- payoffs(self: egttools.numerical.numerical.games.Matrix2PlayerGameHolder) numpy.ndarray[numpy.float64[m, n]] ¶
returns the expected payoffs of each strategy vs each possible game state
- play(self: egttools.numerical.numerical.games.Matrix2PlayerGameHolder, 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.Matrix2PlayerGameHolder, arg0: str) None ¶
Saves the payoff matrix in a txt file.
- update_payoff_matrix(self: egttools.numerical.numerical.games.Matrix2PlayerGameHolder, payoff_matrix: numpy.ndarray[numpy.float64[m, n]]) None ¶
updates the values of the payoff matrix.