import model import networkx if __name__ == '__main__': n = 5000 D = 1 space = .1 n_data_vertices = 11 times = 1 data_vertices = [] data = [0.0]*n_data_vertices for i in xrange(times): G = model.make_opinion_graph(n - n_data_vertices, 0, D) v = 0.0 for j in xrange(n_data_vertices): G.add_node((v,)) data_vertices.append((v,)) v += space model.construct(G, 6.5041*10**-8, 'c') for j in xrange(n_data_vertices): data[j] += G.degree(data_vertices[j]) / float(times) outstring = '' for i in xrange(n_data_vertices): outstring += '{0}\t{1}\n'.format(space * i, data[i])
k = 4 D = 1 times = 5*10**4 stats_size = 1 alpha = 2 outstring = 'N\tMean Pair-Wise Distance\n' print 'Working on ', print 'opPairwise_{0}k_{1}D_{2}alpha_{3}min_{4}max_{5}times_{6}size.dat'.format(k, D, alpha, n_min, n_max, times, stats_size) print 'N\tMean Pair-Wise Distance' for n in xrange(n_min, n_max + n_step, n_step): print "Starting n = %d" % n pairwise_total = 0 for j in xrange(stats_size): G = model.make_opinion_graph(n, .5 * n * k, D, alpha) for i in xrange(n*times): model.iterate(G) giant_component = nx.connected_component_subgraphs(G)[0] iter_pw_distance = 0 #diameter may not be diameter for vertex_one in giant_component.nodes(): for vertex_two in giant_component.nodes(): if vertex_one == vertex_two: break iter_pw_distance += nx.shortest_path_length( giant_component, vertex_one, vertex_two) buf = giant_component.number_of_nodes()
import model import networkx if __name__ == '__main__': n = 5000 D = 1 space = .1 n_data_vertices = 11 times = 1 data_vertices = [] data = [0.0] * n_data_vertices for i in xrange(times): G = model.make_opinion_graph(n - n_data_vertices, 0, D) v = 0.0 for j in xrange(n_data_vertices): G.add_node((v, )) data_vertices.append((v, )) v += space model.construct(G, 6.5041 * 10**-8, 'c') for j in xrange(n_data_vertices): data[j] += G.degree(data_vertices[j]) / float(times) outstring = '' for i in xrange(n_data_vertices): outstring += '{0}\t{1}\n'.format(space * i, data[i])
print "storing degree informations" obs_degrees = {} for x in G.nodes_iter(): if G.degree(x) in obs_degrees: obs_degrees[G.degree(x)] += 1 else: obs_degrees[G.degree(x)] = 1 outstring = "degree\tfrequency\n" for key in obs_degrees.iterkeys(): outstring += "%s\t%d\n" % (key, obs_degrees[key]) # save data print "saving data" outfile = open("observed_degree_{0}n_{1}k_{2}D.dat".format(n, d_mean, D), "w") outfile.write(outstring) outfile.close() if __name__ == "__main__": n = 2000 d_mean = 4.0 D = 1 times = 10 ** 6 alpha = 2 G = model.make_opinion_graph(n, 0.5 * d_mean * n, D, alpha) write_expected_deg(G, n, d_mean, D, times)
n_step = 100 n_max = 1200 k = 4 D = 1 times = 1*10**3 stats_size = 50 alpha = 2 outstring = 'N\tDiameter\n' print 'N\tDiameter' for n in xrange(n_min, n_max + n_step, n_step): print "Starting n = %d" % n diam_total = 0 for j in xrange(stats_size): G = model.make_opinion_graph(n, .5 * n * k, D, alpha) for i in xrange(n*times): model.iterate(G) subgraphs = nx.connected_component_subgraphs(G) max_diameter = 0 #diameter may not be diameter for SG in subgraphs: #of largest connected subgraph if SG.number_of_nodes() < 2: break diameter = nx.diameter(SG) if diameter > max_diameter: max_diameter = diameter diam_total += max_diameter
import model if __name__ == '__main__': n = 200 k_mean = 4 D = 1 times = 10**7 period = 10**5 G = model.make_opinion_graph(n, .5 * n * k_mean, D) outstring = '' for i in xrange(times): model.iterate(G) if i % period == 0: s = '{0}\t{1}\n'.format(i, model.mean_distance(G)) outstring += s if i % (10*period) == 0: print s outfile = open('mixing.dat', 'w') outfile.write(outstring)
import model if __name__ == '__main__': n = 200 k_mean = 4 D = 1 times = 10**7 period = 10**5 G = model.make_opinion_graph(n, .5 * n * k_mean, D) outstring = '' for i in xrange(times): model.iterate(G) if i % period == 0: s = '{0}\t{1}\n'.format(i, model.mean_distance(G)) outstring += s if i % (10 * period) == 0: print s outfile = open('mixing.dat', 'w') outfile.write(outstring)
else: G.remove_edges_from(G.edges()) model.add_random_edges(G, G.m) #There are two Methods to add edges: # 1. By using nx.gnm_random (Must iterate for graph to reach steady state) # 2. By using model.construct (Theorem 2 - construct a graph at the steady state) #This is a test of Theorem 2, so Method 1 is used if __name__ == '__main__': n = 50 d_mean = 2.0 D = 3 iterations = 10**4 times = 100 sample_rate = 100 throw_away = 10**3 iterations_for_getting_C = 100 #Method 1 G = model.make_opinion_graph(n, (d_mean * n) / 2, D) #Method 2 #G = model.make_graph(n, 0, D) #model.construct(G, d_mean) #required for expected calculation G.c = model.getC(G, iterations_for_getting_C) #G.c = 0.0001778 write_edge_existence(G, iterations, times, n, d_mean, D, sample_rate, throw_away)
model.add_random_edges(G, G.m) #There are two Methods to add edges: # 1. By using nx.gnm_random (Must iterate for graph to reach steady state) # 2. By using model.construct (Theorem 2 - construct a graph at the steady state) #This is a test of Theorem 2, so Method 1 is used if __name__ == '__main__': n = 50 d_mean = 2.0 D = 3 iterations = 10**4 times = 100 sample_rate = 100 throw_away = 10**3 iterations_for_getting_C = 100 #Method 1 G = model.make_opinion_graph(n, (d_mean * n) / 2, D) #Method 2 #G = model.make_graph(n, 0, D) #model.construct(G, d_mean) #required for expected calculation G.c = model.getC(G, iterations_for_getting_C) #G.c = 0.0001778 write_edge_existence(G, iterations, times, n, d_mean, D, sample_rate, throw_away)
print "storing degree informations" obs_degrees = {} for x in G.nodes_iter(): if G.degree(x) in obs_degrees: obs_degrees[G.degree(x)] += 1 else: obs_degrees[G.degree(x)] = 1 outstring = "degree\tfrequency\n" for key in obs_degrees.iterkeys(): outstring += "%s\t%d\n" % (key, obs_degrees[key]) #save data print "saving data" outfile = open('observed_degree_{0}n_{1}k_{2}D.dat'.format(n, d_mean, D), 'w') outfile.write(outstring) outfile.close() if __name__ == '__main__': n = 2000 d_mean = 4.0 D = 1 times = 10**6 alpha = 2 G = model.make_opinion_graph(n, 0.5 * d_mean * n, D, alpha) write_expected_deg(G, n, d_mean, D, times)