diff --git a/evalNE_script.py b/evalNE_script.py index 7f29050eadea07598623b40fd70c1d4a2daac370..4449d10d110e9244c98e53e6932fc38b289783c4 100644 --- a/evalNE_script.py +++ b/evalNE_script.py @@ -59,8 +59,8 @@ methods = ['random_prediction', "preferential_attachment", "resource_allocation_index", "stochastic_block_model", - "stochastic_block_model_edge_probs", - "stochastic_block_model_degree_corrected" + "stochastic_block_model_degree_corrected", + "spatial_link_prediction" ] # Evaluate baselines diff --git a/generate_theoric_random_graph.py b/generate_theoric_random_graph.py index 39ec3dc6f76f6dff80e0b767f5b073bee10cc69a..8d6ef8e03167fd96648c2cb14c3db34f2f090342 100644 --- a/generate_theoric_random_graph.py +++ b/generate_theoric_random_graph.py @@ -17,8 +17,9 @@ parser.add_argument("output_dir") args = parser.parse_args() -GRAPH_SIZE = [100,150,200] -EDGE_SIZE = [300,500] +GRAPH_SIZE = [80,800] +EDGE_SIZE = [2,3] + OUTPUT_DIR = args.output_dir if not os.path.exists(OUTPUT_DIR): raise FileExistsError("Output directory does not exists !") @@ -28,7 +29,7 @@ parameters = { "stochastic_block_model_graph": { "nb_nodes":GRAPH_SIZE, "nb_edges":EDGE_SIZE, - "nb_com" :[2,5], + "nb_com" :[2,5,8,16], "percentage_edge_betw":[0.1,0.01] }, "ER_graph": { @@ -38,10 +39,11 @@ parameters = { "powerlaw_graph": { # configuration_model "nb_nodes":GRAPH_SIZE, "nb_edges":EDGE_SIZE, - "exponent":[2,3] + "exponent":[2,3], + "tries":[100] }, "spatial_graph":{ - "nb_nodes":[100,150], + "nb_nodes":GRAPH_SIZE, "nb_edges":EDGE_SIZE, "coords":["random","country"], } @@ -63,11 +65,14 @@ for method,args in pbar: list_of_params = get_params(parameters[method]) func = getattr(ra,method) for ix,params in enumerate(list_of_params): - # try: - G = func(**params) - G.graph.update(params) - nx.write_gml(G, OUTPUT_DIR+"/graph_{method}_{ix}.gml".format(method=method,ix=ix),stringizer=str) - # except Exception as e: - # print(e) + params["nb_edges"] = params["nb_edges"]*params["nb_nodes"] + print(params) + try: + G = func(**params) + G.graph.update(params) + nx.write_gml(G, OUTPUT_DIR+"/graph_{method}_{ix}.gml".format(method=method,ix=ix),stringizer=str) + except Exception as e: + print(e) + print("Can't generate graphs using these parameters") diff --git a/lib/random.py b/lib/random.py index c57df3406a378bdb05d92fe3af86d0194e6f5911..afe6a83960360b138abaf4eac2d22830c387b5c7 100644 --- a/lib/random.py +++ b/lib/random.py @@ -101,7 +101,7 @@ def _conf_model(degree_seq): return G -def powerlaw_graph(nb_nodes, nb_edges, exponent=2, tries=1000, min_deg=1): +def powerlaw_graph(nb_nodes, nb_edges, exponent=2, tries=1000, min_deg=0): """ Generate a graph with a defined number of vertices, edges, and a degree distribution that fit the power law. Using the Molloy-Reed algorithm to @@ -186,7 +186,7 @@ def spatial_graph(nb_nodes, nb_edges, coords="country", dist_func=lambda a, b: n for j in range(nb_nodes): if i == j and not self_link: continue - data.append([i, j, dist_func(coords[i], coords[j])]) + data.append([i, j, 1/(1+(dist_func(coords[i], coords[j])**2))]) df = pd.DataFrame(data, columns="src tar weight".split()).astype({"src": int, "tar": int}) df["hash"] = df.apply(lambda x: "_".join(sorted([str(int(x.src)), str(int(x.tar))])), axis=1) df = df.drop_duplicates(subset="hash") @@ -259,7 +259,7 @@ def stochastic_block_model_graph(nb_nodes, nb_edges, nb_com, percentage_edge_bet percentage_edge_within = 1 - percentage_edge_betw - G = nx.planted_partition_graph(nb_com, int(np.round(nb_nodes / nb_com)), 1, 1) + G = nx.planted_partition_graph(nb_com, nb_nodes//nb_com, 1, 1) if verbose: print(G.size()) diff --git a/run_eval_par.py b/run_eval_par.py index 16e4a1f2faf27bc6cd20d83642b7cf07b20e265c..ba738dce678a1dfabfd21841dfbb17fa3ede79e2 100644 --- a/run_eval_par.py +++ b/run_eval_par.py @@ -21,7 +21,7 @@ args = parser.parse_args() fns = sorted(glob.glob(args.dataset_dir + "/*." + args.format)) def run_eval(fn): - command = "python evalNE_script.py {0} -f {1} -n".format(fn, args.format).split() + command = "python evalNE_script.py {0} -f {1}".format(fn, args.format).split() output = subprocess.run(command) if not output.returncode == 0: print("Error! for the command :", " ".join(command))