def generate_graph(nc, seed): out_dir = FULLY + 'small-world-n1000-k10-p5-nc' + str(nc) + '-seed' + str( seed) graph = create_graph(n=1000, nc=nc, feature_dim=16, k=10, p=0.5, seed=seed) features = get_features_from_graph(graph) FullySynthetic.save_graph(out_dir, graph, features) return out_dir
def gen_fully(full, n_nodes, n_edges, p): name_p = str(int(p)) outdir = full + "/erdos-renyi-n{}-p{}".format(n_nodes, name_p) FullySynthetic.generate_erdos_renyi_graph(outdir, n_nodes=n_nodes, n_edges=n_edges) return outdir
def create_graph(n, nc, feature_dim, k, p, seed=100): """ :param n: number of nodes :param nc: number of connected components :return: graph of networkx format """ # np.random.seed(123) n_nodes = random_number_of_nodes(n, nc, k) graphs = [] idx_node_large_graph = 0 for n_node in n_nodes: graph, feature = FullySynthetic.generate_small_world_graph( None, n_node, k, p, feature_dim=feature_dim, seed=seed) add_feature_to_graph(graph, feature) print("====Subgraph===") print(nx.info(graph)) to_one_connected_components(graph) graph, idx_node_large_graph = relabel_graph(graph, idx_node_large_graph) graphs.append(graph) check_graphs_labels_distinguish(graphs) while len(graphs) > 1: graph = nx.compose(graphs[0], graphs[1]) graphs = [graph, *graphs[2:]] print("====Large graph====") print(nx.info(graphs[0])) print("Number of connected components:", len(list(nx.connected_components(graphs[0])))) return graphs[0]
from input.semi_synthetic import SemiSynthetic from input.fully_synthetic import FullySynthetic import numpy as np n_nodes = [1000, 2000, 5000, 10000, 20000] ks = [20,60,100,200,350] for n in n_nodes: for k in ks: #np.random.seed(123) outdir="../dataspace/graph/fully-synthetic/small-world-n{}-k{}-p5-seed123/".format(n, k) FullySynthetic.generate_small_world_graph(outdir,n_nodes=n,k_neighbors=k, p_edge_modify=0.5, feature_dim=16) semiSynthetic = SemiSynthetic(outdir+'/graphsage',outdir+'/random-d01') semiSynthetic.generate_random_clone_synthetic(0, 0.01)
def gen_fully_smallworld(full, n_nodes, p): name_p = str(int(p)) outdir = full+"/small_world-n{}-p{}".format(n_nodes,name_p) FullySynthetic.generate_small_world_graph(outdir, n_nodes, int(p), 0.35) return outdir
check_graphs_labels_distinguish(graphs) while len(graphs) > 1: graph = nx.compose(graphs[0], graphs[1]) graphs = [graph, *graphs[2:]] print("====Large graph====") print(nx.info(graphs[0])) print("Number of connected components:", len(list(nx.connected_components(graphs[0])))) return graphs[0] def get_features_from_graph(graph): features = None if 'feature' in graph.node[graph.nodes()[0]]: features = [] for idx, node in enumerate(graph.nodes()): features.append(graph.node[node]['feature']) features = np.array(features) return features if __name__ == '__main__': args = parse_args() print(args) graph = create_graph(args.n, args.nc, args.feature_dim, args.k, args.p, args.seed) features = get_features_from_graph(graph) FullySynthetic.save_graph(args.output_dir, graph, features)
def gen_fully(n_nodes,p): name_p = str(p).replace("0.","") outdir = full+"/erdos-renyi-n{}-p{}".format(n_nodes,name_p) FullySynthetic.generate_erdos_renyi_graph(outdir,n_nodes=n_nodes,p_edge_creation=p) return outdir