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


Python networkx.katz_centrality_numpy函数代码示例

本文整理汇总了Python中networkx.katz_centrality_numpy函数的典型用法代码示例。如果您正苦于以下问题:Python katz_centrality_numpy函数的具体用法?Python katz_centrality_numpy怎么用?Python katz_centrality_numpy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_eigenvector_centrality_weighted

 def test_eigenvector_centrality_weighted(self):
     G = self.G
     alpha = self.G.alpha
     p = networkx.katz_centrality_numpy(G, alpha)
     print p.values()
     for (a, b) in zip(list(p.values()), self.G.evc):
         assert_almost_equal(a, b)
开发者ID:jgmjgm,项目名称:networkx,代码行数:7,代码来源:test_katz_centrality.py

示例2: test_eigenvector_v_katz_random

 def test_eigenvector_v_katz_random(self):
     G = nx.gnp_random_graph(10,0.5, seed=1234)
     l = float(max(eigvals(nx.adjacency_matrix(G).todense())))
     e = nx.eigenvector_centrality_numpy(G)
     k = nx.katz_centrality_numpy(G, 1.0/l)
     for n in G:
         assert_almost_equal(e[n], k[n])
开发者ID:4c656554,项目名称:networkx,代码行数:7,代码来源:test_katz_centrality.py

示例3: create_centralities_list

def create_centralities_list(G,maxiter=2000,pphi=5,centList=[]):
    if len(centList)==0:
        centList=['degree_centrality','closeness_centrality','betweenness_centrality',
    'eigenvector_centrality','katz_centrality','page_rank']
    cenLen=len(centList)
    valus={}
    # plt.figure(figsize=figsi)
    for uu,centr in enumerate(centList):
        if centr=='degree_centrality':
            cent=nx.degree_centrality(G)
            sstt='Degree Centralities'
            ssttt='degree centrality'
            valus[centr]=cent
        elif centr=='closeness_centrality':
            cent=nx.closeness_centrality(G)
            sstt='Closeness Centralities'
            ssttt='closeness centrality'
            valus[centr]=cent

        elif centr=='betweenness_centrality':
            cent=nx.betweenness_centrality(G)
            sstt='Betweenness Centralities'
            ssttt='betweenness centrality'
            valus[centr]=cent

        elif centr=='eigenvector_centrality':
            try:
                cent=nx.eigenvector_centrality(G,max_iter=maxiter)
                sstt='Eigenvector Centralities'
                ssttt='eigenvector centrality'
                valus[centr]=cent

            except:
                valus[centr]=None

                continue
        elif centr=='katz_centrality':
            phi = (1+math.sqrt(pphi))/2.0 # largest eigenvalue of adj matrix
            cent=nx.katz_centrality_numpy(G,1/phi-0.01)
            sstt='Katz Centralities'
            ssttt='Katz centrality'
            valus[centr]=cent

        elif centr=='page_rank':
            try:
                cent=nx.pagerank(G)
                sstt='PageRank'
                ssttt='pagerank'
                valus[centr]=cent

            except:
                valus[centr]=None

                continue
        print '%s done!!!' %sstt

    return valus
开发者ID:TwsThomas,项目名称:TwitterMining,代码行数:57,代码来源:utils.py

示例4: test_beta_as_dict

 def test_beta_as_dict(self):
     alpha = 0.1
     beta = {0: 1.0, 1: 1.0, 2: 1.0}
     b_answer = {0: 0.5598852584152165, 1: 0.6107839182711449,
                 2: 0.5598852584152162}
     G = nx.path_graph(3)
     b = nx.katz_centrality_numpy(G, alpha, beta)
     for n in sorted(G):
         assert_almost_equal(b[n], b_answer[n], places=4)
开发者ID:4c656554,项目名称:networkx,代码行数:9,代码来源:test_katz_centrality.py

示例5: test_P3_unweighted

 def test_P3_unweighted(self):
     """Katz centrality: P3"""
     alpha = 0.1
     G = nx.path_graph(3)
     b_answer = {0: 0.5598852584152165, 1: 0.6107839182711449,
                 2: 0.5598852584152162}
     b = nx.katz_centrality_numpy(G, alpha, weight=None)
     for n in sorted(G):
         assert_almost_equal(b[n], b_answer[n], places=4)
开发者ID:4c656554,项目名称:networkx,代码行数:9,代码来源:test_katz_centrality.py

示例6: draw_centralities

