egttools.numerical.structure.Network¶
- class Network(self: egttools.numerical.numerical_.structure.Network, nb_strategies: int, beta: float, mu: float, network: dict[int, list[int]], game: egttools.numerical.numerical_.games.AbstractSpatialGame, cache_size: int = 1000)¶
Bases:
AbstractNetworkStructure
Network structure.
This population structure assumes that players are connected in a network. The network input parameter, is a dictionary which indicates how individuals are connected. The keys of the dictionary are the nodes in the network and the value associated with each key is a list of neighbors to which the node is connected.
We assume that the network is directed. To produce an undirected network, it is enough to consider that 2 connected nodes are in the neighborhood of each other.
This structure only implements asynchronous updates at the moment. This means that at each update step, only one member of the population can be updated. Moreover, the network is static (no links are changed between the nodes).
The update mechanism is pairwise imitation. This is, at a given time step an individual i is selected randomly to die. Another individual j, is selected randomly from i’s neighborhood. i will imitate the strategy of j with probability proportional to the difference of payoffs between them (using the fermi distribution with temperature beta).
The fitness of an individual is given by the calculate_fitness function of the Game object.
- Parameters:
nb_strategies (int) – The maximum number of strategies that can exist in the population.
beta (float) – The intensity of selection.
mu (float) – Mutation probability
network (Dict[int, List[int]]) – Dictionary containing the list of neighbors for each node in the network.
game (egttools.games.AbstractSpatialGame) – The game that the population will play.
cache_size (int) – The size of the cache memory used to save the fitness of each strategy given a neighborhood state.
Methods
Calculates the average gradient of selection at the current state of the network.
calculate_average_gradient_of_selection_and_update_population
Calculates the average gradient of selection at the current state of the network.
Calculates the fitness of a strategy given a neighborhood state.
Returns the game played by the population
Initializes each element of the structure.
Initializes each element of the structure at given state.
Returns a numpy array contain the total counts of strategies in the population.
Returns the maximum number of strategies in the population
Returns a dictionary with list of neighbors for each node in the network.
Returns the number of individuals in the population.
Returns a list containing the strategy adopted by each node in the network.
Updates the strategy of a given node.
Updates the population for one generation.
- __init__(self: egttools.numerical.numerical_.structure.Network, nb_strategies: int, beta: float, mu: float, network: dict[int, list[int]], game: egttools.numerical.numerical_.games.AbstractSpatialGame, cache_size: int = 1000) None ¶
Network structure.
This population structure assumes that players are connected in a network. The network input parameter, is a dictionary which indicates how individuals are connected. The keys of the dictionary are the nodes in the network and the value associated with each key is a list of neighbors to which the node is connected.
We assume that the network is directed. To produce an undirected network, it is enough to consider that 2 connected nodes are in the neighborhood of each other.
This structure only implements asynchronous updates at the moment. This means that at each update step, only one member of the population can be updated. Moreover, the network is static (no links are changed between the nodes).
The update mechanism is pairwise imitation. This is, at a given time step an individual i is selected randomly to die. Another individual j, is selected randomly from i’s neighborhood. i will imitate the strategy of j with probability proportional to the difference of payoffs between them (using the fermi distribution with temperature beta).
The fitness of an individual is given by the calculate_fitness function of the Game object.
- Parameters:
nb_strategies (int) – The maximum number of strategies that can exist in the population.
beta (float) – The intensity of selection.
mu (float) – Mutation probability
network (Dict[int, List[int]]) – Dictionary containing the list of neighbors for each node in the network.
game (egttools.games.AbstractSpatialGame) – The game that the population will play.
cache_size (int) – The size of the cache memory used to save the fitness of each strategy given a neighborhood state.
- __new__(**kwargs)¶
- calculate_average_gradient_of_selection(self: egttools.numerical.numerical_.structure.Network) numpy.ndarray[numpy.float64[m, 1]] ¶
Calculates the average gradient of selection at the current state of the network.
This method averages the difference in transition probabilities of increasing and decreasing the count of each strategy in the population at each node of the network. It runs a single trial.
To obtain the true gradient of selection for a given average network state, this method must be run multiple times with different initializations of the network. In the limit, the best calculation would be obtained by averaging the computations at any possible initialization of the network in a given aggregated state.
- Returns:
The averaged gradient of selection for each strategy in the population at the current network structure.
- Return type:
numpy.array
- calculate_average_gradient_of_selection_and_update_population(self: egttools.numerical.numerical_.structure.Network) numpy.ndarray[numpy.float64[m, 1]] ¶
Calculates the average gradient of selection at the current state of the network.
This method averages the difference in transition probabilities of increasing and decreasing the count of each strategy in the population at each node of the network. It runs a single trial.
To obtain the true gradient of selection for a given average network state, this method must be run multiple times with different initializations of the network. In the limit, the best calculation would be obtained by averaging the computations at any possible initialization of the network in a given aggregated state.
- Returns:
The averaged gradient of selection for each strategy in the population at the current network structure.
- Return type:
numpy.array
- calculate_fitness(self: egttools.numerical.numerical_.structure.Network, arg0: int) float ¶
Calculates the fitness of a strategy given a neighborhood state.
The neighborhood state is the counts of each strategy in the neighborhood.
- game(self: egttools.numerical.numerical_.structure.Network) egttools.numerical.numerical_.games.AbstractSpatialGame ¶
Returns the game played by the population
- Returns:
The game played by the population.
- Return type:
- initialize(self: egttools.numerical.numerical_.structure.Network) None ¶
Initializes each element of the structure.
Each individual will adopt any of the available strategies with equal probability. If the population is big enough and divisible by the number of strategies, This should result in a roughly equal distribution of each strategy.
- initialize_state(self: egttools.numerical.numerical_.structure.Network, state: numpy.ndarray[numpy.uint64[m, 1]]) None ¶
Initializes each element of the structure at given state.
In Evolutionary games, this means that each individual in the structure is assigned a strategy according to some algorithm (generally it will be a random assignment) until the counts of each strategy in the population match that of state.
- Parameters:
state (numpy.ndarray) – A numpy array containing the counts of each strategy in the population
- mean_population_state(self: egttools.numerical.numerical_.structure.Network) numpy.ndarray[numpy.uint64[m, 1]] ¶
Returns a numpy array contain the total counts of strategies in the population.
- Returns:
A numpy array contain the total counts of strategies in the population.
- Return type:
- nb_strategies(self: egttools.numerical.numerical_.structure.Network) int ¶
Returns the maximum number of strategies in the population
- Returns:
The maximum number of strategies in the population.
- Return type:
- network(self: egttools.numerical.numerical_.structure.Network) dict[int, list[int]] ¶
Returns a dictionary with list of neighbors for each node in the network.
- population_size(self: egttools.numerical.numerical_.structure.Network) int ¶
Returns the number of individuals in the population.
- Returns:
The number of individuals in the population.
- Return type:
- population_strategies(self: egttools.numerical.numerical_.structure.Network) list[int] ¶
Returns a list containing the strategy adopted by each node in the network.
- Returns:
A list containing the strategy adopted by each node in the network.
- Return type:
List[int]
- update_node(self: egttools.numerical.numerical_.structure.Network, node: int) None ¶
Updates the strategy of a given node.
- Parameters:
node (int) – Node to update.
- update_population(self: egttools.numerical.numerical_.structure.Network) None ¶
Updates the population for one generation.
The developer has freedom to implement this method. All that is required is that it applies some change to the population every time it is called given the current population state.
- __annotations__ = {}¶