本文整理汇总了Python中igraph.Graph.vs[count]['verticeID']方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.vs[count]['verticeID']方法的具体用法?Python Graph.vs[count]['verticeID']怎么用?Python Graph.vs[count]['verticeID']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类igraph.Graph
的用法示例。
在下文中一共展示了Graph.vs[count]['verticeID']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doClustering
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs[count]['verticeID'] [as 别名]
def doClustering(likes):
NodeList = []
for like in likes:
if like[0] not in NodeList:
NodeList.append(like[0])
if like[1] not in NodeList:
NodeList.append(like[1])
# print NodeList
gr = Graph(0)
gr.add_vertices(len(NodeList))
#Now, we finish adding nodes.
# print 'num of node: '
# print len(NodeList)
#-------------------------------------
count = 0
FromNodeIDtoVerticeID = {}
for vertice in NodeList:
FromNodeIDtoVerticeID[vertice] = count
# In gr.vs, each vertice has two characters.
gr.vs[count]['verticeID'] = count
gr.vs[count]['NodeID'] = str(vertice)
count += 1
# print 'map from NodeID to verticeID: '
# print FromNodeIDtoVerticeID
#Now we map long NodeID into VerticeID.
#-------------------------------------
count = 0
for line in FromNodeIDtoVerticeID:
count = count + 1
#print count
#-------------------------------------
for like in likes:
igraphEdgePair = (FromNodeIDtoVerticeID[like[0]],FromNodeIDtoVerticeID[like[1]])
gr.add_edges(igraphEdgePair)
#print summary(gr)
edgelist = gr.get_edgelist()
#Now we finish building edges.
length = len(NodeList)
# print 'nodelist: ' + str(length)
#Here we are dealing with special situations in final results.
if length == 0:
ClusterResultWithUserID = []
ClusterResultWithUserID.append('0')
return ClusterResultWithUserID
#print '-----------------'
#Now we are building adjacent matrix for later clustering.
b = np.arange(0,length*length,1)
for i in range(0,length*length):
b[i] = 0
#print b
b.shape = length,length
for i in range(0,len(edgelist)):
b[edgelist[i][0]][edgelist[i][1]] = b[edgelist[i][0]][edgelist[i][1]] + 1
b[edgelist[i][1]][edgelist[i][0]] = b[edgelist[i][1]][edgelist[i][0]] + 1
#Now we finished building adjacent matrix.
a = [sum(bi) for bi in b]
G = np.diag(a)
L = G - b
#---------------------------------------------------------------------------------------------------------------------------------
# for w in range(0,200):
# evals, Y, idx = cluster_points(L)
# membership = []
# for i in range(0,len(idx)):
# membership.append(str(idx[i]))
# membership[i] = int(membership[i])
#--------------------------------------------
checkmodularity = -100
savemembership = []
for w in range(0,200):
evals, Y, idx = cluster_points(L)
membership = []
for i in range(0,len(idx)):
membership.append(str(idx[i]))
membership[i] = int(membership[i])
if gr.modularity(membership) > checkmodularity:
checkmodularity = gr.modularity(membership)
#.........这里部分代码省略.........
示例2: Graph
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs[count]['verticeID'] [as 别名]
for line in rawlikedata:
NodeList[line['LikeFromID']] = 1
NodeList[line['LikeToID']] = 1
gr = Graph(0)
gr.add_vertices(len(NodeList))
#Now, we finish adding nodes.
#-------------------------------------
count = 0
FromNodeIDtoVerticeID = {}
for vertice, one in NodeList.iteritems():
FromNodeIDtoVerticeID[vertice] = count
# In gr.vs, each vertice has two characters.
gr.vs[count]['verticeID'] = count
gr.vs[count]['NodeID'] = str(vertice)
count += 1
#print 'map from NodeID to verticeID: '
#print FromNodeIDtoVerticeID
#Now we map long NodeID into VerticeID.
for rawlikedata_line in rawlikedata:
gr.add_edges((
FromNodeIDtoVerticeID[rawlikedata_line['LikeFromID']],
FromNodeIDtoVerticeID[rawlikedata_line['LikeToID']]))
#print summary(gr)
edgelist = gr.get_edgelist()
#Now we finish building edges.