当前位置: 首页>>代码示例>>Python>>正文


Python Graph.community_label_propagation方法代码示例

本文整理汇总了Python中igraph.Graph.community_label_propagation方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.community_label_propagation方法的具体用法?Python Graph.community_label_propagation怎么用?Python Graph.community_label_propagation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在igraph.Graph的用法示例。


在下文中一共展示了Graph.community_label_propagation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: len

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import community_label_propagation [as 别名]
time_cost = []
perm = []
modu = []
community_number = []
max_community_size = []
average_community_size = []
for filename in os.listdir(direct): 
    if os.path.isfile(direct + "/"+filename):
        print "Processing:"+direct + "/"+filename+"\n"
        start = datetime.datetime.now()
        g = Graph.Read_Edgelist(direct + "/"+filename, directed=False)
        "community = Graph.community_spinglass(g)"
        "dendrogram = Graph.community_fastgreedy(g)"
        "community = dendrogram.as_clustering()"
        "community = Graph.community_infomap(g)"
        community = Graph.community_label_propagation(g)
        "community = Graph.community_multilevel(g)"
        end = datetime.datetime.now()
        t = end - start
        time_cost.append(t.seconds)
        "TODO:perm"
        perm.append(permanence_igraph.permanence_igraph(g,community))
        modu.append(g.modularity(community))
        community_number.append(len(community))
        max_community = 0
        average_community = 0
        for i in xrange(len(community)):
            if len(community[i]) > max_community:
                max_community = len(community[i])
            average_community += len(community[i])
        average_community = average_community/float(len(community))
开发者ID:Jafree,项目名称:Permanence-Dynamic-Game,代码行数:33,代码来源:igraph_infomap.py

示例2: SampleGenerator

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import community_label_propagation [as 别名]

#.........这里部分代码省略.........

		tot_p = len(self.prodgr.vs)
		edges, arc_a = infer_arcs(self.comm, tot_p, ratio=2*log(1+tot_p)) # TWEAK # relax for tgraphs
		self.sprdgr = Graph(tot_s, list(edges), directed=True,
		  vertex_attrs={NID:list("%04d" % i for i in xrange(0, tot_s)), "label":[len(com) for com in self.comm]})
		g = self.sprdgr
		LOG.info("%s db: generated producer graph" % name)

		# generate content arcs between producers
		def run_r(nsid):
			prod = self.pgdb[nsid]
			if prod.state != P_ARC:
				rprod = g.vs.select(g.successors(id_p[nsid]))[NID]
				pmap = dict((rnsid, ProducerRelation(None,
				  *self.inferProdArc(prod, self.pgdb[rnsid], show_tag=True))) for rnsid in rprod)
				prod.initProdArcs(pmap, has_tags=True)
				self.pgdb[nsid] = prod
			self.pgsb[nsid] = prod.state
		exec_unique(self.pgdb.iterkeys(), lambda nsid: self.pgsb[nsid] >= P_ARC, run_r, None,
		  "%s db: relations" % name, LOG.info, steps=0x10000)


	def generateCommunities(self):
		"""
		Generates a bunch of communities using various community detection
		algorithms on the underlying producer graph, and selects the non-tiny
		ones.
		"""
		comm = set()

		# aggregate communities using "label propagation" algorithm.
		# without aggregation, multiple runs will generate a lot of similar
		# (ie. redundant) communities with size in the midrange
		labels = zip(*(self.prodgr.community_label_propagation().membership for i in xrange(0, 4)))
		ddd = dict((o, i) for i, o in enumerate(set(labels)))
		mem = self.prodgr.community_label_propagation(initial=[ddd[o] for o in labels],
		  fixed=[False]*self.prodgr.vcount()).membership # fixed=[False]*V workaround igraph bug #570902
		comm.update(frozenset(community) for community in invert_seq(mem).itervalues())
		# TODO repeat this several times?

		# select communities from dendrograms generated by a bunch of algorithms
		dgrams = [
		  undirect_and_simplify(self.prodgr).community_fastgreedy(),
		  #self.prodgr.community_edge_betweenness(directed=True), # this has atrocious performance
		]
		gg = undirect_and_simplify(self.prodgr)
		gg.delete_vertices(gg.vs.select(_degree=0)) # walktrap impl can't handle islands
		dgrams.append(gg.community_walktrap())

		def int_unique(flseq):
			"""
			Turns a sorted list of floats into a sorted list of unique ints
			"""
			it = iter(flseq)
			o = round(it.next())
			yield int(o)

			while True:
				i = round(it.next())
				if i != o:
					yield int(i)
				o = i

		from igraph.core import InternalError
		from igraph.statistics import power_law_fit
		ratio = power_law_fit([prod.size() for prod in self.phdb.itervalues()], 6)
开发者ID:infinity0,项目名称:tag-routing,代码行数:70,代码来源:sample.py


注:本文中的igraph.Graph.community_label_propagation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。