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


Python networkx.katz_centrality函数代码示例

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


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

示例1: test_K5

 def test_K5(self):
     """Katz centrality: K5"""
     G = nx.complete_graph(5)
     alpha = 0.1
     b = nx.katz_centrality(G, alpha)
     v = math.sqrt(1 / 5.0)
     b_answer = dict.fromkeys(G, v)
     for n in sorted(G):
         assert_almost_equal(b[n], b_answer[n])
     nstart = dict([(n, 1) for n in G])
     b = nx.katz_centrality(G, alpha, nstart=nstart)
     for n in sorted(G):
         assert_almost_equal(b[n], b_answer[n])
开发者ID:4c656554,项目名称:networkx,代码行数:13,代码来源:test_katz_centrality.py

示例2: most_central

 def most_central(self,F=1,cent_type='betweenness'):
     if cent_type == 'betweenness':
         ranking = nx.betweenness_centrality(self.G).items()
     elif cent_type == 'closeness':
         ranking = nx.closeness_centrality(self.G).items()
     elif cent_type == 'eigenvector':
         ranking = nx.eigenvector_centrality(self.G).items()
     elif cent_type == 'harmonic':
         ranking = nx.harmonic_centrality(self.G).items()
     elif cent_type == 'katz':
         ranking = nx.katz_centrality(self.G).items()
     elif cent_type == 'load':
         ranking = nx.load_centrality(self.G).items()
     elif cent_type == 'degree':
         ranking = nx.degree_centrality(self.G).items()
     ranks = [r for n,r in ranking]
     cent_dict = dict([(self.lab[n],r) for n,r in ranking])
     m_centrality = sum(ranks)
     if len(ranks) > 0:
         m_centrality = m_centrality/len(ranks)
     #Create a graph with the nodes above the cutoff centrality- remove the low centrality nodes
     thresh = F*m_centrality
     lab = {}
     for k in self.lab:
         lab[k] = self.lab[k]
     g = Graph(self.adj.copy(),self.char_list)
     for n,r in ranking:
         if r < thresh:
             g.G.remove_node(n)
             del g.lab[n]
     return (cent_dict,thresh,g)
开发者ID:PCJohn,项目名称:Script-Analyzer,代码行数:31,代码来源:graph.py

示例3: relevant_stats

def relevant_stats(G):
	cloC = nx.closeness_centrality(G, distance = 'distance')
	betC = nx.betweenness_centrality(G, weight = 'distance')
	katC = nx.katz_centrality(G)
	eigC = nx.eigenvector_centrality(G)

	return
开发者ID:mhong19414,项目名称:anelka,代码行数:7,代码来源:passes_nx.py

示例4: centrality_calculation_by_networkx

def centrality_calculation_by_networkx(G):
    '''
    使用 networkx 计算 Centrality
    '''

    d_c = nx.degree_centrality(G)

    k_z = nx.katz_centrality(
        G=G,
        alpha=0.3,
        beta=0.3,
        max_iter=1000,
        tol=1.0e-6,
        nstart=None,
        normalized=True)

    # 归一化,每个元素除以集合中最大元素
    max_item = max([d_c[item] for item in d_c])
    degree_centrality = [round(d_c[item] / max_item, 4) for item in d_c]

    max_item = max([k_z[item] for item in k_z])
    katz_centrality = [round(k_z[item] / max_item, 4) for item in k_z]

    nx_list = [{'Degree': degree_centrality}, {'Katz': katz_centrality}]

    return nx_list
开发者ID:liyp0095,项目名称:project,代码行数:26,代码来源:Calculation.py

示例5: nextBestNode

    def nextBestNode(self, state): #Finds the next best spot for a station
        graph = state.get_graph()
        nodeScores = []
        centrality = nx.katz_centrality(graph)
        for i in centrality:
            nodeScores.append(centrality[i])

        bestNode = 0
        bestScore = nodeScores[0]
        for i in range(len(nodeScores)):
            if (nodeScores[i] > bestScore and (i not in self.stations)):
                bestNode = i
                bestScore = nodeScores[i]
        #print("bestNode=",(bestScore,bestNode))

        #Factor in distance from each station
        for i in range(len(nodeScores)):
            if (i not in self.stations):
                distanceScore = 1.0 / self.closestStation(graph, i)[1]
                #print("distanceScore=",distanceScore)
                nodeScores[i] -= distanceScore * self.distanceWeight

        #Get the node with the best score
        bestNode = 0
        bestScore = nodeScores[0]
        for i in range(len(nodeScores)):
            if (nodeScores[i] > bestScore and (i not in self.stations)):
                bestNode = i
                bestScore = nodeScores[i]
        #print("bestNode=",(bestScore,bestNode))
        return bestNode
开发者ID:remzr7,项目名称:Pawa,代码行数:31,代码来源:player.py

