egttools.games.informal_risk.InformalRiskGame

class InformalRiskGame(group_size, cost, multiplying_factor, strategies)[source]

Bases: AbstractGame

Game of informal risk sharing.

This game has been taken from the model introduced in

`Santos, F. P., Pacheco, J. M., Santos, F. C., & Levin, S. A. (2021). Dynamics of informal risk sharing in collective index insurance. Nature Sustainability. https://doi.org/10.1038/s41893-020-00667-2`

to investigate the dynamics of a collective index insurance with informal risk sharing.

Parameters
  • group_size (int) –

  • cost (float) –

  • multiplying_factor (float) –

  • strategies (List) –

Methods

calculate_fitness

Calculates the Fitness of an strategy for a given population state.

calculate_payoffs

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

payoff

Returns the payoff of a strategy given a group composition.

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.

Attributes

nb_strategies

Number of different strategies playing the game.

payoffs

Returns the payoff matrix of the game.

type

returns the type of game.

__init__(group_size, cost, multiplying_factor, strategies)[source]

Game of informal risk sharing.

This game has been taken from the model introduced in

`Santos, F. P., Pacheco, J. M., Santos, F. C., & Levin, S. A. (2021). Dynamics of informal risk sharing in collective index insurance. Nature Sustainability. https://doi.org/10.1038/s41893-020-00667-2`

to investigate the dynamics of a collective index insurance with informal risk sharing.

Parameters
  • group_size (int) –

  • cost (float) –

  • multiplying_factor (float) –

  • strategies (List) –

__new__(**kwargs)
__str__()[source]
Return type

str

calculate_fitness(player_strategy, pop_size, population_state)[source]

Calculates the Fitness of an strategy for a given population state.

The calculation is done by computing the expected payoff over all possible group combinations for the given population state: $ fitness = sum_{states} payoff * P(state) $ :type player_strategy: int :param player_strategy: :type player_strategy: index of the strategy :type pop_size: int :param pop_size: (might be eliminated in the future) :type pop_size: size of the population - Only necessary for compatibility with the C++ implementation :type population_state: ndarray :param population_state: :type population_state: vector with the population state (the number of players adopting each strategy)

Return type

The fitness of the population.

calculate_payoffs()[source]

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.

Returns

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

Return type

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

payoff(strategy, group_composition)[source]

Returns the payoff of a strategy given a group composition.

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.

  • group_composition (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

play(group_composiiton, game_payoffs)[source]

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

Return type

None

save_payoffs(file_name)[source]

Stores the payoff matrix in a txt file.

Parameters

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

Return type

None

property nb_strategies: int

Number of different strategies playing the game.

Return type

int

property payoffs: ndarray

Returns the payoff matrix of the game.

Returns

The payoff matrix.

Return type

numpy.ndarray

property type: str

returns the type of game.

Return type

str