egttools.games.informal_risk.InformalRiskGame¶
- class InformalRiskGame(group_size, cost, multiplying_factor, strategies)[source]¶
Bases:
AbstractGameGame 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
nb_strategies(-> int)Returns the number of strategies available in the game.
payoffs(...)Returns the current payoff matrix of the game.
type(-> str)Returns the type of the game as a string.
- classmethod __new__(*args, **kwargs)¶
- __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.
- __str__(self: egttools.numerical.numerical_.games.AbstractGame) 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) $ :param player_strategy: :type player_strategy:
int:param pop_size: (might be eliminated in the future) :type pop_size:int:param population_state: :type population_state:ndarray- Return type:
- Returns:
The fitness of the population.
- calculate_payoffs(self: egttools.numerical.numerical_.games.AbstractGame) Annotated[numpy.typing.NDArray[numpy.float64], '[m, n]'][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(self: egttools.numerical.numerical_.games.AbstractGame, strategy: SupportsInt | SupportsIndex, group_composition: collections.abc.Sequence[SupportsInt | SupportsIndex]) float[source]¶
Returns the expected payoff of a specific strategy in a group.
- play(self: egttools.numerical.numerical_.games.AbstractGame, group_composition: collections.abc.Sequence[SupportsInt | SupportsIndex], game_payoffs: collections.abc.Sequence[SupportsFloat | SupportsIndex]) None[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.
- Parameters:
group_composition (numpy.ndarray) – One-dimensional array indicating the number of individuals playing each strategy in the group.
game_payoffs (
ndarray) – Pre-allocated one-dimensional array that will be updated with the payoffs of each strategy.
- Returns:
This function modifies game_payoffs directly.
- Return type:
- save_payoffs(self: egttools.numerical.numerical_.games.AbstractGame, file_name: str) None[source]¶
Saves the current payoff matrix to a file.
- __annotations__ = {}¶
- InformalRiskGame.nb_strategies -> int
Returns the number of strategies available in the game.
- Returns:
The total number of strategies.
- Return type:
- InformalRiskGame.payoffs -> typing.Annotated[numpy.typing.NDArray[numpy.float64], "[m, n]"]
Returns the current payoff matrix of the game.
- Returns:
The stored payoff matrix used in the game.
- Return type:
- InformalRiskGame.type -> str
Returns the type of the game as a string.
- Returns:
A label identifying the game type.
- Return type: