예제 #1
0
 def compute_local_community(self, g):
     r = []
     for i in xrange(3):
         r.append(minimize(lambda x: -1*(gt.modularity(g, gt.community_structure(g, 100, x)))
         , 0, method='COBYLA', options={'disp': True}).x)
     print "Optimal global Modularity: ", np.mean(r)
     b = gt.community_structure(g, 100, np.mean(r))
     return b
예제 #2
0
 def compute_global_community(self):
     r = []
     for i in xrange(3):
         r.append(minimize(self.optimize_global_modularity, 0, method='COBYLA', options={'disp': False}).x)
     print "Optimal global group number: ", np.mean(r)
     b = gt.community_structure(self.g, 100, np.mean(r))
     return b
def community():
	g = gt.load_graph(filename)
	print 'Graph loaded, now finding community'
	# state = gt.BlockState(g, B=blocks)
	# for i in xrange(iterations):
	# 	if i < iterations / 2:
	# 		gt.mcmc_sweep(state)
	# 	else:
	# 		gt.mcmc_sweep(state, beta=float('inf'))

	# g.vp['blocks'] = state.get_blocks()

	spins = {}
	if 'blocks' in g.vp:
		spins = {'spins': g.vp['blocks']}

	g.vp['blocks'] = gt.community_structure(g, n_iter=iterations, n_spins=blocks, **spins)

	if 'pos' in g.vp:
		gt.sfdp_layout(g, groups=g.vp['blocks'], pos=g.vp['pos'])

	for i in xrange(blocks):
		print '%d nodes in block %d' % (len(gt.find_vertex(g, g.vp['blocks'], i)), i)

	g.save(filename)
예제 #4
0
 def optimize_global_modularity(self, x):
     b = gt.community_structure(self.g, 100, x)
     return -1*(gt.modularity(self.g, b))
예제 #5
0
        if f_g.edge(s_i,t_i) is not None:
            e = f_g.edge(s_i, t_i)
            e_w[e] +=1
        else:
            e = f_g.add_edge(s_i, t_i)
            e_w[e] = 0
f_g.edge_properties['cofield'] = e_w

# <codecell>

print f_g.num_edges()
f_g.num_vertices()

# <codecell>

v_comm = gt.community_structure(f_g, 1000, 5)
#v_comm = gt.betweenness(f_g)

# <codecell>

import numpy
u = gt.GraphView(f_g, vfilt=gt.label_largest_component(f_g))
deg = u.degree_property_map('total', weight = f_g.edge_properties['cofield'])
deg.fa = 2*(numpy.sqrt(deg.fa)*0.5  + 0.4)
edg = f_g.edge_properties['cofield']
edg.fa = (numpy.sqrt(edg.fa)*0.6+1)
ebet = gt.betweenness(f_g)[1]

# <codecell>