本文整理汇总了Python中networkx.current_flow_betweenness_centrality函数的典型用法代码示例。如果您正苦于以下问题:Python current_flow_betweenness_centrality函数的具体用法?Python current_flow_betweenness_centrality怎么用?Python current_flow_betweenness_centrality使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了current_flow_betweenness_centrality函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_K4
def test_K4(self):
"""Betweenness centrality: K4"""
G=networkx.complete_graph(4)
b=networkx.current_flow_betweenness_centrality_subset(G,
list(G),
list(G),
normalized=True)
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
# test weighted network
G.add_edge(0,1,{'weight':0.5,'other':0.3})
b=networkx.current_flow_betweenness_centrality_subset(G,
list(G),
list(G),
normalized=True,
weight=None)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
b=networkx.current_flow_betweenness_centrality_subset(G,
list(G),
list(G),
normalized=True)
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
b=networkx.current_flow_betweenness_centrality_subset(G,
list(G),
list(G),
normalized=True,
weight='other')
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True,weight='other')
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
开发者ID:argriffing,项目名称:networkx,代码行数:34,代码来源:test_current_flow_betweenness_centrality_subset.py
示例2: test_P4_normalized
def test_P4_normalized(self):
"""Betweenness centrality: P4 normalized"""
G=networkx.path_graph(4)
b=networkx.current_flow_betweenness_centrality(G,normalized=True)
b_answer={0: 0, 1: 2./3, 2: 2./3, 3:0}
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
开发者ID:Bludge0n,项目名称:AREsoft,代码行数:7,代码来源:test_current_flow_betweenness_centrality.py
示例3: test_K4_normalized
def test_K4_normalized(self):
"""Betweenness centrality: K4"""
G = networkx.complete_graph(4)
b = networkx.current_flow_betweenness_centrality_subset(G, G.nodes(), G.nodes(), normalized=True)
b_answer = networkx.current_flow_betweenness_centrality(G, normalized=True)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n])
开发者ID:GccX11,项目名称:networkx,代码行数:7,代码来源:test_current_flow_betweenness_centrality_subset.py
示例4: compute_centrality
def compute_centrality(star_dict, edge_dict):
#build up a nx graph
galaxy = networkx.Graph()
for v, vertex in star_dict.iteritems():
galaxy.add_node(v)
for v, neighbors in edge_dict.iteritems():
for n in neighbors:
galaxy.add_edge(v,n)
print "betweenness"
betweenness_map = networkx.current_flow_betweenness_centrality(galaxy)
betweenness_map = normalize(betweenness_map)
for key, value in betweenness_map.iteritems():
star_dict[key]['betweenness'] = value
print "closeness"
closeness_map = networkx.current_flow_closeness_centrality(galaxy)
closeness_map = normalize(closeness_map)
for key, value in closeness_map.iteritems():
star_dict[key]['closeness'] = value
print "pagerank"
pagerank_map = networkx.pagerank_scipy(galaxy)
pagerank_map = normalize(pagerank_map)
for key, value in pagerank_map.iteritems():
star_dict[key]['pagerank'] = value
开发者ID:ejmahler,项目名称:galaxygen,代码行数:32,代码来源:centrality.py
示例5: describe
def describe(G, ny_tri, chems):
global describeNetwork
'''
Describe the network: degrees, clustering, and centrality measures
'''
# Degree
# The number of connections a node has to other nodes.
degrees= nx.degree(G)
degrees_df = pd.DataFrame(degrees.items(), columns=['Facility', 'Degrees'])
values = sorted(set(degrees.values()))
hist = [degrees.values().count(x) for x in values]
plt.figure()
plt.plot(values, hist,'ro-') # degree
plt.xlabel('Degree')
plt.ylabel('Number of nodes')
plt.title('Degree Distribution')
plt.savefig('output/degree_distribution.png')
# Clustering coefficients
# The bipartie clustering coefficient is a measure of local density of connections.
clust_coefficients = nx.clustering(G)
clust_coefficients_df = pd.DataFrame(clust_coefficients.items(), columns=['Facility', 'Clustering Coefficient'])
clust_coefficients_df = clust_coefficients_df.sort('Clustering Coefficient', ascending=False)
#print clust_coefficients_df
# Node centrality measures
FCG=list(nx.connected_component_subgraphs(G, copy=True))[0]
# Current flow betweenness centrality
# Current-flow betweenness centrality uses an electrical current model for information spreading
# in contrast to betweenness centrality which uses shortest paths.
betweeness = nx.current_flow_betweenness_centrality(FCG)
betweeness_df = pd.DataFrame(betweeness.items(), columns=['Facility', 'Betweeness'])
betweeness_df = betweeness_df.sort('Betweeness', ascending=False)
# Closeness centrality
# The closeness of a node is the distance to all other nodes in the graph
# or in the case that the graph is not connected to all other nodes in the connected component containing that node.
closeness = nx.closeness_centrality(FCG)
closeness_df = pd.DataFrame(closeness.items(), columns=['Facility', 'Closeness'])
closeness_df = closeness_df.sort('Closeness', ascending=False)
# Eigenvector centrality
# Eigenvector centrality computes the centrality for a node based on the centrality of its neighbors.
# In other words, how connected a node is to other highly connected nodes.
eigenvector = nx.eigenvector_centrality(FCG)
eigenvector_df = pd.DataFrame(eigenvector.items(), columns=['Facility', 'Eigenvector'])
eigenvector_df = eigenvector_df.sort('Eigenvector', ascending=False)
# Create dataframe of facility info
fac_info = ny_tri[['tri_facility_id','facility_name', 'primary_naics', 'parent_company_name']].drop_duplicates()
fac_info.rename(columns={'facility_name':'Facility'}, inplace=True)
# Merge everything
describeNetwork = degrees_df.merge(
clust_coefficients_df,on='Facility').merge(
betweeness_df,on='Facility').merge(
closeness_df, on='Facility').merge(
eigenvector_df, on='Facility').merge(
fac_info, on='Facility', how='left').merge(
chems, on='Facility', how='left')
describeNetwork = describeNetwork.sort('Degrees', ascending=False)
describeNetwork.to_csv('output/describeNetwork.csv')
开发者ID:stevecarrea,项目名称:ny_tri_networkAnalysis,代码行数:60,代码来源:buildNetwork.py
示例6: test_P4
def test_P4(self):
"""Betweenness centrality: P4"""
G = nx.path_graph(4)
b = nx.current_flow_betweenness_centrality_subset(G, list(G), list(G), normalized=True)
b_answer = nx.current_flow_betweenness_centrality(G, normalized=True)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n])
开发者ID:nishnik,项目名称:networkx,代码行数:7,代码来源:test_current_flow_betweenness_centrality_subset.py
示例7: test_P4
def test_P4(self):
"""Betweenness centrality: P4"""
G=nx.path_graph(4)
b=nx.current_flow_betweenness_centrality(G,normalized=False)
b_answer={0: 0, 1: 2, 2: 2, 3: 0}
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
开发者ID:4c656554,项目名称:networkx,代码行数:7,代码来源:test_current_flow_betweenness_centrality.py
示例8: test_K4
def test_K4(self):
"""Betweenness centrality: K4"""
G=networkx.complete_graph(4)
b=networkx.current_flow_betweenness_centrality(G,normalized=False)
b_answer={0: 0.75, 1: 0.75, 2: 0.75, 3: 0.75}
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
开发者ID:AhmedPho,项目名称:NetworkX_fork,代码行数:7,代码来源:test_current_flow_betweenness_centrality.py
示例9: centrality
def centrality(net):
values ={}
close = nx.closeness_centrality(net, normalized= True)
eigen = nx.eigenvector_centrality_numpy(net)
page = nx.pagerank(net)
bet = nx.betweenness_centrality(net,normalized= True)
flow_c = nx.current_flow_closeness_centrality(net,normalized= True)
flow_b = nx.current_flow_betweenness_centrality(net,normalized= True)
load = nx.load_centrality(net, normalized = True)
com_c = nx.communicability_centrality(net)
com_b = nx.communicability_betweenness_centrality(net, normalized= True)
degree = net.degree()
file3 = open("bl.csv",'w')
for xt in [bet,load,degree,page,flow_b,com_c,com_b,eigen,close,flow_c]:#[impo,bet,flow_b,load,com_c,com_b] :
for yt in [bet,load,degree,page,flow_b,com_c,com_b,eigen,close,flow_c]:#[impo,bet,flow_b,load,com_c,com_b] :
corr(xt.values(),yt.values(),file3)
print
file3.write("\n")
file3.close()
#plt.plot(x,y, 'o')
#plt.plot(x, m*x + c, 'r', label='Fitted line')
#plt.show()
#for key,item in close.iteritems() :
#values[key] = [impo.get(key),bet.get(key),flow_b.get(key), load.get(key),com_c.get(key),com_b.get(key)]
return values
开发者ID:FourquetDavid,项目名称:morphogenesis_network,代码行数:27,代码来源:test_complex_networks.py
示例10: test_grid
def test_grid(self):
"Approximate current-flow betweenness centrality: 2d grid"
G=nx.grid_2d_graph(4,4)
b=nx.current_flow_betweenness_centrality(G,normalized=True)
epsilon=0.1
ba = approximate_cfbc(G,normalized=True, epsilon=0.5*epsilon)
for n in sorted(G):
assert_allclose(b[n],ba[n],atol=epsilon)
开发者ID:4c656554,项目名称:networkx,代码行数:8,代码来源:test_current_flow_betweenness_centrality.py
示例11: test_K4
def test_K4(self):
"Approximate current-flow betweenness centrality: K4"
G=nx.complete_graph(4)
b=nx.current_flow_betweenness_centrality(G,normalized=False)
epsilon=0.1
ba = approximate_cfbc(G,normalized=False, epsilon=0.5*epsilon)
for n in sorted(G):
assert_allclose(b[n],ba[n],atol=epsilon*len(G)**2)
开发者ID:4c656554,项目名称:networkx,代码行数:8,代码来源:test_current_flow_betweenness_centrality.py
示例12: test_star
def test_star(self):
"""Betweenness centrality: star """
G = nx.Graph()
nx.add_star(G, ["a", "b", "c", "d"])
b = nx.current_flow_betweenness_centrality_subset(G, list(G), list(G), normalized=True)
b_answer = nx.current_flow_betweenness_centrality(G, normalized=True)
for n in sorted(G):
assert_almost_equal(b[n], b_answer[n])
开发者ID:nishnik,项目名称:networkx,代码行数:8,代码来源:test_current_flow_betweenness_centrality_subset.py
示例13: current_flow_betweenness
def current_flow_betweenness(G):
"""Current-flow betweenness centrality"""
G = G.to_undirected()
G = invert_edge_weights(G)
if nx.is_connected(G):
return nx.current_flow_betweenness_centrality(G)
else:
return _aggregate_for_components(G, nx.current_flow_betweenness_centrality)
开发者ID:himanshusapra9,项目名称:TextNet,代码行数:8,代码来源:graph.py
示例14: test_star
def test_star(self):
"""Betweenness centrality: star """
G=nx.Graph()
nx.add_star(G, ['a', 'b', 'c', 'd'])
b=nx.current_flow_betweenness_centrality(G,normalized=True)
b_answer={'a': 1.0, 'b': 0.0, 'c': 0.0, 'd':0.0}
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
开发者ID:4c656554,项目名称:networkx,代码行数:8,代码来源:test_current_flow_betweenness_centrality.py
示例15: test_K4_normalized
def test_K4_normalized(self):
"Approximate current-flow betweenness centrality: K4 normalized"
G=networkx.complete_graph(4)
b=networkx.current_flow_betweenness_centrality(G,normalized=True)
epsilon=0.1
ba = approximate_cfbc(G,normalized=True, epsilon=epsilon)
for n in sorted(G):
assert_allclose(b[n],ba[n],atol=epsilon)
开发者ID:Bludge0n,项目名称:AREsoft,代码行数:8,代码来源:test_current_flow_betweenness_centrality.py
示例16: test_solers
def test_solers(self):
"""Betweenness centrality: alternate solvers"""
G=nx.complete_graph(4)
for solver in ['full','lu','cg']:
b=nx.current_flow_betweenness_centrality(G,normalized=False,
solver=solver)
b_answer={0: 0.75, 1: 0.75, 2: 0.75, 3: 0.75}
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
开发者ID:4c656554,项目名称:networkx,代码行数:9,代码来源:test_current_flow_betweenness_centrality.py
示例17: test_K4_normalized
def test_K4_normalized(self):
"""Betweenness centrality: K4"""
G=nx.complete_graph(4)
b=nx.current_flow_betweenness_centrality(G,normalized=True)
b_answer={0: 0.25, 1: 0.25, 2: 0.25, 3: 0.25}
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
G.add_edge(0,1,{'weight':0.5,'other':0.3})
b=nx.current_flow_betweenness_centrality(G,normalized=True,weight=None)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
wb_answer={0: 0.2222222, 1: 0.2222222, 2: 0.30555555, 3: 0.30555555}
b=nx.current_flow_betweenness_centrality(G,normalized=True)
for n in sorted(G):
assert_almost_equal(b[n],wb_answer[n])
wb_answer={0: 0.2051282, 1: 0.2051282, 2: 0.33974358, 3: 0.33974358}
b=nx.current_flow_betweenness_centrality(G,normalized=True,weight='other')
for n in sorted(G):
assert_almost_equal(b[n],wb_answer[n])
开发者ID:4c656554,项目名称:networkx,代码行数:19,代码来源:test_current_flow_betweenness_centrality.py
示例18: f30
def f30(self):
return "ND"
start = 0
try:
c_vals = nx.current_flow_betweenness_centrality(self.G).values()
res = sum(c_vals)
except nx.NetworkXError:
res = "ND"
stop = 0
# self.feature_time.append(stop - start)
return res
开发者ID:jieaozhu,项目名称:alignment_free_network_comparison,代码行数:11,代码来源:generate_feature.py
示例19: test_star
def test_star(self):
"""Betweenness centrality: star """
G=networkx.Graph()
G.add_star(['a','b','c','d'])
b=networkx.current_flow_betweenness_centrality_subset(G,
G.nodes(),
G.nodes(),
normalized=True)
b_answer=networkx.current_flow_betweenness_centrality(G,normalized=True)
for n in sorted(G):
assert_almost_equal(b[n],b_answer[n])
开发者ID:AhmedPho,项目名称:NetworkX_fork,代码行数:11,代码来源:test_current_flow_betweenness_centrality_subset.py
示例20: DegreeOfInterestMIPs
def DegreeOfInterestMIPs(self, user, obj, alpha=0.3, beta=0.7):
#compute apriori importance of node obj (considers effective conductance)
current_flow_betweeness = nx.current_flow_betweenness_centrality(True, 'weight');
api_obj = current_flow_betweeness[obj] #node centrality
# print 'obj'
# print obj
# print 'api_obj'
# print api_obj
#compute proximity between user node and object node using Cycle-Free-Edge-Conductance from Koren et al. 2007
cfec_user_obj = self.CFEC(user,obj)
# print 'cfec_user_obj'
# print cfec_user_obj
return alpha*api_obj+beta*cfec_user_obj #TODO: check that scales work out for centrality and proximity, otherwise need some normalization
开发者ID:pombredanne,项目名称:MipsColWriting,代码行数:13,代码来源:GeneralMIP.py
注:本文中的networkx.current_flow_betweenness_centrality函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论