def generate_synthetic():
import random
max_nodes=200
min_nodes=100
community_num_nodes=10
graphs=[]
labels=[]
com_1= nx.caveman_graph(1, community_num_nodes)
com_2= nx.star_graph(community_num_nodes)
for i in range(500):
num_nodes= random.randint(min_nodes, max_nodes)
graph= nx.fast_gnp_random_graph(num_nodes, 0.1)
graph = nx.disjoint_union(graph,com_1)
for i in range(num_nodes,graph.number_of_nodes()):
for j in range(num_nodes):
if random.random() > 0.9:
graph.add_edge(graph.nodes()[i], graph.nodes()[j])
graphs.append(graph)
labels.append(1)
num_nodes = random.randint(min_nodes, max_nodes)
graph = nx.fast_gnp_random_graph(num_nodes, 0.1)
for i in range(num_nodes, graph.number_of_nodes()):
for j in range(num_nodes):
if random.random() > 0.9:
graph.add_edge(graph.nodes[i], graph.nodes[j])
graphs.append(graph)
labels.append(0)
return graphs,labels
评论列表
文章目录