args = sys.argv[1:] if len(args) != 3: print "Usage: er.py n_nodes p prop_steps" sys.exit(1) n_nodes = int(args[0]) p = float(args[1]) prop_steps = float(args[2]) steps = int(n_nodes * prop_steps) results_path = "results/er_%s_%s_%s_%s" % (n_nodes, p, prop_steps, time.time()) if not os.path.exists(results_path): os.makedirs(results_path) try: digraph = nx.fast_gnp_random_graph(n_nodes, p, directed = True) nx.write_edgelist(digraph, "%s/er.csv" % (results_path,), delimiter = ",") jointrw.main(digraph, #graph steps, #number of steps also_recip=True, plot_path=results_path, title=("\nn=%s, p=%s" % (n_nodes, p) + ", runs=%s, walkers=%s, steps=%s" % (1, 1, steps))) plt.show() except IndexError: import shutil print "died because graph not reciprocally connected!" shutil.rmtree(results_path)
print "Usage: er.py n_nodes p prop_steps" sys.exit(1) n_nodes = int(args[0]) p = float(args[1]) prop_steps = float(args[2]) steps = int(n_nodes * prop_steps) results_path = "results/er_%s_%s_%s_%s" % (n_nodes, p, prop_steps, time.time()) if not os.path.exists(results_path): os.makedirs(results_path) try: digraph = nx.fast_gnp_random_graph(n_nodes, p, directed=True) nx.write_edgelist(digraph, "%s/er.csv" % (results_path, ), delimiter=",") jointrw.main( digraph, #graph steps, #number of steps also_recip=True, plot_path=results_path, title=("\nn=%s, p=%s" % (n_nodes, p) + ", runs=%s, walkers=%s, steps=%s" % (1, 1, steps))) plt.show() except IndexError: import shutil print "died because graph not reciprocally connected!" shutil.rmtree(results_path)
try: netpath = generate_krapivsky_networks(results_path, n_nodes=n_nodes, p=p, lamb=l, mu=m, r=r, fname_base='krapiv') f = open(netpath, 'r') digraph = nx.DiGraph() nx.parse_edgelist(f, comments="#", delimiter=",", nodetype=int, create_using=digraph) f.close() jointrw.main( digraph, steps, also_recip=True, plot_path=results_path, title=("\nn=%s, p=%s, l=%s, m=%s, r=%s" % (n_nodes, p, l, m, r) + ", runs=%s, walkers=%s, steps=%s" % (1, 1, steps))) plt.show() except IndexError: import shutil print "died because graph not reciprocally connected!" shutil.rmtree(results_path)
#!/usr/bin/env python import os, os.path import gzip import networkx as nx import urllib import jointrw data_path = 'data/wiki-Talk.txt.gz' if __name__ == '__main__': if not os.path.exists(data_path): print "pulling data..." d = os.path.dirname(data_path) if not os.path.exists(d): os.makedirs(d) urllib.urlretrieve('http://snap.stanford.edu/data/wiki-Talk.txt.gz',data_path) print 'reading data...' f = gzip.open(data_path,'r') digraph = nx.DiGraph() nx.parse_edgelist(f, comments="#", delimiter="\t", nodetype = int, create_using=digraph) f.close() print 'random walk...' jointrw.main(digraph, digraph.order() // 100, also_recip=False)
netpath = generate_krapivsky_networks(results_path, n_nodes = n_nodes, p = p, lamb = l, mu = m, r = r, fname_base = 'krapiv') f = open(netpath,'r') digraph = nx.DiGraph() nx.parse_edgelist(f, comments="#", delimiter=",", nodetype = int, create_using=digraph) f.close() jointrw.main(digraph, steps, also_recip = True, plot_path=results_path, title= ("\nn=%s, p=%s, l=%s, m=%s, r=%s" % (n_nodes, p, l, m, r) + ", runs=%s, walkers=%s, steps=%s" % (1, 1, steps))) plt.show() except IndexError: import shutil print "died because graph not reciprocally connected!" shutil.rmtree(results_path)