From e0fab81979acdb041c3611276677f3e67a356b6f Mon Sep 17 00:00:00 2001 From: Fize Jacques <jacques.fize@cirad.fr> Date: Thu, 4 Feb 2021 14:11:44 +0100 Subject: [PATCH] Debug --- evalNE_script.py | 4 ++-- generate_theoric_random_graph.py | 27 ++++++++++++++++----------- lib/random.py | 6 +++--- run_eval_par.py | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/evalNE_script.py b/evalNE_script.py index 7f29050..4449d10 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 39ec3dc..8d6ef8e 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 c57df34..afe6a83 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 16e4a1f..ba738dc 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)) -- GitLab