def draw_centralities(G,centr,pos,with_edgewidth=False,withLabels=True,pernode_dict={},title_st='', labfs=10,valpha=0.4,ealpha=0.4):

    plt.figure(figsize=(12,12))
    if centr=='degree_centrality':
        cent=nx.degree_centrality(G)
        sstt='Degree Centralities'
        ssttt='degree centrality'
    elif centr=='closeness_centrality':
        cent=nx.closeness_centrality(G)
        sstt='Closeness Centralities'
        ssttt='closeness centrality'
    elif centr=='betweenness_centrality':
        cent=nx.betweenness_centrality(G)
        sstt='Betweenness Centralities'
        ssttt='betweenness centrality'
    elif centr=='eigenvector_centrality':
        cent=nx.eigenvector_centrality(G,max_iter=1000)
        sstt='Eigenvector Centralities'
        ssttt='eigenvector centrality'
    elif centr=='katz_centrality':
        phi = (1+math.sqrt(5))/2.0 # largest eigenvalue of adj matrix
        cent=nx.katz_centrality_numpy(G,1/phi-0.01)
        sstt='Katz Centralities'
        ssttt='Katz centrality'
    elif centr=='page_rank':
        cent=nx.pagerank(G)
        sstt='PageRank'
        ssttt='pagerank'
    cs={}
    for k,v in cent.items():
        if v not in cs:
            cs[v]=[k]
        else:
            cs[v].append(k)
    for k in sorted(cs,reverse=True):
        for v in cs[k]:
            print 'Node %s has %s = %.4f' %(v,ssttt,k)

    if withLabels:
        if len(pernode_dict)>1:
            labels={i:v for v,i in pernode_dict.items() if i in G.nodes()}
            labe=nx.draw_networkx_labels(G,pos=pos,labels=labels,font_size=20)
        else:
            labe=nx.draw_networkx_labels(G,pos=pos,font_size=labfs)
    nx.draw_networkx_nodes(G,pos=pos,nodelist=cent.keys(), #with_labels=withLabels,
                           node_size = [d*4000 for d in cent.values()],node_color=cent.values(),
                           cmap=plt.cm.Reds,alpha=valpha)
    if with_edgewidth:
        edgewidth=[]
        for (u,v,d) in G.edges(data=True):
            edgewidth.append(d['weight'])
    else:
        edgewidth=[1 for i in G.edges()]
    nx.draw_networkx_edges(G,pos=pos,edge_color='b',width=edgewidth, alpha=ealpha)
    plt.title(title_st+' '+ sstt,fontsize=20)
    kk=plt.axis('off')
开发者ID:mboudour,项目名称:GraphMultilayerity,代码行数:56,代码来源:utils.py

示例7: centrailtyM

def centrailtyM(A,num=5):
    G=nx.DiGraph(A)
    ranks=np.zeros((num,8))
    ranks[:,0]=np.argsort(nx.in_degree_centrality(G).values())[::-1][:num]
    ranks[:,1]=np.argsort(nx.closeness_centrality(G).values())[::-1][:num]
    ranks[:,2]=np.argsort(nx.betweenness_centrality(G).values())[::-1][:num]
    ranks[:,3]=np.argsort(nx.eigenvector_centrality_numpy(G).values())[::-1][:num]
    ranks[:,4]=np.argsort(nx.katz_centrality_numpy(G,weight=None).values())[::-1][:num]
    ranks[:,5]=np.argsort(nx.pagerank_numpy(G,weight=None).values())[::-1][:num]
    return ranks
开发者ID:AZaitzeff,项目名称:Sparse,代码行数:10,代码来源:sparse.py

示例8: displayCentralities

def displayCentralities():
	print("---------------------------")
	print("Degree centrality (the number of links incident upon a node) => LIKELIHOOD TO CATCH AN INFORMATION")
	print(sorted(list(nx.degree_centrality(G).items()),key=operator.itemgetter(1),reverse=True))
	print("---------------------------")
	print("---------------------------")
	print("Betweenness centrality (quantifies the number of times a node acts as a bridge along the shortest path between two other nodes) => CONTROL ON OTHERS")
	print(sorted(list(nx.betweenness_centrality(G).items()),key=operator.itemgetter(1),reverse=True))
	print("---------------------------")
	print("---------------------------")
	print("Eigenvector centrality (a measure of the influence of a node in a network)")
	print(sorted(list(nx.eigenvector_centrality(G).items()),key=operator.itemgetter(1),reverse=True))
	print("---------------------------")
	print("---------------------------")
	print("Katz centrality (relative influence of a node)")
	print(sorted(list(nx.katz_centrality_numpy(G).items()),key=operator.itemgetter(1),reverse=True))
	print("---------------------------")
