egttools.games.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:

Methods

calculate_fitness

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

calculate_payoffs

Calculates and stores all payoffs internally for all possible group compositions.

payoff

Returns the expected payoff of a specific strategy in a group.

play

Computes the payoff of each strategy for a given group composition.

save_payoffs

Saves the current payoff matrix to a file.

Attributes

nb_strategies

Returns the number of strategies available in the game.

payoffs

Returns the current payoff matrix of the game.

type

Returns the type of the game as a string.

__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:
__new__(**kwargs)
__str__()[source]

Returns a string representation of the game object.

Returns:

A string describing the game instance.

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]

Calculates and stores all payoffs internally for all possible group compositions.

This method must be called before computing fitness values or using the game in simulations.

Return type:

ndarray

payoff(strategy, group_composition)[source]

Returns the expected payoff of a specific strategy in a group.

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

  • group_composition (NDArray[np.int64]) – Vector specifying the number of individuals using each strategy.

Returns:

Expected payoff of the strategy in the given group context.

Return type:

float

play(group_composiiton, game_payoffs)[source]

Computes the payoff of each strategy for a given group composition.

This method modifies game_payoffs in-place to store the payoff of each strategy, given a group composed of the specified number of individuals per strategy.

This avoids memory reallocation by reusing the existing array, which can significantly speed up simulations.

Parameters:
  • group_composition (NDArray[np.int64]) – A vector of shape (n_strategies,) indicating the number of individuals playing each strategy in the group.

  • game_payoffs (NDArray[np.float64]) – A pre-allocated vector of shape (n_strategies,) which will be updated with the payoffs of each strategy in the group. Modified in-place.

Returns:

This function modifies game_payoffs directly.

Return type:

None

Examples

>>> group = np.array([1, 2, 0])
>>> out = np.zeros_like(group, dtype=np.float64)
>>> game.play(group, out)
>>> print(out)  # Contains payoffs for each strategy in the group
save_payoffs(file_name)[source]

Saves the current payoff matrix to a file.

Parameters:

file_name (str) – Name of the file to which the matrix should be saved.

Return type:

None

__annotations__ = {}
property nb_strategies: int

Returns the number of strategies available in the game.

Returns:

The total number of strategies.

Return type:

int

property payoffs: ndarray

Returns the current payoff matrix of the game.

Returns:

The stored payoff matrix used in the game.

Return type:

NDArray[np.float64]

property type: str

Returns the type of the game as a string.

Returns:

A label identifying the game type (e.g., “NormalFormGame”).

Return type:

str