egttools.games.nonlinear_games.CommonPoolResourceDilemmaCommitment¶
- class CommonPoolResourceDilemmaCommitment(group_size, a, b, cost, fine, strategies)[source]¶
Bases:
AbstractNPlayerGame
Common Pool resource game with commitment, but the threshold is set as another strategy :type group_size:
int
:param group_size: Size of the group playing the game. :type group_size: int :param a and b: Both a and b are the parameters of the game, if a>>b, then it’s attractive to invest in the CPR :type a and b: flaot :type cost:float
:param cost: cost of making the commitment for commitment proposing strategy :type fine:float
:param fine: fine for defection when accepting the commitment :type fine: float :type strategies:List
[AbstractCPRStrategy
] :param strategies: List of strategies which will play the game :type strategies: Lit[int]Methods
Computes the fitness of a given strategy in a population state.
Computes and returns the full payoff matrix.
Returns the size of the group.
Returns the number of distinct group configurations.
Returns the number of strategies in the game.
Returns the payoff of a strategy in a given group context.
Returns the payoff matrix.
Executes the game for a given group composition and fills the payoff vector.
Saves the payoff matrix to a text file.
Returns the string identifier for the game.
Updates an entry in the payoff matrix.
- __init__(group_size, a, b, cost, fine, strategies)[source]¶
Common Pool resource game with commitment, but the threshold is set as another strategy :type group_size:
int
:param group_size: Size of the group playing the game. :type group_size: int :param a and b: Both a and b are the parameters of the game, if a>>b, then it’s attractive to invest in the CPR :type a and b: flaot :type cost:float
:param cost: cost of making the commitment for commitment proposing strategy :type fine:float
:param fine: fine for defection when accepting the commitment :type fine: float :type strategies:List
[AbstractCPRStrategy
] :param strategies: List of strategies which will play the game :type strategies: Lit[int]
- __new__(**kwargs)¶
- __str__(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) str ¶
Returns a string representation of the game.
- Return type:
- calculate_fitness(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, strategy_index: int, pop_size: int, strategies: numpy.ndarray[numpy.uint64[m, 1]]) float ¶
Computes the fitness of a given strategy in a population state.
- Parameters:
strategy_index (int) – The strategy of the focal player.
pop_size (int) – Total population size (excluding the focal player).
strategies (numpy.ndarray[uint64]) – The population state as a strategy count vector.
- Returns:
Fitness of the focal strategy in the given state.
- Return type:
- calculate_payoffs()[source]¶
Computes and returns the full payoff matrix.
- Returns:
A matrix with expected payoffs. Each row represents a strategy, each column a group configuration.
- Return type:
- check_if_commitment_validated(nb_committed, group_composition, commitment_accepted)[source]¶
- Return type:
- group_size(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int ¶
Returns the size of the group.
- Return type:
- nb_group_configurations(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int ¶
Returns the number of distinct group configurations.
- Return type:
- nb_strategies(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int ¶
Returns the number of strategies in the game.
- Return type:
- payoff(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, strategy: int, group_composition: list[int]) float ¶
Returns the payoff of a strategy in a given group context.
- payoffs(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) numpy.ndarray[numpy.float64[m, n]] ¶
Returns the payoff matrix.
- Returns:
The matrix of shape (nb_strategies, nb_group_configurations).
- Return type:
- play(group_composition, game_payoffs)[source]¶
Executes the game for a given group composition and fills the payoff vector.
- Parameters:
group_composition (List[int] | numpy.ndarray[int]) – The number of players of each strategy in the group.
game_payoffs (List[float] | numpy.ndarray[float]) – Output container where the payoff of each player will be written.
- Return type:
- save_payoffs(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, file_name: str) None ¶
Saves the payoff matrix to a text file.
- Parameters:
file_name (str) – Destination file path.
- type(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) str ¶
Returns the string identifier for the game.
- Return type:
- update_payoff(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, strategy_index: int, group_configuration_index: int, value: float) None ¶
Updates an entry in the payoff matrix.
- __annotations__ = {}¶