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


Python Graph.vs[count]['verticeID']方法代码示例

本文整理汇总了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)
#.........这里部分代码省略.........
开发者ID:blublud,项目名称:shdp,代码行数:103,代码来源:comment_cluster_red.py

示例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.
开发者ID:dslfaithdev,项目名称:Data-organizer,代码行数:32,代码来源:comments.py


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