开发者ID:rodenas2u,项目名称:equipe_du_soir_relationships,代码行数:17,代码来源:main.py

示例9: test_multiple_alpha

 def test_multiple_alpha(self):
     alpha_list = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]
     for alpha in alpha_list:
         b_answer = {0.1: {0: 0.5598852584152165, 1: 0.6107839182711449,
                           2: 0.5598852584152162},
                     0.2: {0: 0.5454545454545454, 1: 0.6363636363636365,
                           2: 0.5454545454545454},
                     0.3: {0: 0.5333964609104419, 1: 0.6564879518897746,
                           2: 0.5333964609104419},
                     0.4: {0: 0.5232045649263551, 1: 0.6726915834767423,
                           2: 0.5232045649263551},
                     0.5: {0: 0.5144957746691622, 1: 0.6859943117075809,
                           2: 0.5144957746691622},
                     0.6: {0: 0.5069794004195823, 1: 0.6970966755769258,
                           2: 0.5069794004195823}}
         G = nx.path_graph(3)
         b = nx.katz_centrality_numpy(G, alpha)
         for n in sorted(G):
             assert_almost_equal(b[n], b_answer[alpha][n], places=4)
开发者ID:4c656554,项目名称:networkx,代码行数:19,代码来源:test_katz_centrality.py

示例10: test_empty_numpy

 def test_empty_numpy(self):
     e = networkx.katz_centrality_numpy(networkx.Graph(), 0.1)
开发者ID:jgmjgm,项目名称:networkx,代码行数:2,代码来源:test_katz_centrality.py

示例11: test_katz_centrality_unweighted

 def test_katz_centrality_unweighted(self):
     G = self.H
     alpha = self.H.alpha
     p = nx.katz_centrality_numpy(G, alpha)
     for (a, b) in zip(list(p.values()), self.G.evc):
         assert_almost_equal(a, b)
开发者ID:4c656554,项目名称:networkx,代码行数:6,代码来源:test_katz_centrality.py

示例12: calculate_katz

def calculate_katz(g):
    return nx.katz_centrality_numpy(g)
开发者ID:chendaniely,项目名称:spring_2016_cs_5854-PathLinker,代码行数:2,代码来源:calculate_node_attributes.py

示例13: test_bad_beta_numbe

 def test_bad_beta_numbe(self):
     G = nx.Graph([(0,1)])
     e = nx.katz_centrality_numpy(G, 0.1,beta='foo')
开发者ID:4c656554,项目名称:networkx,代码行数:3,代码来源:test_katz_centrality.py

示例14: test_bad_beta

 def test_bad_beta(self):
     G = nx.Graph([(0,1)])
     beta = {0:77}
     e = nx.katz_centrality_numpy(G, 0.1,beta=beta)
开发者ID:4c656554,项目名称:networkx,代码行数:4,代码来源:test_katz_centrality.py

示例15:

import matplotlib.pyplot as plt
import pygraphviz
import math

edges = pd.read_csv('fulllist.csv', encoding = 'utf-8')

#edges[(edges.name_x == 'Zadie Smith') | (edges.name_y == 'Zadie Smith')]
H = nx.DiGraph()
#phil = edges[(edges.phil_x == 1) & (edges.phil_y == 1)]
#phil = phil.dropna(subset = ['name_x', 'name_y'])
#H.add_edges_from(numpy.array(phil[['name_x', 'name_y']]))
edges = edges.dropna(subset = ['name_x', 'name_y'])
H.add_edges_from(numpy.array(edges[['name_x', 'name_y']]))

d = nx.degree(H)
k = nx.katz_centrality_numpy(H.reverse(), alpha = 0.075, beta = 1)
#b = nx.betweenness_centrality(H)
s = pd.Series(k, name = 'kc_score')
s.index.name = 'name'
s.reset_index()
s.sort('kc_score', ascending=False)
print (s[0:60])


#nx.ancestors(H, 'Plato')
#plt.figure(figsize = (50,50))
#try:
#pos=nx.graphviz_layout(H, prog='dot')
#except:
#        pos=nx.spring_layout(H,iterations=20)
#pos = nx.spring_layout(H,iterations=20)
开发者ID:alex-hh,项目名称:philosophynetwork,代码行数:31,代码来源:fullgraphprops.py


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