egttools.calculate_hypergeometric_fitness¶
- calculate_hypergeometric_fitness()¶
Compute the fitness of a focal player (not included in
strategies) via hypergeometric sampling.This is the standard EGT fitness calculation for finite populations:
fitness = sum_g P(g | strategies, pop_size-1, group_size-1) * payoff(player_type, g)
where g ranges over all group configurations that include the focal player (i.e.
g[player_type] >= 1), and P is the multivariate hypergeometric probability that the remaining group_size-1 slots are filled from the background population (which hasstrategiesindividuals, not including the focal player).- Parameters:
player_type (int) – Index of the focal player’s strategy (0-based).
pop_size (int) – Total population size including the focal player.
group_size (int) – Number of individuals in the interaction group including the focal player.
nb_strategies (int) – Number of distinct strategies.
strategies (numpy.ndarray) – Integer array of length
nb_strategieswith counts of each strategy in the population excluding the focal player. Must sum topop_size - 1.payoffs_row (numpy.ndarray) – Float array of length
calculate_nb_states(group_size, nb_strategies)wherepayoffs_row[g]is the payoff ofplayer_typein group configurationsample_simplex(g, group_size, nb_strategies).
- Returns:
Expected fitness of the focal player.
- Return type:
Examples
>>> import numpy as np >>> import egttools as egt >>> pop_size, group_size, nb_strategies = 10, 3, 2 >>> # Focal player is a cooperator (strategy 1), population has 5 C, 4 D (excluding focal) >>> strategies = np.array([4, 5], dtype=np.uint64) >>> # payoffs_row[g] = payoff of cooperator in group config g >>> nb_configs = egt.calculate_nb_states(group_size, nb_strategies) >>> payoffs_row = np.zeros(nb_configs) >>> for g in range(nb_configs): ... gc = egt.sample_simplex(g, group_size, nb_strategies) ... payoffs_row[g] = gc[1] - 1.0 # cooperators pay cost 1 >>> egt.calculate_hypergeometric_fitness(1, pop_size, group_size, nb_strategies, strategies, payoffs_row)