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.
Methods
Calculates the Fitness of an strategy for a given population state.
Calculates and stores all payoffs internally for all possible group compositions.
Returns the expected payoff of a specific strategy in a group.
Computes the payoff of each strategy for a given group composition.
Saves the current payoff matrix to a file.
Attributes
Returns the number of strategies available in the game.
Returns the current payoff matrix of the game.
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.
- __new__(**kwargs)¶
- __str__()[source]¶
Returns a string representation of the game object.
- Returns:
A string describing the game instance.
- Return type:
- 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:
- payoff(strategy, group_composition)[source]¶
Returns the expected payoff of a specific strategy in a group.
- 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
- __annotations__ = {}¶
- property nb_strategies: int¶
Returns the number of strategies available in the game.
- Returns:
The total number of strategies.
- Return type: