if m == 0: return graph #For each node u, we add a node to k randomly chosen nodes weak_ties = random.choice(k) while weak_ties > 0: xt = random.randint(0, line-1) yt = random.randint(0, line-1) if xt*line+yt > n-1: continue if xt != i and yt != j and xt*line+yt not in graph[i*line+j] and random.random() <= (1/(euclidean_distance((xt, yt), (i,j))**q)): graph[i*line+j].add(xt*line+yt) m -= 1 weak_ties -= 1 if m == 0: return graph return graph if __name__ == '__main__': EXECUTIONS = 3 NODES = 7056 # edges = random.randint(75000, 125000) edges = [75000, 100000, 125000] radius = 2 weak_ties = [i*5 for i in xrange(0, 3)] seed = 100 for i in xrange(EXECUTIONS): g = GenWSGridGraph(NODES, edges[i], radius, weak_ties) print 'Edges %d\tAverage Clustering = %f' % (countEdges(g),ac(und(g)))
for i in xrange(100): NODES = 7115 edges = random.randint(75000, 125000) radius = 2 weak_ties = [i * 5 for i in xrange(0, 4)] seed = 100 # ##Create a Watts-Strogatz 2D direct graph # In[4]: g = standardize(WS2D(NODES, edges, radius, weak_ties)) print '# Edges %d\tAverage Clustering = %f' % (countEdges(g) * 2, ac( und(g))) fi(g) # Fill incoming edges sys.stdout.flush() # ## Execute centrality measures # In[5]: print '# Page Rank execution...' pagerank, iterations, err = pr(g, alpha=1.0e-5, eps=1.0e-3) print '#', iterations, ' iterations. Error:', err top_pr = [a for a, b in topk(pagerank, seed)] # In[6]:
#For each node u, we add a node to k randomly chosen nodes weak_ties = random.choice(k) while weak_ties > 0: xt = random.randint(0, line - 1) yt = random.randint(0, line - 1) if xt * line + yt > n - 1: continue if xt != i and yt != j and xt * line + yt not in graph[ i * line + j] and random.random() <= (1 / (euclidean_distance( (xt, yt), (i, j))**q)): graph[i * line + j].add(xt * line + yt) m -= 1 weak_ties -= 1 if m == 0: return graph return graph if __name__ == '__main__': EXECUTIONS = 3 NODES = 7056 # edges = random.randint(75000, 125000) edges = [75000, 100000, 125000] radius = 2 weak_ties = [i * 5 for i in xrange(0, 3)] seed = 100 for i in xrange(EXECUTIONS): g = GenWSGridGraph(NODES, edges[i], radius, weak_ties) print 'Edges %d\tAverage Clustering = %f' % (countEdges(g), ac(und(g)))
return len(adopters) # ## Set Parameters # In[3]: seed = 100 # ##Read the wiki-vote graph # In[4]: g = readGraph('wiki-Vote.txt') print '# Wiki-Vote.txt' print '# Edges = %d\tAverage Clustering = %f' % (countEdges(g) * 2, ac(und(g))) fi(g) # Fill incoming edges dictionary sys.stdout.flush() # ## Execute centrality measures # In[8]: print '# Page Rank execution...' pagerank, iterations, err = pr(g, alpha=1.0e-5, eps=1.0e-3) print '#', iterations, ' iterations. Error:', err top_pr = [a for a, b in topk(pagerank, seed)] # In[9]:
# ## Set Parameters # In[3]: seed = 100 # ##Read the wiki-vote graph # In[4]: g = readGraph('wiki-Vote.txt') print '# Wiki-Vote.txt' print '# Edges = %d\tAverage Clustering = %f'% (countEdges(g)*2, ac(und(g))) fi(g) # Fill incoming edges dictionary sys.stdout.flush() # ## Execute centrality measures # In[8]: print '# Page Rank execution...' pagerank, iterations, err = pr(g, alpha=1.0e-5, eps=1.0e-3) print '#',iterations, ' iterations. Error:', err top_pr = [a for a,b in topk(pagerank, seed)] # In[9]: