module documentation

This module contains methods to initialize and compute metrics for a small-world simulation.

Function clustering_coefficient Returns the average clustering coefficient for specified graph. This is a shortcut method to the `average_clustering()` method from NetworkX.
Function connect_initial_communities Connects communities at the start of the simulation.
Function form_community_lattice Instantiate a Graph and construct a lattice containing all community members.
Function form_community_lattices Instantiate a graph and add a group of communities in lattice structures.
Function form_dense_communities Returns a graph of fully connected communities.
Function form_dense_community Returns a graph with all possible edges added.
Function get_SWI_index Computes small world index (SWI).
Function initialize_small_world Sets up a small world graph for an experiment.
Function is_small_world Checks if a network qualifies as a small world.
Function make_lattice_from_nodes Construct a lattice structure out of existing nodes.
Function make_small_world_graph_info_file Creates an information file (.csv) for this small world experiment.
Function net_avg_degree Returns average degree of nodes in a graph.
Function small_world_rewire Rewires the small world network.
def clustering_coefficient(G):

Returns the average clustering coefficient for specified graph. This is a shortcut method to the `average_clustering()` method from NetworkX.

A clustering coefficient is a measure of how much nodes cluster together in a graph.

Parameters
Gtarget graph for computation
Returns
average clustering coefficient for specified graph
def connect_initial_communities(G):

Connects communities at the start of the simulation.

Parameters
Ggraph containing disconnected communities
Returns
graph containing connected communities
def form_community_lattice(community):

Instantiate a Graph and construct a lattice containing all community members.

Parameters
communitycommunity containing buyers/members
Returns
NetworkX Graph object in lattice structure
def form_community_lattices(community_set):

Instantiate a graph and add a group of communities in lattice structures.

Parameters
community_setlist of communities (with members) to add (CommunitySet)
Returns
NetworkX Graph object with communities in lattice structure
def form_dense_communities(community_set):

Returns a graph of fully connected communities.

Parameters
community_setList of communities (CommunitySet)
Returns
a graph of fully connected communities
def form_dense_community(community):

Returns a graph with all possible edges added.

Parameters
communitycommunity of buyers to fully connect
Returns
a fully connected community of buyers
def get_SWI_index(G):

Computes small world index (SWI).

Let n be the number of nodes in the graph. Let k be the average degree of nodes in the graph. Let L_path be the average shortest path length of nodes in the graph.

Parameters
Gtarget graph for computation
Returns
small world index of inputted graph
def initialize_small_world(num_buyers, num_communities, min_community_fill, assemblage, community_structure='dense'):

Sets up a small world graph for an experiment.

Parameters
num_buyersnumber of buyers in market
num_communitiesnumber of communities in market
min_community_fillminimum number of buyers per community
assemblagelist of items for sale in market
community_structurestructure to initialize communities; can be dense or lattice (default: dense)
Returns
small world graph of communities
def is_small_world(G, small_world_index_threshold=0.5):

Checks if a network qualifies as a small world.

Parameters
Gpotential small world network
small_world_index_thresholdqualifying SWI
Returns
True if qualifies as small world, False otherwise
def make_lattice_from_nodes(G):

Construct a lattice structure out of existing nodes.

Parameters
GNetworkX graph object containing nodes
Returns
restructured NetworkX graph object
def make_small_world_graph_info_file(num_buyers, min_num_communities, min_community_fill, assemblage, epochs, upper_thresh, lower_thresh, death_thresh, results_dir, prob_rewire, start_structure):

Creates an information file (.csv) for this small world experiment.

Parameters
num_buyersnumber of buyers in market
min_num_communitiesminimum number of communities
min_community_fillminimum number of buyers per community
assemblagelist of items for sale in market
epochsnumber of market iterations
upper_thresh% of buyers that must own a particular item to change a buyer's intention to that item
lower_threshmax % of buyers that may own a particular item to change a buyer's intention to random item
death_threshpercentage at which a pot is removed from the market
results_dirdirectory path in which to store the file
prob_rewireprobability that a node is rewired each epoch
start_structurestructure in which communities are initialized (dense or lattice)
def net_avg_degree(G):

Returns average degree of nodes in a graph.

Parameters
Gtarget graph for computation
Returns
average degree of nodes in a graph
def small_world_rewire(G, prob_rewire, epoch, logger):

Rewires the small world network.

Parameters
Gcurrent network structure
prob_rewireprobability of rewire for each node
epochcurrent epoch (for logger)
loggerlogging object
Returns
rewired graph