From ac8806e1a3427ae3fed1ee0a4ca3dee98d29d1f1 Mon Sep 17 00:00:00 2001 From: Fize Jacques <jacques.fize@cirad.fr> Date: Wed, 10 Feb 2021 14:14:09 +0100 Subject: [PATCH] Debug Node2vec --- evalNE_script.py | 10 +++++++--- generate_theoric_random_graph.py | 2 +- run_eval.py | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/evalNE_script.py b/evalNE_script.py index 99d70ee..4aa2d08 100644 --- a/evalNE_script.py +++ b/evalNE_script.py @@ -42,11 +42,12 @@ log("Building link prediction dataset...") # Create an evaluator and generate train/test edge split traintest_split = LPEvalSplit() try: - traintest_split.compute_splits(G, split_alg="spanning_tree", train_frac=args.train_frac, fe_ratio=1) + traintest_split.compute_splits(G, split_alg="random", train_frac=args.train_frac, fe_ratio=1) except ValueError: traintest_split.compute_splits(G, split_alg="fast", train_frac=args.train_frac, fe_ratio=1) +print("BEFORE", len(traintest_split.test_edges)) nee = LPEvaluator(traintest_split) - +print("AFTER",len(traintest_split.test_edges)) log("Dataset Built !") # Create a Scoresheet to store the results @@ -93,9 +94,12 @@ if args.network_embedding: pbar = tqdm(enumerate(methods), disable=(not args.verbose)) for i,method in pbar: pbar.set_description("Evaluate "+method) + is_weighted = nx.is_weighted(G) command = commands[i] + " --input {} --output {} --representation-size {}" + if is_weighted: + command = command + " --weighted" results = nee.evaluate_cmd(method_name=methods[i], method_type='ne', command=command, - edge_embedding_methods=edge_emb, input_delim=' ', output_delim=' ', verbose=args.verbose,write_weights=nx.is_weighted(G)) + edge_embedding_methods=edge_emb, input_delim=' ', output_delim=' ', verbose=args.verbose,write_weights=is_weighted) scoresheet.log_results(results) except ImportError: diff --git a/generate_theoric_random_graph.py b/generate_theoric_random_graph.py index 2a3a2ff..d7f5796 100644 --- a/generate_theoric_random_graph.py +++ b/generate_theoric_random_graph.py @@ -18,7 +18,7 @@ args = parser.parse_args() GRAPH_SIZE = [80,800] -EDGE_SIZE = [2,3] +EDGE_SIZE = [2,4,5] sample_per_params = 4 OUTPUT_DIR = args.output_dir diff --git a/run_eval.py b/run_eval.py index 985f55c..121bdcb 100644 --- a/run_eval.py +++ b/run_eval.py @@ -16,6 +16,7 @@ parser.add_argument("dataset_dir") parser.add_argument("output_filename") parser.add_argument("-f", "--format", default="gexf", choices=["gexf", "gml", "txt"]) parser.add_argument("-t","--train-frac",default=0.9,type=float) +parser.add_argument("-v","--verbose",action="store_true") args = parser.parse_args() fns = sorted(glob.glob(args.dataset_dir + "/*." + args.format)) @@ -24,9 +25,9 @@ all_res = [] pbar = tqdm(fns) for fn in pbar: pbar.set_description("run eval on "+ fn) - + verbose_cmd = "-v" if args.v else "" if not os.path.exists(fn + "_results_lp"): - command = "python evalNE_script.py {0} -f {1} -n --train-frac {2}".format(fn, args.format,args.train_frac).split() + command = "python evalNE_script.py {0} -f {1} -n --train-frac {2} {3}".format(fn, args.format,args.train_frac,verbose_cmd).split() output = subprocess.run(command) if not output.returncode == 0: print("Error! for the command :", " ".join(command)) -- GitLab