示例6: centralities

 def centralities(self):
     '''
     Get info on centralities of data
     Params:
         None
     Returns:
         dictionary of centrality metrics with keys(centralities supported):
             degree - degree centrality
             betweeness - betweeness centrality
             eigenvector - eigenvector centrality
             hub - hub scores - not implemented
             authority - authority scores - not implemented
             katz - katz centrality with params X Y
             pagerank - pagerank centrality with params X Y
     '''
     output = {}
     output['degree'] = nx.degree_centrality(self.G)
     output['betweeness'] = nx.betweenness_centrality(self.G)
     try:
         output['eigenvector'] = nx.eigenvector_centrality(self.G)
         output['katz'] = nx.katz_centrality(self.G)
     except:
         output['eigenvector'] = 'empty or exception'
         output['katz'] = 'empty or exception'
     # output['hub'] = 'Not implemented'
     # output['authority'] = 'Not implemented'
     # output['pagerank'] = 'Not implemented'
     return output
开发者ID:harrisonhunter,项目名称:groupcest,代码行数:28,代码来源:data_object.py

示例7: run

	def run(self,steps):
		for _ in xrange(steps):
			self.update()

		self.prs =nx.pagerank(self.G)			
		self.close = nx.closeness_centrality(self.G)
		self.bet = nx.betweenness_centrality(self.G)
		self.katz = nx.katz_centrality(self.G)
开发者ID:iSTB,项目名称:Python-neurons,代码行数:8,代码来源:ANN.py

示例8: test_P3

 def test_P3(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(G, alpha)
     for n in sorted(G):
         assert_almost_equal(b[n], b_answer[n], places=4)
开发者ID:4c656554,项目名称:networkx,代码行数:9,代码来源:test_katz_centrality.py

示例9: comparisons

def comparisons(G):
    evec = nx.eigenvector_centrality(G)
    print "EVEC:",evec

    pagerank = nx.pagerank(G)
    print "PAGERANK: ", pagerank

    katz = nx.katz_centrality(G)
    print "KATZ: ", katz
开发者ID:abhisheknkar,项目名称:AcademicSearchEngine,代码行数:9,代码来源:FairShare.py

示例10: test_maxiter

 def test_maxiter(self):
     alpha = 0.1
     G = nx.path_graph(3)
     max_iter = 0
     try:
         b = nx.katz_centrality(G, alpha, max_iter=max_iter)
     except nx.NetworkXError as e:
         assert str(max_iter) in e.args[0], "max_iter value not in error msg"
         raise # So that the decorater sees the exception.
开发者ID:4c656554,项目名称:networkx,代码行数:9,代码来源:test_katz_centrality.py

示例11: 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(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

示例12: katz

def katz(g):
    eigv = eig(nx.adjacency_matrix(g, weight='diff').todense())
    max_eigv = max(eigv[0])
    max_eigv_reciprocal = 1./max_eigv
    alpha = max_eigv_reciprocal
    alpha = 0.9 * alpha
    beta = 1 - alpha
    katz_centrality = nx.katz_centrality(g, alpha=alpha, beta=beta,
                                         weight='diff')
    return katz_centrality
开发者ID:colwem,项目名称:nfl-graph-theory,代码行数:10,代码来源:nflgraph.py

示例13: centralityMeasures

def centralityMeasures(G):
	# Betweenness
	# betw = nx.betweenness_centrality(G, normalized=True, weight='weight')
	# print sorted([(k,v) for k,v in betw.iteritems()], key= lambda x:(-x[1],x[0]))

	# clsn = nx.closeness_centrality(G, normalized=True)
	# print sorted([(k,v) for k,v in clsn.iteritems()], key= lambda x:(-x[1],x[0]))

	# evec = nx.eigenvector_centrality(G, weight='weight')
	# print sorted([(k,v) for k,v in evec.iteritems()], key= lambda x:(-x[1],x[0]))

	katz = nx.katz_centrality(G, normalized=True, weight='weight', alpha=0.005)
	print sorted([(k,v) for k,v in katz.iteritems()], key= lambda x:(-x[1],x[0]))
开发者ID:svnathan,项目名称:224w_window,代码行数:13,代码来源:analyze.py

示例14: test_K5_unweighted

 def test_K5_unweighted(self):
     """Katz centrality: K5"""
     G = nx.complete_graph(5)
     alpha = 0.1
     b = nx.katz_centrality(G, alpha, weight=None)
     v = math.sqrt(1 / 5.0)
     b_answer = dict.fromkeys(G, v)
     for n in sorted(G):
         assert_almost_equal(b[n], b_answer[n])
     nstart = dict([(n, 1) for n in G])
     b = nx.eigenvector_centrality_numpy(G)
     for n in sorted(G):
         assert_almost_equal(b[n], b_answer[n], places=3)
开发者ID:4c656554,项目名称:networkx,代码行数:13,代码来源:test_katz_centrality.py

示例15: 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(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


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