Network (network_init)
This page lists all the functions involved in generating the NetworkX Graph object. Most notably ‘generate_network’ is the factory method that you should call to produce a network from scratch, and ‘read_network’ is the function you should call when you want to produce a network from an adjacency matrix or edgelist.
generate_network
-
defSim.network_init.network_init.
generate_network
(name: str, network_modifiers=None, **kwargs) → networkx.classes.graph.Graph This factory method calls the graph generator and returns the desired network. It takes as arguments the name of the required network and a dictionary containing all the arguments that are required by the desired graph generator. defSim can produce three types networks (‘grid’, ‘spatial_random_graph’, and ‘ring’), but will also accept and call any network generator in the NetworkX Graph Generator library.
- Parameters
name – A string with the name of the network type. Possible options: “spatial_random_graph”, “ring”, “grid”
network_modifiers – A list of network modifiers to apply (in order) after network initialization
kwargs – A dictionary containing the parameter names as keys and their respective values as values to be passed to the function that produces the network.
- Raises
ValueError if not one of the possible network topologies is selected.
- Returns
A NetworkX Graph object.
read_network
-
defSim.network_init.network_init.
read_network
(network_input: numpy.ndarray) This function takes the structure of an empirically measured network, provided as an adjacency matrix, and creates a network graph object out of it.
- Parameters
network_input – Either an adjacency matrix where the entry (i,j) represents whether an edge between i and j exists or if applicable, its strength, or the path to a file containing an edge list
network_generators
-
defSim.network_init.network_init.
_produce_grid_network
(**kwargs) → networkx.classes.graph.Graph This method produces a grid graph, connected to itself as a torus. Each agent on the grid is connected to its neighborhood depending on the parameters “neighborhood” and “radius”.
- Parameters
num_agents (int=49) – How many agents the network contains.
neighborhood (String=moore) – Either “von_neumann” or “moore”. Von Neumann connects each agent to its 4 neighbors in each cardinal direction. In a Moore neighborhood, each agent is connected to their 8 immediate neighbors.
radius (int=1) – Increases the number of connections further than the immediate neigbourhood. An agent in a Moore neighborhood with radius 2 has 24 connections.
- Returns
A NetworkX Graph object.
-
defSim.network_init.network_init.
_produce_networkx_graph
(name: str, **kwargs) This method allows for passing on the graph generation to one of the generators included in the NetworkX package. Provide the name of the method as the first argument here, and pass all (required) arguments for the NetworkX function in the kwargs dictionary.
- Parameters
name – Name of the NetworkX graph generator to be used
kwargs – A dictionary containing the parameter names as keys and their respective values as values to be passed to the function that produces the network.
- Returns
A NetworkX Graph object.
-
defSim.network_init.network_init.
_produce_ring_network
(**kwargs) → networkx.classes.graph.Graph This method produces a ring network with varying number of neighbors.
- Parameters
num_agents (int=49) – The number of agents the network should contain.
num_neighbors (int=2) – The number of neighbors per agent. Must be an even number.
- Returns
A NetworkX Graph object.
-
defSim.network_init.network_init.
_produce_spatial_random_graph
(**kwargs) → networkx.classes.graph.Graph This method produces a Spatial Random Graph.
- Parameters
num_agents (int=49) – How many agents the network contains.
min_neighbors (int=8) – How many neighborhood each agent should have at least.
proximity_weight (float=1) – Determines how much spatial distance in the grid matters in the rewiring process.
- Returns
A networkx Graph object.