本文整理汇总了Python中networkx.radius函数的典型用法代码示例。如果您正苦于以下问题:Python radius函数的具体用法?Python radius怎么用?Python radius使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了radius函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NetStats
def NetStats(G):
return { 'radius': nx.radius(G),
'diameter': nx.diameter(G),
'connected_components': nx.number_connected_components(G),
'density' : nx.density(G),
'shortest_path_length': nx.shortest_path_length(G),
'clustering': nx.clustering(G)}
示例2: strongly_connected_components
def strongly_connected_components():
conn = sqlite3.connect("zhihu.db")
#following_data = pd.read_sql('select user_url, followee_url from Following where followee_url in (select user_url from User where agree_num > 50000) and user_url in (select user_url from User where agree_num > 50000)', conn)
following_data = pd.read_sql('select user_url, followee_url from Following where followee_url in (select user_url from User where agree_num > 10000) and user_url in (select user_url from User where agree_num > 10000)', conn)
conn.close()
G = nx.DiGraph()
cnt = 0
for d in following_data.iterrows():
G.add_edge(d[1][0],d[1][1])
cnt += 1
print 'links number:', cnt
scompgraphs = nx.strongly_connected_component_subgraphs(G)
scomponents = sorted(nx.strongly_connected_components(G), key=len, reverse=True)
print 'components nodes distribution:', [len(c) for c in scomponents]
#plot graph of component, calculate saverage_shortest_path_length of components who has over 1 nodes
index = 0
print 'average_shortest_path_length of components who has over 1 nodes:'
for tempg in scompgraphs:
index += 1
if len(tempg.nodes()) != 1:
print nx.average_shortest_path_length(tempg)
print 'diameter', nx.diameter(tempg)
print 'radius', nx.radius(tempg)
pylab.figure(index)
nx.draw_networkx(tempg)
pylab.show()
# Components-as-nodes Graph
cG = nx.condensation(G)
pylab.figure('Components-as-nodes Graph')
nx.draw_networkx(cG)
pylab.show()
示例3: print_graph_info
def print_graph_info(graph):
e = nx.eccentricity(graph)
print 'graph with %u nodes, %u edges' % (len(graph.nodes()), len(graph.edges()))
print 'radius: %s' % nx.radius(graph, e) # min e
print 'diameter: %s' % nx.diameter(graph, e) # max e
print 'len(center): %s' % len(nx.center(graph, e)) # e == radius
print 'len(periphery): %s' % len(nx.periphery(graph, e)) # e == diameter
示例4: calculate
def calculate(network):
try:
n = nx.radius(network)
except:
return 0
return round(n, 7)
示例5: netstats_simple
def netstats_simple(graph):
G = graph
if nx.is_connected(G):
d = nx.diameter(G)
r = nx.radius(G)
else:
d = 'NA - graph is not connected' #should be calculatable on unconnected graph - see example code for hack
r = 'NA - graph is not connected'
#using dictionary to pack values and variablesdot, eps, ps, pdf break equally
result = {#"""single value measures"""
'nn': G.number_of_nodes(),
'ne': G.number_of_edges(),
'd': d,
'r': r,
'conn': nx.number_connected_components(G),
'asp': nx.average_shortest_path_length(G),
# """number of the largest clique"""
'cn': nx.graph_clique_number(G),
# """number of maximal cliques"""
'mcn': nx.graph_number_of_cliques(G),
# """transitivity - """
'tr': nx.transitivity(G),
#cc = nx.clustering(G) """clustering coefficient"""
'avgcc': nx.average_clustering(G) }
# result['d'] = nx.diameter(G)
print result
return result
示例6: NetStats
def NetStats(G,name):
s=0
d = nx.degree(G)
for i in d.values():
s = s + i
n = len(G.nodes())
m = len(G.edges())
k = float(s)/float(n)
#k = nx.average_node_connectivity(G)
C = nx.average_clustering(G)
l = nx.average_shortest_path_length(G)
Cc = nx.closeness_centrality(G)
d = nx.diameter(G) #The diameter is the maximum eccentricity.
r = nx.radius(G) #The radius is the minimum eccentricity.
output = "ESTADISITICOS_"+name
SALIDA = open(output,"w")
SALIDA.write(("Numero de nodos n = %s \n") % n)
SALIDA.write(("Numero de aristas m = %s \n") % m)
SALIDA.write(("Grado promedio <k> = %s \n") % k)
SALIDA.write(("Clustering Coeficient = %s \n") % C)
SALIDA.write(("Shortest Path Length = %s \n") % l)
#SALIDA.write(("Closeness = %s \n") % Cc)
SALIDA.write(("Diameter (maximum eccentricity) = %d \n") % d)
SALIDA.write(("Radius (minimum eccentricity) = %d \n") % r)
示例7: get_tree_symmetries_for_traitset
def get_tree_symmetries_for_traitset(model, simconfig, cultureid, traitset, culture_count_map):
radii = []
symstats = stats.BalancedTreeAutomorphismStatistics(simconfig)
subgraph_set = model.trait_universe.get_trait_graph_components(traitset)
trait_subgraph = model.trait_universe.get_trait_forest_from_traits(traitset)
results = symstats.calculate_graph_symmetries(trait_subgraph)
for subgraph in subgraph_set:
radii.append( nx.radius(subgraph))
mean_radii = np.mean(np.asarray(radii))
sd_radii = np.sqrt(np.var(np.asarray(radii)))
degrees = nx.degree(trait_subgraph).values()
mean_degree = np.mean(np.asarray(degrees))
sd_degree = np.sqrt(np.var(np.asarray(degrees)))
mean_orbit_mult = np.mean(np.asarray(results['orbitcounts']))
sd_orbit_mult = np.sqrt(np.var(np.asarray(results['orbitcounts'])))
max_orbit_mult = np.nanmax(np.asarray(results['orbitcounts']))
r = dict(cultureid=str(cultureid), culture_count=culture_count_map[cultureid],
orbit_multiplicities=results['orbitcounts'],
orbit_number=results['orbits'],
autgroupsize=results['groupsize'],
remaining_density=results['remainingdensity'],
mean_radii=mean_radii,
sd_radii=sd_radii,
mean_degree=mean_degree,
sd_degree=sd_degree,
mean_orbit_multiplicity=mean_orbit_mult,
sd_orbit_multiplicity=sd_orbit_mult,
max_orbit_multiplicity=max_orbit_mult
)
#log.debug("groupstats: %s", r)
return r
示例8: updateGraphStats
def updateGraphStats(self, graph):
origgraph = graph
if nx.is_connected(graph):
random = 0
else:
connectedcomp = nx.connected_component_subgraphs(graph)
graph = max(connectedcomp)
if len(graph) > 1:
pathlength = nx.average_shortest_path_length(graph)
else:
pathlength = 0
# print graph.nodes(), len(graph), nx.is_connected(graph)
stats = {
"radius": nx.radius(graph),
"density": nx.density(graph),
"nodecount": len(graph.nodes()),
"center": nx.center(graph),
"avgcluscoeff": nx.average_clustering(graph),
"nodeconnectivity": nx.node_connectivity(graph),
"components": nx.number_connected_components(graph),
"avgpathlength": pathlength
}
# print "updated graph stats", stats
return stats
示例9: graph_radius
def graph_radius(graph):
sp = nx.shortest_path_length(graph,weight='weight')
ecc = nx.eccentricity(graph,sp=sp)
if ecc:
rad = nx.radius(graph,e=ecc)
else:
rad = 0
return rad
示例10: test_radius
def test_radius(testgraph):
"""
Testing radius function for graphs.
"""
a, b = testgraph
nx_rad = nx.radius(a)
sg_rad = sg.digraph_distance_measures.radius(b, b.order())
assert nx_rad == sg_rad
示例11: get_path_lengths
def get_path_lengths(self):
if not hasattr(self,"shortest_path_lenghts") or self.shortest_path_lenghts is None:
self.shortest_paths_lengths = nx.all_pairs_shortest_path_length(self.G)
self.avg_shortest_path = sum([ length for sp in self.shortest_paths_lengths.values() for length in sp.values() ])/float(self.N*(self.N-1))
self.eccentricity = nx.eccentricity(self.G,sp=self.shortest_paths_lengths)
self.diameter = nx.diameter(self.G,e=self.eccentricity)
self.radius = nx.radius(self.G,e=self.eccentricity)
return self.shortest_paths_lengths
示例12: get_graph_info
def get_graph_info(graph):
nodes = networkx.number_of_nodes(graph)
edges = networkx.number_of_edges(graph)
radius = networkx.radius(graph)
diameter = networkx.diameter(graph)
density = networkx.density(graph)
average_clustering = networkx.average_clustering(graph)
average_degree = sum(graph.degree().values()) / nodes
return nodes, edges, radius, diameter, density, average_clustering, average_degree
示例13: connectivity
def connectivity(self):
components = list(nx.connected_component_subgraphs(self.G))
print('Connected components number: ')
print(len(components))
giant = components.pop(0)
print('Giant component radius: ')
print(nx.radius(giant))
print('Giant component diameter: ')
print(nx.diameter(giant))
center = nx.center(giant)
print('Giant component center: ')
for i in xrange(len(center)):
print(self.singer_dict[int(center[i])].split('|')[0])
inf = self.get_graph_info(giant)
for i in xrange(len(inf)):
print(inf[i])
示例14: write_graph
def write_graph(graph_name, g):
radius = nx.radius(g)
# https://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.distance_measures.radius.html
diameter = nx.diameter(g)
# https://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.distance_measures.diameter.html
closeness = float(sum(nx.algorithms.centrality.closeness_centrality(g).values()))/size
# https://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.centrality.closeness_centrality.html#networkx.algorithms.centrality.closeness_centrality
betweenness = float(sum(nx.algorithms.centrality.betweenness_centrality(g).values()))/size
# https://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.centrality.betweenness_centrality.html#networkx.algorithms.centrality.betweenness_centrality
clustering = float(sum(nx.algorithms.clustering(g).values()))/size
# https://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.cluster.clustering.html#networkx.algorithms.cluster.clustering
print "%s\t%s\t%s\t%s\t%s\t%s" % (graph_name, radius, diameter, closeness, betweenness, clustering)
示例15: PrintGraphStat
def PrintGraphStat(self):
logging.debug("From SVNFileNetwork.PrintGraphStat")
print "%s" % '-' * 40
print "Graph Radius : %f" % NX.radius(self)
print "Graph Diameter : %f" % NX.diameter(self)
weighted = True
closenessdict = NX.closeness_centrality(self, distance=weighted)
print "%s" % '-' * 40
print "All nodes in graph"
nodeinfolist = [(node, closeness)
for node, closeness in closenessdict.items()]
# sort the node infolist by closeness number
nodeinfolist = sorted(
nodeinfolist, key=operator.itemgetter(1), reverse=True)
for node, closeness in nodeinfolist:
print "\t%s : %f" % (node.name(), closeness)
print "%s" % '-' * 40