egttools.games.Matrix2PlayerGameHolder

class Matrix2PlayerGameHolder(self: egttools.numerical.numerical_.games.Matrix2PlayerGameHolder, nb_strategies: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n], flags.c_contiguous])

Bases: AbstractGame

Matrix-based 2-Player Game Holder.

Stores the expected payoffs between strategies in a 2-player game. This class is useful for simulations where the payoff matrix is externally computed and fixed, enabling fast fitness calculations without recomputation.

Parameters:
  • nb_strategies (int) – Number of strategies used in the game.

  • payoff_matrix (numpy.ndarray[float64[m, m]]) – Matrix containing the payoff of each strategy against all others.

Methods

calculate_fitness

Computes the fitness of a strategy given the population configuration.

calculate_payoffs

Returns the stored payoff matrix.

nb_strategies

Returns the number of strategies in the game.

payoff

Returns the payoff for a given strategy pair.

payoffs

Returns the expected payoff matrix.

play

Executes a match given a group composition and stores the resulting payoffs.

save_payoffs

Saves the current payoff matrix to a text file.

type

update_payoff_matrix

Replaces the internal payoff matrix with a new one.

__init__(self: egttools.numerical.numerical_.games.Matrix2PlayerGameHolder, nb_strategies: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n], flags.c_contiguous]) None

Matrix-based 2-Player Game Holder.

Stores the expected payoffs between strategies in a 2-player game. This class is useful for simulations where the payoff matrix is externally computed and fixed, enabling fast fitness calculations without recomputation.

Parameters:
  • nb_strategies (int) – Number of strategies used in the game.

  • payoff_matrix (numpy.ndarray[float64[m, m]]) – Matrix containing the payoff of each strategy against all others.

__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

Computes the fitness of a strategy given the population configuration.

Assumes the focal player is not included in the population state.

Parameters:
  • player_type (int) – Index of the focal strategy.

  • pop_size (int) – Size of the population.

  • population_state (numpy.ndarray) – Vector of counts of each strategy in the population.

Return type:

float

calculate_payoffs(self: egttools.numerical.numerical_.games.Matrix2PlayerGameHolder) numpy.ndarray[numpy.float64[m, n]]

Returns the stored payoff matrix.

Returns:

Payoff matrix of shape (nb_strategies, nb_strategies).

Return type:

numpy.ndarray

nb_strategies(self: egttools.numerical.numerical_.games.Matrix2PlayerGameHolder) int

Returns the number of strategies in the game.

payoff(self: egttools.numerical.numerical_.games.Matrix2PlayerGameHolder, strategy: int, strategy pair: list[int]) float

Returns the payoff for a given strategy pair.

payoffs(self: egttools.numerical.numerical_.games.Matrix2PlayerGameHolder) numpy.ndarray[numpy.float64[m, n]]

Returns the expected payoff matrix.

play(self: egttools.numerical.numerical_.games.Matrix2PlayerGameHolder, arg0: list[int], arg1: list[float]) None

Executes a match given a group composition and stores the resulting payoffs.

Parameters:
save_payoffs(self: egttools.numerical.numerical_.games.Matrix2PlayerGameHolder, arg0: str) None

Saves the current payoff matrix to a text file.

type(self: egttools.numerical.numerical_.games.Matrix2PlayerGameHolder) str
update_payoff_matrix(self: egttools.numerical.numerical_.games.Matrix2PlayerGameHolder, payoff_matrix: numpy.ndarray[numpy.float64[m, n]]) None

Replaces the internal payoff matrix with a new one.

__annotations__ = {}