本文整理汇总了Python中networkx.powerlaw_cluster_graph函数的典型用法代码示例。如果您正苦于以下问题:Python powerlaw_cluster_graph函数的具体用法?Python powerlaw_cluster_graph怎么用?Python powerlaw_cluster_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了powerlaw_cluster_graph函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: initialize
def initialize():
global g
global wr
global f
global initialConditions
initialConditions=0
# Inicialite file for saving data
cola= dt.datetime.now().strftime('%H%M')
outputfilename = 'competicion_01_{}.csv'.format( cola)
fileOut = open(outputfilename, 'w')
wr = csv.writer(fileOut,quoting = csv.QUOTE_NONE)
wr.writerow(['Tipo 1','Tipo 2','Tipo 3','Patogeno'])
f = open( 'competicion_01_{}.ini'.format( cola), "w")
# g = nx.karate_club_graph()
g=nx.powerlaw_cluster_graph(100,3,0.3)
g.pos = nx.spring_layout(g)
for i in g.nodes_iter():
if random() < .33:
g.node[i]['tipo'] = 0
elif random() < .33:
g.node[i]['tipo'] = 1
elif random() < .33:
g.node[i]['tipo'] = 2
elif random() < .33:
g.node[i]['tipo'] = 3
else:
g.node[i]['tipo'] = 4
开发者ID:falevian,项目名称:Bacterias-PrimerosPasos,代码行数:29,代码来源:00+Un+bacteria+contra+tres.py
示例2: get_graph
def get_graph(objects, properties):
graph_type = properties['graph_type']
n = len(objects)-1
if 'num_nodes_to_attach' in properties.keys():
k = properties['num_nodes_to_attach']
else:
k = 3
r = properties['connection_probability']
tries = 0
while(True):
if graph_type == 'random':
x = nx.fast_gnp_random_graph(n,r)
elif graph_type == 'erdos_renyi_graph':
x = nx.erdos_renyi_graph(n,r)
elif graph_type == 'watts_strogatz_graph':
x = nx.watts_strogatz_graph(n, k, r)
elif graph_type == 'newman_watts_strogatz_graph':
x = nx.newman_watts_strogatz_graph(n, k, r)
elif graph_type == 'barabasi_albert_graph':
x = nx.barabasi_albert_graph(n, k, r)
elif graph_type == 'powerlaw_cluster_graph':
x = nx.powerlaw_cluster_graph(n, k, r)
elif graph_type == 'cycle_graph':
x = nx.cycle_graph(n)
else: ##Star by default
x = nx.star_graph(len(objects)-1)
tries += 1
cc_conn = nx.connected_components(x)
if len(cc_conn) == 1 or tries > 5:
##best effort to create a connected graph!
break
return x, cc_conn
开发者ID:BenjaminDHorne,项目名称:agentsimulation,代码行数:33,代码来源:GraphGen.py
示例3: fromPowerLaw
def fromPowerLaw(cls, specs):
'''
:param specs: a tupple containing (n, m, p, seed, bw, delay, cpu)
:return: a substrate
'''
n, m, p, seed, bw, delay, cpu = specs
n = int(n)
m = int(m)
p = float(p)
seed = int(seed)
g = nx.powerlaw_cluster_graph(n, m, p, seed)
session = Session()
nodes = [Node(name=str(n), cpu_capacity=cpu) for n in g.nodes()]
session.add_all(nodes)
session.flush()
edges = [Edge
(node_1=session.query(Node).filter(Node.name == str(e[0])).one(),
node_2=session.query(Node).filter(Node.name == str(e[1])).one(),
bandwidth=bw,
delay=delay
)
for e in g.edges()
]
session.add_all(edges)
session.flush()
return cls(edges, nodes
)
开发者ID:nherbaut,项目名称:vCDN,代码行数:31,代码来源:substrate.py
示例4: __update_structure
def __update_structure(self):
self.structure = nx.powerlaw_cluster_graph(
self.num_nodes,
self.node_degree,
self.prob_triad,
self.seed
)
if nx.is_connected(self.structure):
return
components = nx.connected_components(self.structure)
biggest_comp = []
comp_index = -1
for i, component in enumerate(components):
if len(component) > len(biggest_comp):
biggest_comp = component
comp_index = i
if self.seed:
random.seed(self.seed)
del components[comp_index]
for component in components:
for left_node in component:
right_node = random.choice(biggest_comp)
self.structure.add_edge(left_node, right_node)
开发者ID:jim-pansn,项目名称:sybil_detection,代码行数:28,代码来源:graphs.py
示例5: add_edges_to_groups
def add_edges_to_groups(output_graph, groups_list, edges_to_add, prob, level):
global template_created
total_groups = len(groups_list)
edges_per_node = max((3 - level), 1)
triangle_prob = 0.1*level
if False:
random_graph = nx.random_regular_graph(int(total_groups/3), total_groups)
else:
random_graph = nx.powerlaw_cluster_graph(total_groups, edges_per_node, triangle_prob, random.random()*10)
if template_created:
template_created = False
plt.axis('off')
position = nx.graphviz_layout(random_graph, prog='sfdp')
nx.draw_networkx_nodes(random_graph, position, node_size=30, node_color='r') #output_graph.degree().values())
nx.draw_networkx_edges(random_graph, position, alpha=0.3)
plt.savefig(dataset_name2 +"/"+ "template_" + image_name, bbox_inches='tight', dpi=500)
print "plot saved as ", image_name
random_edges = random_graph.edges()
for edge in random_edges:
e0 = edge[0]
e1 = edge[1]
if random.random() > 0.3:
e0, e1 = e1, e0
print("adding level{} edges between group{} and group{}".format(level, e0, e1))
add_edges_to_two_groups(output_graph, groups_list[e0], groups_list[e1], edges_to_add, prob)
开发者ID:vijkp,项目名称:graph-bench,代码行数:28,代码来源:igen_data.py
示例6: test_pagerank
def test_pagerank(self):
size = 1000
g = nx.DiGraph(nx.powerlaw_cluster_graph(size, 3, 0.001))
N = len(g.nodes())
tmp_file = tempfile.NamedTemporaryFile(delete=False)
for node in g.nodes():
outlinks = g.out_edges(nbunch=[node])
outlinks = map(str, [n2 for n1, n2 in outlinks])
if not outlinks:
value = 'pr_results,%s,%s' % (1.0/N, N)
tmp_file.write('%s\t%s\n' % (node, value))
else:
outlinks_str = ','.join(outlinks)
value = 'pr_results,%s,%s,' % (1.0/N, N)
value += outlinks_str
tmp_file.write('%s\t%s\n' % (node, value))
tmp_file.flush()
input_path = tmp_file.name
job_id = 'unittest'
sorted_ids = pagerank(job_id, self.iter_count, input_path, self.top_n)
fs = HadoopFS()
fs.rmr('%s/hat_results' % job_id)
if self.top_n <= size:
self.assertEqual(len(sorted_ids), self.top_n, 'some ids is missing')
id_ranges = range(0, 1000)
for _id in sorted_ids:
self.assertIn(int(_id), id_ranges, 'node should in graph')
开发者ID:huxiaoqian,项目名称:project,代码行数:27,代码来源:area_identify_test.py
示例7: createGraphsAndCommunities
def createGraphsAndCommunities():
g = nx.scale_free_graph(500, alpha=0.40, beta=0.40, gamma=0.20)
g1 = nx.powerlaw_cluster_graph(500, 10, 0.2)
g2 = nx.barabasi_albert_graph(500, 10)
g3 = nx.newman_watts_strogatz_graph(500, 10, 0.2)
nx.write_graphml (g, direc+"sfg.graphml")
nx.write_graphml(g1, direc+"pcg.graphml")
nx.write_graphml(g2, direc+"bag.graphml")
nx.write_graphml(g3, direc+"nwsg.graphml")
graphs = {}
graphs["sfg"] = graph_tool.load_graph(direc+"sfg.graphml")
graphs["pcg"] = graph_tool.load_graph(direc+"pcg.graphml")
graphs["bag"] = graph_tool.load_graph(direc+"bag.graphml")
graphs["nwsg"] = graph_tool.load_graph(direc+"nwsg.graphml")
graphs["price"] = graph_tool.generation.price_network(1000)
for i,h in graphs.iteritems():
s = graph_tool.community.minimize_blockmodel_dl(h)
b = s.b
graph_tool.draw.graph_draw(h, vertex_fill_color=b, vertex_shape=b, output=direc+"block"+str(i)+".pdf")
com = graph_tool.community.community_structure(h, 10000, 20)
graph_tool.draw.graph_draw(h, vertex_fill_color=com, vertex_shape=com, output=direc+"community"+str(i)+".pdf")
state = graph_tool.community.minimize_nested_blockmodel_dl(h)
graph_tool.draw.draw_hierarchy(state, output=direc+"nestedblock"+str(i)+".pdf")
pagerank = graph_tool.centrality.pagerank(h)
graph_tool.draw.graph_draw(h, vertex_fill_color=pagerank, vertex_size = graph_tool.draw.prop_to_size(pagerank, mi=5, ma=15), vorder=pagerank, output=direc+"pagerank"+str(i)+".pdf")
h.set_reversed(is_reversed=True)
pagerank = graph_tool.centrality.pagerank(h)
graph_tool.draw.graph_draw(h, vertex_fill_color=pagerank, vertex_size = graph_tool.draw.prop_to_size(pagerank, mi=5, ma=15), vorder=pagerank, output=direc+"reversed_pagerank"+str(i)+".pdf")
开发者ID:stonepierre,项目名称:reseauSocial,代码行数:33,代码来源:graphtoolMethods.py
示例8: RandomHolmeKim
def RandomHolmeKim(n, m, p, seed=None):
"""
Returns a random graph generated by the Holme and Kim algorithm for
graphs with power law degree distribution and approximate average
clustering.
INPUT:
- ``n`` - number of vertices.
- ``m`` - number of random edges to add for each new
node.
- ``p`` - probability of adding a triangle after
adding a random edge.
- ``seed`` - for the random number generator.
From the NetworkX documentation: The average clustering has a hard
time getting above a certain cutoff that depends on m. This cutoff
is often quite low. Note that the transitivity (fraction of
triangles to possible triangles) seems to go down with network
size. It is essentially the Barabasi-Albert growth model with an
extra step that each random edge is followed by a chance of making
an edge to one of its neighbors too (and thus a triangle). This
algorithm improves on B-A in the sense that it enables a higher
average clustering to be attained if desired. It seems possible to
have a disconnected graph with this algorithm since the initial m
nodes may not be all linked to a new node on the first iteration
like the BA model.
EXAMPLE: We show the edge list of a random graph on 8 nodes with 2
random edges per node and a probability `p = 0.5` of
forming triangles.
::
sage: graphs.RandomHolmeKim(8, 2, 0.5).edges(labels=False)
[(0, 2), (0, 5), (1, 2), (1, 3), (2, 3), (2, 4), (2, 6), (2, 7),
(3, 4), (3, 6), (3, 7), (4, 5)]
::
sage: G = graphs.RandomHolmeKim(12, 3, .3)
sage: G.show() # long time
REFERENCE:
- [1] Holme, P. and Kim, B.J. Growing scale-free networks with
tunable clustering, Phys. Rev. E (2002). vol 65, no 2,
026107.
"""
if seed is None:
seed = current_randstate().long_seed()
import networkx
return graph.Graph(networkx.powerlaw_cluster_graph(n, m, p, seed=seed))
开发者ID:CETHop,项目名称:sage,代码行数:59,代码来源:random.py
示例9: generate_topo
def generate_topo(n):
topo = nx.powerlaw_cluster_graph(n,2,0.08)
# topo = fnss.waxman_1_topology(n=50,alpha=0.6,beta=0.3)
# topo = fnss.fat_tree_topology(n)
fnss.set_weights_constant(topo,1)
fnss.set_delays_constant(topo, 1, 'ms')
fnss.set_capacities_edge_betweenness(topo,[100,500,1000],'Mbps')
fnss.write_topology(topo,'topo_pl_50.xml')
开发者ID:chenhuan0,项目名称:ryu,代码行数:8,代码来源:topo_random.py
示例10: generate_graph
def generate_graph():
# Try these included graphs! Play around with the constants!
# Feel free to define your own graph for testing.
#return nx.random_regular_graph(5, GRAPH_SIZE, seed=GRAPH_SEED)
#return nx.barabasi_albert_graph(GRAPH_SIZE, 5)
#return grid_graph()
return nx.powerlaw_cluster_graph(GRAPH_SIZE, 5, 0.7)
开发者ID:jamesjwu,项目名称:awap-2015,代码行数:8,代码来源:graphs.py
示例11: graph_space_iter
def graph_space_iter():
i = 20
n = 0
while n < 1000000:
G = nx.powerlaw_cluster_graph(i, 10, 0.1)
G = nx.convert_node_labels_to_integers(G)
n = G.number_of_edges()
i *= 2
yield G.number_of_nodes(), G
开发者ID:jorants,项目名称:MV-Matching-V2,代码行数:9,代码来源:test.py
示例12: pl_cluster_new
def pl_cluster_new(n, m, p, random_seed=None):
Gw=nx.powerlaw_cluster_graph(n, m, p, seed=random_seed)
Gs=nx.Graph()
Gs.add_nodes_from(Gw.nodes(),state=1.0)
Gs.add_edges_from(Gw.edges(),weight=1.0)
##remove self-edges
Gs.remove_edges_from(Gs.selfloop_edges())
return Gs
开发者ID:sideshownick,项目名称:NetWorks,代码行数:10,代码来源:my_networks.py
示例13: create_scale_free_graph
def create_scale_free_graph(N_nodes,p_edge,n_infected):
#scale free and small world
#Growing Scale-Free Networks with Tunable Clustering
n = N_nodes
m = int(0.5*p_edge*N_nodes)
p = 1.0
#Random graph
#p_coop is the fraction of cooperators
G = nx.powerlaw_cluster_graph(n,m,p)
return set_graph_strategies(G, n_infected)
开发者ID:jnkh,项目名称:epidemics,代码行数:10,代码来源:graph_epidemic.py
示例14: topo_pl
def topo_pl(nodes):
bws = [1,2,3,4,5,6,7,8,9]
network = nx.powerlaw_cluster_graph(nodes,2,0.13)
g = nx.Graph()
g.add_nodes_from(network.nodes())
for link in network.edges():
bw = random.choice(bws)
g.add_edge(link[0],link[1],{'weight':bw})
g.add_edge(link[1],link[0],{'weight':bw})
return g
开发者ID:chenhuan0,项目名称:ryu,代码行数:10,代码来源:rerouter.py
示例15: initialize
def initialize():
global g
# g = nx.karate_club_graph()
g=nx.powerlaw_cluster_graph(100,3,0.3)
g.pos = nx.spring_layout(g)
for i in g.nodes_iter():
if random() < .3:
g.node[i]['state'] = 1
elif random() < .3:
g.node[i]['state'] = 2
elif random() < .3:
g.node[i]['state'] = 3
else:
g.node[i]['state'] = 0
开发者ID:falevian,项目名称:Bacterias-PrimerosPasos,代码行数:14,代码来源:00+Adaptativo_Matricial.py
示例16: main
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--input', help="Input file path", default=None)
parser.add_argument(
'-o', '--output', help="Output file path",
default=None)
parser.add_argument(
'--page-rank',
help="Adds page rank to the output network",
action='store_const', default=False, const=True)
parser.add_argument(
'--eigenvector',
help="Adds eigenvector centrality to the output network",
action='store_const', default=False, const=True)
parser.add_argument(
'--betweenness',
help="Adds betweenness centrality to the output network",
action='store_const', default=False, const=True)
namespace = parser.parse_args()
if namespace.input is None:
graph = nx.powerlaw_cluster_graph(100, 8, 0.1)
else:
graph = read_network(namespace.input)
if namespace.page_rank:
page_rank_dictionary = nx.pagerank(graph)
for node, rank in page_rank_dictionary.iteritems():
graph.add_node(node, pagerank=rank)
if namespace.eigenvector:
eig_dictionary = nx.eigenvector_centrality(graph)
for node, rank in eig_dictionary.iteritems():
graph.add_node(node, eigenvector_centrality=rank)
if namespace.betweenness:
betw_dictionary = nx.betweenness_centrality(graph)
for node, rank in betw_dictionary.iteritems():
graph.add_node(node, betweenness=rank)
graph_dict = convert_network(graph)
if namespace.output is None:
out = sys.stdout
else:
out = file(namespace.output, 'w')
json.dump(graph_dict, out)
开发者ID:rik0,项目名称:PyD3Formatter,代码行数:49,代码来源:Py3DFormatter.py
示例17: __init__
def __init__(self, vertices, m, c, seed = int(time.time())):
"""
Construct a Powerlaw Clustered network. The vertices argument contains
objects of type Vertex representing the vertices of the network. The
m argument specifies the number of attachments made from the
new vertex to the existing vertices during the network construction
process. The c argument specifies the desired level of clustering.
The seed argument is the seed for the random number generator used to
build the network.
Note that the desired level of clustering may not always be achievable.
"""
self.vertices = vertices
self.m = m
self.c = c
self.seed = seed
p = 0.0
g = networkx.powerlaw_cluster_graph(len(vertices), m, p, seed = seed)
while p < 1 and networkx.average_clustering(g) < c:
g = networkx.powerlaw_cluster_graph(len(vertices), m, p)
p += 0.01
self.g = g
self.__adj_list_map__ = {}
开发者ID:swamiiyer,项目名称:network,代码行数:24,代码来源:network.py
示例18: emulate
def emulate(tmp_file, size=1000):
g = nx.DiGraph(nx.powerlaw_cluster_graph(size, 3, 0.001))
N = len(g.nodes())
for node in g.nodes():
outlinks = g.out_edges(nbunch=[node])
outlinks = map(str, [n2 for n1, n2 in outlinks])
if not outlinks:
value = 'pr_results,%s,%s' % (1.0/N, N)
tmp_file.write('%s\t%s\n' % (node, value))
else:
outlinks_str = ','.join(outlinks)
value = 'pr_results,%s,%s,' % (1.0/N, N)
value += outlinks_str
tmp_file.write('%s\t%s\n' % (node, value))
return tmp_file
开发者ID:huxiaoqian,项目名称:project,代码行数:15,代码来源:pagerank_test.py
示例19: __init__
def __init__(self, vertices, m, p, seed = int(time.time())):
"""
Construct a Powerlaw Clustered network. The vertices argument contains
objects of type Vertex representing the vertices of the network. The
m argument specifies the number of attachments made from the
new vertex to the existing vertices during the network construction
process. The p argument specifies the probability of adding a triangle
after adding a random edge. The seed argument is the seed for
the random number generator used to build the network.
"""
self.vertices = vertices
self.m = m
self.p = p
self.seed = seed
self.g = networkx.powerlaw_cluster_graph(len(vertices), m, p, seed = seed)
self.__adj_list_map__ = {}
开发者ID:swamiiyer,项目名称:edcn,代码行数:17,代码来源:network.py
示例20: add_edges_to_groups
def add_edges_to_groups(output_graph, groups_list, edges_to_add, prob, level):
total_groups = len(groups_list)
edges_per_node = max((3 - level), 1)
triangle_prob = 0.1*level
if False:
random_graph = nx.random_regular_graph(int(total_groups/3), total_groups)
else:
random_graph = nx.powerlaw_cluster_graph(total_groups, edges_per_node, triangle_prob, random.random()*10)
random_edges = random_graph.edges()
for edge in random_edges:
e0 = edge[0]
e1 = edge[1]
if random.random() > 0.3:
e0, e1 = e1, e0
print("adding level{} edges between group{} and group{}".format(level, e0, e1))
add_edges_to_two_groups(output_graph, groups_list[e0], groups_list[e1], edges_to_add, prob)
开发者ID:vijkp,项目名称:graph-bench,代码行数:17,代码来源:gen_data.py
注:本文中的networkx.powerlaw_cluster_graph函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论