You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

create_graphs.py 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import networkx as nx
  2. import numpy as np
  3. from utils import *
  4. from data import *
  5. def create(args):
  6. ### load datasets
  7. graphs=[]
  8. # synthetic graphs
  9. if args.graph_type=='ladder':
  10. graphs = []
  11. for i in range(100, 201):
  12. graphs.append(nx.ladder_graph(i))
  13. args.max_prev_node = 10
  14. elif args.graph_type=='ladder_small':
  15. graphs = []
  16. for i in range(2, 11):
  17. graphs.append(nx.ladder_graph(i))
  18. args.max_prev_node = 10
  19. elif args.graph_type=='tree':
  20. graphs = []
  21. for i in range(2,5):
  22. for j in range(3,5):
  23. graphs.append(nx.balanced_tree(i,j))
  24. args.max_prev_node = 256
  25. elif args.graph_type=='caveman':
  26. # graphs = []
  27. # for i in range(5,10):
  28. # for j in range(5,25):
  29. # for k in range(5):
  30. # graphs.append(nx.relaxed_caveman_graph(i, j, p=0.1))
  31. graphs = []
  32. for i in range(2, 3):
  33. for j in range(30, 81):
  34. for k in range(10):
  35. graphs.append(caveman_special(i,j, p_edge=0.3))
  36. args.max_prev_node = 100
  37. elif args.graph_type=='caveman_small':
  38. # graphs = []
  39. # for i in range(2,5):
  40. # for j in range(2,6):
  41. # for k in range(10):
  42. # graphs.append(nx.relaxed_caveman_graph(i, j, p=0.1))
  43. graphs = []
  44. for i in range(2, 3):
  45. for j in range(6, 11):
  46. for k in range(20):
  47. graphs.append(caveman_special(i, j, p_edge=0.8)) # default 0.8
  48. args.max_prev_node = 20
  49. elif args.graph_type=='caveman_small_single':
  50. # graphs = []
  51. # for i in range(2,5):
  52. # for j in range(2,6):
  53. # for k in range(10):
  54. # graphs.append(nx.relaxed_caveman_graph(i, j, p=0.1))
  55. graphs = []
  56. for i in range(2, 3):
  57. for j in range(8, 9):
  58. for k in range(100):
  59. graphs.append(caveman_special(i, j, p_edge=0.5))
  60. args.max_prev_node = 20
  61. elif args.graph_type.startswith('community'):
  62. num_communities = int(args.graph_type[-1])
  63. print('Creating dataset with ', num_communities, ' communities')
  64. c_sizes = np.random.choice([12, 13, 14, 15, 16, 17], num_communities)
  65. #c_sizes = [15] * num_communities
  66. for k in range(3000):
  67. graphs.append(n_community(c_sizes, p_inter=0.01))
  68. args.max_prev_node = 80
  69. elif args.graph_type=='grid':
  70. graphs = []
  71. for i in range(10,20):
  72. for j in range(10,20):
  73. graphs.append(nx.grid_2d_graph(i,j))
  74. args.max_prev_node = 40
  75. elif args.graph_type=='grid_small':
  76. graphs = []
  77. for i in range(2,5):
  78. for j in range(2,6):
  79. graphs.append(nx.grid_2d_graph(i,j))
  80. args.max_prev_node = 15
  81. elif args.graph_type=='barabasi':
  82. graphs = []
  83. for i in range(100,200):
  84. for j in range(4,5):
  85. for k in range(5):
  86. graphs.append(nx.barabasi_albert_graph(i,j))
  87. args.max_prev_node = 130
  88. elif args.graph_type=='barabasi_small':
  89. graphs = []
  90. for i in range(4,21):
  91. for j in range(3,4):
  92. for k in range(10):
  93. graphs.append(nx.barabasi_albert_graph(i,j))
  94. args.max_prev_node = 20
  95. elif args.graph_type=='grid_big':
  96. graphs = []
  97. for i in range(36, 46):
  98. for j in range(36, 46):
  99. graphs.append(nx.grid_2d_graph(i, j))
  100. args.max_prev_node = 90
  101. elif 'barabasi_noise' in args.graph_type:
  102. graphs = []
  103. for i in range(100,101):
  104. for j in range(4,5):
  105. for k in range(500):
  106. graphs.append(nx.barabasi_albert_graph(i,j))
  107. graphs = perturb_new(graphs,p=args.noise/10.0)
  108. args.max_prev_node = 99
  109. # real graphs
  110. elif args.graph_type == 'enzymes':
  111. graphs= Graph_load_batch(min_num_nodes=10, name='ENZYMES')
  112. args.max_prev_node = 25
  113. elif args.graph_type == 'enzymes_small':
  114. graphs_raw = Graph_load_batch(min_num_nodes=10, name='ENZYMES')
  115. graphs = []
  116. for G in graphs_raw:
  117. if G.number_of_nodes()<=20:
  118. graphs.append(G)
  119. args.max_prev_node = 15
  120. elif args.graph_type == 'protein':
  121. graphs = Graph_load_batch(min_num_nodes=20, name='PROTEINS_full')
  122. args.max_prev_node = 80
  123. elif args.graph_type == 'DD':
  124. graphs = Graph_load_batch(min_num_nodes=100, max_num_nodes=500, name='DD',node_attributes=False,graph_labels=True)
  125. args.max_prev_node = 230
  126. elif args.graph_type == 'citeseer':
  127. _, _, G = Graph_load(dataset='citeseer')
  128. G = max(nx.connected_component_subgraphs(G), key=len)
  129. G = nx.convert_node_labels_to_integers(G)
  130. graphs = []
  131. for i in range(G.number_of_nodes()):
  132. G_ego = nx.ego_graph(G, i, radius=3)
  133. if G_ego.number_of_nodes() >= 50 and (G_ego.number_of_nodes() <= 400):
  134. graphs.append(G_ego)
  135. args.max_prev_node = 250
  136. elif args.graph_type == 'citeseer_small':
  137. _, _, G = Graph_load(dataset='citeseer')
  138. G = max(nx.connected_component_subgraphs(G), key=len)
  139. G = nx.convert_node_labels_to_integers(G)
  140. graphs = []
  141. for i in range(G.number_of_nodes()):
  142. G_ego = nx.ego_graph(G, i, radius=1)
  143. if (G_ego.number_of_nodes() >= 4) and (G_ego.number_of_nodes() <= 20):
  144. graphs.append(G_ego)
  145. shuffle(graphs)
  146. graphs = graphs[0:200]
  147. args.max_prev_node = 15
  148. return graphs