def construct_graph_list_und(graphs_to_const): """Construct and return a list of graphs so graph construction is easily repeatable. Can handle: Random, Small-world, Scale-free, SGPA, SGPA-random""" graph_list = [] # Always construct and add Allen Institute mouse brain to list G_brain = brain_graph.binary_undirected()[0] graph_list.append(G_brain) # Calculate degree & clustering coefficient distribution n_nodes = G_brain.order() brain_degree = nx.degree(G_brain).values() brain_degree_mean = np.mean(brain_degree) # Construct degree controlled random if 'Random' in graphs_to_const: G_RAND = und_graphs.random_simple_deg_seq(sequence=brain_degree, brain_size=BRAIN_SIZE, tries=1000)[0] graph_list.append(G_RAND) # Construct small-world graph if 'Small-world' in graphs_to_const: graph_list.append( nx.watts_strogatz_graph(n_nodes, int(round(brain_degree_mean)), SW_REWIRE_PROB)) # Construct scale-free graph if 'Scale-free' in graphs_to_const: graph_list.append( nx.barabasi_albert_graph(n_nodes, int(round(brain_degree_mean / 2.)))) # Construct SGPA graph if 'SGPA' in graphs_to_const: G_SGPA = source_growth(bc.num_brain_nodes, bc.num_brain_edges_directed, L=LENGTH_SCALE)[0] graph_list.append(G_SGPA.to_undirected()) # Construct degree-controlled SGPA graph if 'SGPA-random' in graphs_to_const: SGPA_degree = nx.degree(G_SGPA).values() G_SGPA_RAND = und_graphs.random_simple_deg_seq( sequence=SGPA_degree, brain_size=BRAIN_SIZE, tries=1000)[0] graph_list.append(G_SGPA_RAND) # Error check that we created correct number of graphs if len(graph_list) != len(graphs_to_const): raise RuntimeError('Graph list/names don\'t match') return graph_list
def construct_graph_list_und(graphs_to_const): """Construct and return a list of graphs so graph construction is easily repeatable. Can handle: Random, Small-world, Scale-free, SGPA, SGPA-random""" graph_list = [] # Always construct and add Allen Institute mouse brain to list G_brain = brain_graph.binary_undirected()[0] graph_list.append(G_brain) # Calculate degree & clustering coefficient distribution n_nodes = G_brain.order() brain_degree = nx.degree(G_brain).values() brain_degree_mean = np.mean(brain_degree) # Construct degree controlled random if 'Random' in graphs_to_const: G_RAND = und_graphs.random_simple_deg_seq( sequence=brain_degree, brain_size=BRAIN_SIZE, tries=1000)[0] graph_list.append(G_RAND) # Construct small-world graph if 'Small-world' in graphs_to_const: graph_list.append(nx.watts_strogatz_graph( n_nodes, int(round(brain_degree_mean)), SW_REWIRE_PROB)) # Construct scale-free graph if 'Scale-free' in graphs_to_const: graph_list.append(nx.barabasi_albert_graph( n_nodes, int(round(brain_degree_mean / 2.)))) # Construct SGPA graph if 'SGPA' in graphs_to_const: G_SGPA = source_growth(bc.num_brain_nodes, bc.num_brain_edges_directed, L=LENGTH_SCALE)[0] graph_list.append(G_SGPA.to_undirected()) # Construct degree-controlled SGPA graph if 'SGPA-random' in graphs_to_const: SGPA_degree = nx.degree(G_SGPA).values() G_SGPA_RAND = und_graphs.random_simple_deg_seq( sequence=SGPA_degree, brain_size=BRAIN_SIZE, tries=1000)[0] graph_list.append(G_SGPA_RAND) # Error check that we created correct number of graphs if len(graph_list) != len(graphs_to_const): raise RuntimeError('Graph list/names don\'t match') return graph_list
def construct_graph_list_und(graphs_to_const): """Construct and return a list of graphs so graph construction is easily repeatable""" graph_check = ['Random', 'Small-world', 'Scale-free', 'SGPA'] graph_list = [] # Always construct and add Allen Institute mouse brain to list G_brain, _, _ = brain_graph.binary_undirected() graph_list.append(G_brain) # Calculate degree & clustering coefficient distribution n_nodes = G_brain.order() brain_degree = nx.degree(G_brain).values() brain_degree_mean = np.mean(brain_degree) # Construct degree controlled random if graph_check[0] in graphs_to_const: G_RAND, _, _ = und_graphs.random_simple_deg_seq( sequence=brain_degree, brain_size=brain_size, tries=100) graph_list.append(G_RAND) # Construct small-world graph if graph_check[1] in graphs_to_const: graph_list.append(nx.watts_strogatz_graph( n_nodes, int(round(brain_degree_mean)), 0.159)) # Construct scale-free graph if graph_check[2] in graphs_to_const: graph_list.append(nx.barabasi_albert_graph( n_nodes, int(round(brain_degree_mean / 2.)))) # Construct SGPA graph if graph_check[3] in graphs_to_const: G_SGPA, _, _ = pgpa_dir(bc.num_brain_nodes, bc.num_brain_edges_directed, L=LENGTH_SCALE) graph_list.append(G_SGPA.to_undirected()) # Error check that we created correct number of graphs assert len(graph_list) == len(graphs_to_const), ( 'Graph list/names don\'t match') return graph_list
for met_i, bm in enumerate(metrics): met_arr[graph_names.index('Connectome'), :, met_i] = bm(G_brain) print 'Running metric table with %d repeats\n' % repeats for rep in np.arange(repeats): # PGPA model if 'PGPA' in graph_names: G_PGPA, _, _ = pgpa_dir(bc.num_brain_nodes, L=LENGTH_SCALE) met_arr[graph_names.index('PGPA'), rep, :] = \ calc_metrics(G_PGPA.to_undirected(), metrics) # Random Configuration model (random with fixed degree sequence) if 'Random' in graph_names: G_CM, _, _ = binary_undirected.random_simple_deg_seq(sequence=brain_degree, brain_size=brain_size, tries=100) met_arr[graph_names.index('Random'), rep, :] = \ calc_metrics(G_CM, metrics) # Small-world (Watts-Strogatz) model with standard reconnection prob if 'Small-world' in graph_names: G_SW = nx.watts_strogatz_graph(n_nodes, int(round(brain_degree_mean)), 0.159) met_arr[graph_names.index('Small-world'), rep, :] = \ calc_metrics(G_SW, metrics) # Scale-free (Barabasi-Albert) graph if 'Scale-free' in graph_names: G_SF = nx.barabasi_albert_graph(n_nodes, int(round(brain_degree_mean / 2.)))
# Calculate metrics specially because no repeats can be done on brain brain_metrics = calc_metrics(G_brain, metrics) for met_i, bm in enumerate(metrics): met_arr[graph_names.index('Connectome'), :, met_i] = bm(G_brain) print 'Running metric table with %d repeats\n' % repeats for rep in np.arange(repeats): # SGPA model if 'SGPA' in graph_names: G_SGPA = source_growth(bc.num_brain_nodes, L=LENGTH_SCALE)[0] met_arr[graph_names.index('SGPA'), rep, :] = \ calc_metrics(G_SGPA.to_undirected(), metrics) # Random Configuration model (random with fixed degree sequence) if 'Random' in graph_names: G_CM = binary_undirected.random_simple_deg_seq( sequence=brain_degree, brain_size=BRAIN_SIZE, tries=100)[0] met_arr[graph_names.index('Random'), rep, :] = \ calc_metrics(G_CM, metrics) # Small-world (Watts-Strogatz) model with standard reconnection prob if 'Small-world' in graph_names: G_SW = nx.watts_strogatz_graph(n_nodes, int(round(brain_degree_mean)), SW_REWIRE_PROB) met_arr[graph_names.index('Small-world'), rep, :] = \ calc_metrics(G_SW, metrics) # Scale-free (Barabasi-Albert) graph if 'Scale-free' in graph_names: G_SF = nx.barabasi_albert_graph(n_nodes, int(round(brain_degree_mean / 2.))) met_arr[graph_names.index('Scale-free'), rep, :] = \