egttools.games.NormalFormGame

class NormalFormGame(*args, **kwargs)

Bases: AbstractGame

Overloaded function.

  1. __init__(self: egttools.numerical.numerical.games.NormalFormGame, nb_rounds: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n], flags.c_contiguous]) -> None

    Normal Form Game. This constructor assumes that there are only two possible strategies and two possible actions.

    This class will run the game using the players and player types defined in :param group_composition, and will update the vector :param game_payoffs with the resulting payoff of each player.

    nb_roundsint

    Number of rounds of the game.

    payoff_matrixnumpy.ndarray[numpy.float64[m, m]]

    A payoff matrix of shape (nb_actions, nb_actions).

    egttools.games.AbstractGame, egttools.games.AbstractNPlayerGame, egttools.games.CRDGame, egttools.games.CRDGameTU, egttools.behaviors.NormalForm.TwoActions

  2. __init__(self: egttools.numerical.numerical.games.NormalFormGame, nb_rounds: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n], flags.c_contiguous], strategies: list) -> None

    Normal Form Game.

    This constructor allows you to define any number of strategies by passing a list of pointers to them. All strategies must by of type AbstractNFGStrategy *.

    nb_roundsint

    Number of rounds of the game.

    payoff_matrixnumpy.ndarray[float]

    A payoff matrix of shape (nb_actions, nb_actions).

    strategiesList[egttools.behaviors.AbstractNFGStrategy]

    A list containing references of AbstractNFGStrategy strategies (or child classes).

    egttools.games.AbstractGame

Methods

calculate_cooperation_rate

Calculates the rate/level of cooperation in the population at a given population state.

calculate_fitness

Estimates the fitness for a player_type in the population with state :param strategies.

calculate_payoffs

Estimates the payoffs for each strategy and returns the values in a matrix.

expected_payoffs

returns the expected payoffs of each strategy vs another

nb_strategies

Number of different strategies which are playing the game.

payoff

Returns the payoff of a strategy given a strategy pair.

payoffs

Returns the payoff matrix of the game.

play

Updates the vector of payoffs with the payoffs of each player after playing the game.

save_payoffs

Stores the payoff matrix in a txt file.

type

Attributes

nb_rounds

Number of rounds of the game.

nb_states

Number of combinations of 2 strategies that can be matched in the game.

strategies

A list with pointers to the strategies that are playing the game.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: egttools.numerical.numerical.games.NormalFormGame, nb_rounds: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n], flags.c_contiguous]) -> None

    Normal Form Game. This constructor assumes that there are only two possible strategies and two possible actions.

    This class will run the game using the players and player types defined in :param group_composition, and will update the vector :param game_payoffs with the resulting payoff of each player.

    nb_roundsint

    Number of rounds of the game.

    payoff_matrixnumpy.ndarray[numpy.float64[m, m]]

    A payoff matrix of shape (nb_actions, nb_actions).

    egttools.games.AbstractGame, egttools.games.AbstractNPlayerGame, egttools.games.CRDGame, egttools.games.CRDGameTU, egttools.behaviors.NormalForm.TwoActions

  2. __init__(self: egttools.numerical.numerical.games.NormalFormGame, nb_rounds: int, payoff_matrix: numpy.ndarray[numpy.float64[m, n], flags.c_contiguous], strategies: list) -> None

    Normal Form Game.

    This constructor allows you to define any number of strategies by passing a list of pointers to them. All strategies must by of type AbstractNFGStrategy *.

    nb_roundsint

    Number of rounds of the game.

    payoff_matrixnumpy.ndarray[float]

    A payoff matrix of shape (nb_actions, nb_actions).

    strategiesList[egttools.behaviors.AbstractNFGStrategy]

    A list containing references of AbstractNFGStrategy strategies (or child classes).

    egttools.games.AbstractGame

__new__(**kwargs)
__str__(self: egttools.numerical.numerical.games.NormalFormGame) str
calculate_cooperation_rate(self: egttools.numerical.numerical.games.NormalFormGame, population_size: int, population_state: numpy.ndarray[numpy.uint64[m, 1]]) float

Calculates the rate/level of cooperation in the population at a given population state.

Parameters
  • population_size (int) – The size of the population.

  • population_state (numpy.ndarray[numpy.uint64[m, 1]]) – A vector of counts of each strategy in the population. The current state of the population.

Returns

The level of cooperation at the population_state.

Return type

float

calculate_fitness(self: egttools.numerical.numerical.games.NormalFormGame, player_strategy: int, population_size: int, population_state: 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
  • player_type (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

float

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

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.

This method also updates a matrix that stores the cooperation level of each strategy against any other.

Returns

A matrix with the expected payoffs for each strategy given each possible game state.

Return type

numpy.ndarray[numpy.float64[m, n]]

expected_payoffs(self: egttools.numerical.numerical.games.NormalFormGame) numpy.ndarray[numpy.float64[m, n]]

returns the expected payoffs of each strategy vs another

nb_strategies(self: egttools.numerical.numerical.games.NormalFormGame) int

Number of different strategies which are playing the game.

payoff(self: egttools.numerical.numerical.games.NormalFormGame, strategy: int, strategy_pair: List[int]) float

Returns the payoff of a strategy given a strategy pair.

If the group composition does not include the strategy, the payoff should be zero.

Parameters
  • strategy (int) – The index of the strategy used by the player.

  • strategy_pair (List[int]) – List with the group composition. The structure of this list depends on the particular implementation of this abstract method.

Returns

The payoff value.

Return type

float

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

Returns the payoff matrix of the game.

Returns

The payoff matrix.

Return type

numpy.ndarray

play(self: egttools.numerical.numerical.games.NormalFormGame, group_composition: List[int], game_payoffs: List[float]) None

Updates the vector of payoffs with the payoffs of each player after playing the game.

This method will run the game using the players and player types defined in :param group_composition, and will update the vector :param game_payoffs with the resulting payoff of each player.

Parameters
  • group_composition (List[int]) – A list with counts of the number of players of each strategy in the group.

  • game_payoffs (List[float]) – A list used as container for the payoffs of each player

save_payoffs(self: egttools.numerical.numerical.games.NormalFormGame, arg0: str) None

Stores the payoff matrix in a txt file.

Parameters

file_name (str) – Name of the file in which the data will be stored.

type(self: egttools.numerical.numerical.games.NormalFormGame) str
property nb_rounds

Number of rounds of the game.

property nb_states

Number of combinations of 2 strategies that can be matched in the game.

property strategies

A list with pointers to the strategies that are playing the game.