egttools.games.opinion_game.OpinionGame

class OpinionGame(group_size, peer_pressure_importance, peer_pressure_ratio, opinion_values)[source]

Bases: AbstractNPlayerGame

Classical Public Goods game with only 2 possible contributions (o or cost).

Parameters:
  • group_size (int) – Size of the group playing the game.

  • peer_pressure_importance (float) – Importance of being close in opinion to your group

  • peer_pressure_ratio (float) – Ratio at which the peer pressure is more important

  • opinion_values (List[float]) – Value of each opinion

Methods

calculate_fitness

Computes the fitness of a given strategy in a population state.

calculate_payoffs

Computes and returns the full payoff matrix.

group_size

nb_group_configurations

nb_strategies

payoff

Returns the payoff of a strategy in a given group context.

payoffs

Returns the payoff matrix.

play

Executes the game for a given group composition and fills the payoff vector.

save_payoffs

Saves the payoff matrix to a text file.

type

update_payoff

Updates an entry in the payoff matrix.

__init__(group_size, peer_pressure_importance, peer_pressure_ratio, opinion_values)[source]

Classical Public Goods game with only 2 possible contributions (o or cost).

Parameters:
  • group_size (int) – Size of the group playing the game.

  • peer_pressure_importance (float) – Importance of being close in opinion to your group

  • peer_pressure_ratio (float) – Ratio at which the peer pressure is more important

  • opinion_values (List[float]) – Value of each opinion

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

str

calculate_fitness(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, strategy_index: SupportsInt | SupportsIndex, pop_size: SupportsInt | SupportsIndex, strategies: Annotated[numpy.typing.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.

  • strategies (numpy.ndarray) – Population state as a strategy count vector.

Returns:

Fitness of the focal strategy in the given state.

Return type:

float

calculate_payoffs()[source]

Computes and returns the full payoff matrix.

Returns:

A matrix with expected payoffs. Each row represents a strategy, and each column a group configuration.

Return type:

numpy.ndarray

group_size(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int
nb_group_configurations(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int
nb_strategies(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) int
payoff(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, strategy: SupportsInt | SupportsIndex, group_composition: collections.abc.Sequence[SupportsInt | SupportsIndex]) float

Returns the payoff of a strategy in a given group context.

Parameters:
  • strategy (int) – The strategy index.

  • group_composition (numpy.ndarray) – The group configuration.

Returns:

The corresponding payoff.

Return type:

float

payoffs(self: egttools.numerical.numerical_.games.AbstractNPlayerGame) Annotated[numpy.typing.NDArray[numpy.float64], '[m, n]']

Returns the payoff matrix.

Returns:

Matrix of shape (nb_strategies, nb_group_configurations).

Return type:

numpy.ndarray

play(group_composition, game_payoffs)[source]

Executes the game for a given group composition and fills the payoff vector.

Parameters:
  • group_composition (numpy.ndarray) – One-dimensional array containing the number of players of each strategy in the group.

  • game_payoffs (numpy.ndarray) – Output container where the payoff of each strategy will be written.

Return type:

None

save_payoffs(file_name)[source]

Saves the payoff matrix to a text file.

Parameters:

file_name (str) – Destination file path.

Return type:

None

type()[source]
Return type:

str

update_payoff(self: egttools.numerical.numerical_.games.AbstractNPlayerGame, strategy_index: SupportsInt | SupportsIndex, group_configuration_index: SupportsInt | SupportsIndex, value: SupportsFloat | SupportsIndex) None

Updates an entry in the payoff matrix.

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

  • group_configuration_index (int) – Index of the group composition.

  • value (float) – The new payoff value.

__annotations__ = {}