From 83df933158a618b1e86e3bdf12deb75a815e1a23 Mon Sep 17 00:00:00 2001 From: Fize Jacques <jacques.fize@cirad.fr> Date: Fri, 1 Jun 2018 08:59:55 +0200 Subject: [PATCH] Update --- config/config.json | 6 +- .../database_graph_viewer.db | Bin .../database_graph_viewerV1.db | Bin .../database_graph_viewerv2.db | Bin data/graph_exp_mar_12/selected.json | 1 - data/graph_exp_may_25/selected.json | 1 + eval.py | 73 +- exp_22_may.sh | 73 + generate_data.py | 2 +- generate_data_csv.py | 2 + generate_selected_document.py | 6 +- generate_transform.py | 11 + gmatch4py/__init__.py | 2 +- gmatch4py/ged/__init__.py | 3 +- gmatch4py/ged/algorithm/edge_edit_dist.py | 2 +- gmatch4py/ged/algorithm/graph_edit_dist.py | 6 +- gmatch4py/ged/graph/__init__.py | 1 + gmatch4py_cython/__init__.py | 1 + gmatch4py_cython/gmatch4py/deltacon.pyx | 34 +- .../ged/algorithm/edge_edit_dist.pyx | 2 +- .../ged/algorithm/graph_edit_dist.pyx | 6 +- .../gmatch4py/ged/approximate_ged.pyx | 20 +- .../ged/bipartite_graph_matching_2.pyx | 49 +- .../gmatch4py/ged/greedy_edit_distance.pyx | 15 +- .../gmatch4py/ged/hausdorff_edit_distance.pyx | 29 +- .../gmatch4py/graph_matching_algorithm.pyx | 37 + gmatch4py_cython/gmatch4py/jaccard.pyx | 20 +- .../gmatch4py/kernels/random_walk_kernel.pyx | 93 + .../kernels/shortest_path_kernel.pyx | 88 + .../gmatch4py/kernels/weisfeiler_lehman.pyx | 143 + .../kernels/weisfeiler_lehman_edge.pyx | 192 + .../kernels/weisfeiler_lehman_geo.pyx | 165 + gmatch4py_cython/gmatch4py/mcs.pyx | 22 +- gmatch4py_cython/setup.py | 3 +- {gmatch4py => gmatch4py_old}/README.md | 0 gmatch4py_old/__init__.py | 1 + .../bag_of_cliques.py | 0 gmatch4py_old/data/source/source1.txt | 36 + {gmatch4py => gmatch4py_old}/deltacon.py | 0 gmatch4py_old/exception/__init__.py | 7 + gmatch4py_old/ged/__init__.py | 1 + gmatch4py_old/ged/algorithm/__init__.py | 0 .../ged/algorithm/abstract_graph_edit_dist.py | 112 + gmatch4py_old/ged/algorithm/edge_edit_dist.py | 29 + .../ged/algorithm/graph_edit_dist.py | 71 + .../ged/approximate_ged.py | 0 .../ged/bipartite_graph_matching_2.py | 0 gmatch4py_old/ged/graph/__init__.py | 0 gmatch4py_old/ged/graph/edge_graph.py | 16 + .../ged/greedy_edit_distance.py | 0 .../ged/hausdorff_edit_distance.py | 0 gmatch4py_old/helpers/__init__.py | 1 + gmatch4py_old/helpers/networkx_parser.py | 148 + {gmatch4py => gmatch4py_old}/jaccard.py | 0 gmatch4py_old/kernels/__init__.py | 1 + gmatch4py_old/kernels/random_walk_kernel.py | 93 + gmatch4py_old/kernels/shortest_path_kernel.py | 88 + gmatch4py_old/kernels/weisfeiler_lehman.py | 136 + .../kernels/weisfeiler_lehman_edge.py | 192 + .../kernels/weisfeiler_lehman_geo.py | 165 + {gmatch4py => gmatch4py_old}/mcs.py | 4 + {gmatch4py => gmatch4py_old}/utils.py | 0 .../vertex_edge_overlap.py | 0 .../vertex_ranking.py | 0 gui_graph_viewer/server.py | 4 +- gui_graph_viewer/templates/index.html | 2 +- helpers/boundary.py | 33 +- helpers/collision_c.pyx | 99 + helpers/collision_with_gazetteer_data.py | 4 +- helpers/gazeteer_helpers.py | 14 + models/str.py | 15 +- nlp/disambiguator/models/__init__.py | 1 + nlp/disambiguator/models/bigram.py | 41 + nlp/disambiguator/most_common.py | 6 +- nlp/disambiguator/wikipedia_cooc.py | 45 + notebooks/Cython Enhancement on HED.ipynb | 3332 +++++++-- notebooks/Eval_mada_light_30_mars.ipynb | 6514 +---------------- notebooks/MadaMada.ipynb | 8 +- notebooks/WorthItEval.ipynb | 2 +- pipeline.py | 7 +- setup.py | 7 + temp.py | 181 - 82 files changed, 4887 insertions(+), 7637 deletions(-) rename data/graph_exp_fev_18/{result_eval => result_eval_backup}/database_graph_viewer.db (100%) rename data/graph_exp_fev_18/{result_eval => result_eval_backup}/database_graph_viewerV1.db (100%) rename data/graph_exp_fev_18/{result_eval => result_eval_backup}/database_graph_viewerv2.db (100%) delete mode 100644 data/graph_exp_mar_12/selected.json create mode 100644 data/graph_exp_may_25/selected.json create mode 100755 exp_22_may.sh create mode 100644 gmatch4py_cython/__init__.py create mode 100644 gmatch4py_cython/gmatch4py/graph_matching_algorithm.pyx create mode 100644 gmatch4py_cython/gmatch4py/kernels/random_walk_kernel.pyx create mode 100644 gmatch4py_cython/gmatch4py/kernels/shortest_path_kernel.pyx create mode 100644 gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman.pyx create mode 100644 gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman_edge.pyx create mode 100644 gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman_geo.pyx rename {gmatch4py => gmatch4py_old}/README.md (100%) create mode 100644 gmatch4py_old/__init__.py rename {gmatch4py => gmatch4py_old}/bag_of_cliques.py (100%) create mode 100644 gmatch4py_old/data/source/source1.txt rename {gmatch4py => gmatch4py_old}/deltacon.py (100%) create mode 100644 gmatch4py_old/exception/__init__.py create mode 100644 gmatch4py_old/ged/__init__.py create mode 100644 gmatch4py_old/ged/algorithm/__init__.py create mode 100644 gmatch4py_old/ged/algorithm/abstract_graph_edit_dist.py create mode 100644 gmatch4py_old/ged/algorithm/edge_edit_dist.py create mode 100644 gmatch4py_old/ged/algorithm/graph_edit_dist.py rename gmatch4py_cython/ged/approximate_ged.pyx => gmatch4py_old/ged/approximate_ged.py (100%) rename gmatch4py_cython/ged/bipartite_graph_matching_2.pyx => gmatch4py_old/ged/bipartite_graph_matching_2.py (100%) create mode 100644 gmatch4py_old/ged/graph/__init__.py create mode 100644 gmatch4py_old/ged/graph/edge_graph.py rename gmatch4py_cython/ged/greedy_edit_distance.pyx => gmatch4py_old/ged/greedy_edit_distance.py (100%) rename gmatch4py_cython/ged/hausdorff_edit_distance.pyx => gmatch4py_old/ged/hausdorff_edit_distance.py (100%) create mode 100644 gmatch4py_old/helpers/__init__.py create mode 100644 gmatch4py_old/helpers/networkx_parser.py rename {gmatch4py => gmatch4py_old}/jaccard.py (100%) create mode 100644 gmatch4py_old/kernels/__init__.py create mode 100644 gmatch4py_old/kernels/random_walk_kernel.py create mode 100644 gmatch4py_old/kernels/shortest_path_kernel.py create mode 100644 gmatch4py_old/kernels/weisfeiler_lehman.py create mode 100644 gmatch4py_old/kernels/weisfeiler_lehman_edge.py create mode 100644 gmatch4py_old/kernels/weisfeiler_lehman_geo.py rename {gmatch4py => gmatch4py_old}/mcs.py (90%) rename {gmatch4py => gmatch4py_old}/utils.py (100%) rename {gmatch4py => gmatch4py_old}/vertex_edge_overlap.py (100%) rename {gmatch4py => gmatch4py_old}/vertex_ranking.py (100%) create mode 100644 helpers/collision_c.pyx create mode 100644 nlp/disambiguator/models/__init__.py create mode 100644 nlp/disambiguator/models/bigram.py create mode 100644 nlp/disambiguator/wikipedia_cooc.py create mode 100644 setup.py delete mode 100644 temp.py diff --git a/config/config.json b/config/config.json index 05d4ed8..eefac00 100644 --- a/config/config.json +++ b/config/config.json @@ -6,5 +6,9 @@ "es_server_old":"http://192.168.1.15:9200/", "es_server":"http://localhost:9200/", "database_json":"resources/database_exp_12_mars.db", - "log_file":"extract_log" + "log_file":"extract_log", + "wiki_cooc_dis":{ + "cooc_freq":"/Users/jacquesfize/nas_cloud/Code/str-python/resources/coocurrence_wiki.pkl", + "count":"/Users/jacquesfize/nas_cloud/Code/str-python/resources/count_wiki.pkl" + } } \ No newline at end of file diff --git a/data/graph_exp_fev_18/result_eval/database_graph_viewer.db b/data/graph_exp_fev_18/result_eval_backup/database_graph_viewer.db similarity index 100% rename from data/graph_exp_fev_18/result_eval/database_graph_viewer.db rename to data/graph_exp_fev_18/result_eval_backup/database_graph_viewer.db diff --git a/data/graph_exp_fev_18/result_eval/database_graph_viewerV1.db b/data/graph_exp_fev_18/result_eval_backup/database_graph_viewerV1.db similarity index 100% rename from data/graph_exp_fev_18/result_eval/database_graph_viewerV1.db rename to data/graph_exp_fev_18/result_eval_backup/database_graph_viewerV1.db diff --git a/data/graph_exp_fev_18/result_eval/database_graph_viewerv2.db b/data/graph_exp_fev_18/result_eval_backup/database_graph_viewerv2.db similarity index 100% rename from data/graph_exp_fev_18/result_eval/database_graph_viewerv2.db rename to data/graph_exp_fev_18/result_eval_backup/database_graph_viewerv2.db diff --git a/data/graph_exp_mar_12/selected.json b/data/graph_exp_mar_12/selected.json deleted file mode 100644 index 9981086..0000000 --- a/data/graph_exp_mar_12/selected.json +++ /dev/null @@ -1 +0,0 @@ -[3, 5, 6, 7, 8, 10, 11, 13, 14, 17, 19, 20, 23, 25, 26, 28, 29, 32, 34, 35, 39, 40, 41, 42, 43, 44, 50, 53, 57, 58, 61, 62, 63, 68, 70, 74, 80, 81, 82, 93, 94, 100, 101, 103, 113, 114, 115, 116, 122, 131, 133, 135, 140, 141, 142, 144, 151, 153, 154, 162, 198, 205, 207, 213, 218, 224, 226, 231, 234, 236, 243, 245, 246, 247, 248, 249, 252, 253, 256, 258, 259, 262, 264, 267, 270, 273, 275, 279, 280, 282, 283, 286, 287, 291, 328, 329, 330, 332, 340, 341] diff --git a/data/graph_exp_may_25/selected.json b/data/graph_exp_may_25/selected.json new file mode 100644 index 0000000..dc133d2 --- /dev/null +++ b/data/graph_exp_may_25/selected.json @@ -0,0 +1 @@ +[254, 566, 594, 642, 877, 887, 988, 1072, 1210, 1308, 1315, 1335, 1356, 1416, 1548, 1571, 1587, 1683, 1685, 1958, 1960, 1961, 1968, 2034, 2047, 2182, 2194, 2345, 2422, 2528, 2560, 2734, 3306, 3606, 3682, 3718, 3864, 4092, 4119, 4392, 4432, 4789, 5020, 5244, 5704, 5847, 5967, 6031, 6265, 6815, 6922, 7261, 7285, 7303, 7394, 7441, 7498, 7546, 7564, 7570, 7573, 7772, 7776, 9138, 12078, 12216, 12270, 12462, 12813, 12871, 12918, 13009, 13068, 13223, 13408, 13695, 13708, 13727, 13771, 13937, 14179, 14218, 14250, 14295, 14346, 14417, 14507, 14615, 14731, 14748, 14899, 14938, 15008, 15154, 15224, 15236, 15435, 15534, 15628, 15633] \ No newline at end of file diff --git a/eval.py b/eval.py index d63d09f..48b8e81 100644 --- a/eval.py +++ b/eval.py @@ -8,7 +8,7 @@ import time from progressbar import ProgressBar, Timer, Bar, ETA from gmatch4py.bag_of_cliques import BagOfCliques -from gmatch4py.exception import NotFoundDistance +from gmatch4py_old.exception import NotFoundDistance from gmatch4py.ged.approximate_ged import ApproximateGraphEditDistance from gmatch4py.ged.bipartite_graph_matching_2 import BP_2 from gmatch4py.ged.greedy_edit_distance import GreedyEditDistance @@ -62,35 +62,35 @@ def getEdges4Draw(data,edges): # Similarity Function between graph and a set of graphs -def compareMCS(graphs): - return 1-MCS.compare(graphs) +def compareMCS(graphs,selected): + return 1-MCS.compare(graphs,selected) # GED algorithm -def compareGED(graphs): - return ApproximateGraphEditDistance.compare(graphs) +def compareGED(graphs,selected): + return ApproximateGraphEditDistance.compare(graphs,selected) -def compareBP2(graphs): - return BP_2.compare(graphs) +def compareBP2(graphs,selected): + return BP_2.compare(graphs,selected) -def compareHED(graphs): - return HED.compare(graphs) +def compareHED(graphs,selected): + return HED.compare(graphs,selected) -def compareGreedy(graphs): - return GreedyEditDistance.compare(graphs) +def compareGreedy(graphs,selected): + return GreedyEditDistance.compare(graphs,selected) -def compareWLSubTreeKernel(graphs): - return 1 - WeisfeleirLehmanKernel.compare(graphs,h=3) +def compareWLSubTreeKernel(graphs,selected): + return 1 - WeisfeleirLehmanKernel.compare(graphs,selected,h=3) -def compareBOWSE(graphs): - return 1-BOWSE.compare(graphs) +def compareBOWSE(graphs,selected): + return 1-BOWSE.compare(graphs,selected) -def compareBOC(graphs_array): - return 1 - BagOfCliques.compare(graphs_array) +def compareBOC(graphs_array,selected): + return 1 - BagOfCliques.compare(graphs_array,selected) -def compareVEO(graphs_array): - return 1 - VertexEdgeOverlap.compare(graphs_array) +def compareVEO(graphs_array,selected): + return 1 - VertexEdgeOverlap.compare(graphs_array,selected) -def compareJaccard(graphs_array): - return 1 - Jaccard.compare(graphs_array) +def compareJaccard(graphs_array,selected): + return 1 - Jaccard.compare(graphs_array,selected) funcDict={ "MCS":compareMCS, @@ -191,7 +191,7 @@ final_data={} deb=time.time() print("Computing Similarity Matrix ...") -similarity_matrix = funcDict[args.distance](graphs_array) +similarity_matrix = funcDict[args.distance](graphs_array,selected_documents_) print("Similarity Matrix Computed in {0} s.".format(time.time()-deb)) graphs={} @@ -199,31 +199,38 @@ for file in glob.glob(original_dir.rstrip("/")+"/*.gexf"): id=int(re.findall("\d+",file)[-1]) graphs[id]=nx.read_gexf(file) + + +nn_ = 5 + with ProgressBar(max_value=len(selected_documents_),widgets=[' [', Timer(), '] ',Bar(),' (', ETA(), ') ',]) as pg: inc=0 for doc_s in selected_documents_: if not len(graphs[doc_s])>0: continue - id_json=str(doc_s) bow_score=similarity_matrix[doc_s] - top_10_docs_score=np.sort(bow_score)[1:11].astype(float) - top_10_docs=np.argsort(bow_score)[1:11].astype(int) + top_docs_score = np.sort(bow_score).astype(float) + top_docs = np.argsort(bow_score).astype(int) final_data[doc_s]={ "sp_entities":get_associated_es(graphs[doc_s].nodes()), "text":texts[doc_s], } - final_data[doc_s]["edges"]=getEdges4Draw(final_data[doc_s]["sp_entities"],graphs[doc_s].edges(data=True)) - #print(final_data[doc_s]["edges"]) - final_data[doc_s]["top_10"]=[] - for d in range(len(top_10_docs)): + final_data[doc_s]["edges"] = getEdges4Draw(final_data[doc_s]["sp_entities"],graphs[doc_s].edges(data=True)) + final_data[doc_s]["topk"] = [] + n_top_docs = len(top_docs) + for d in range(n_top_docs): + if not top_docs[d] in graphs or top_docs[d] == doc_s: + continue + if len(final_data[doc_s]["topk"]) == nn_: + break doc_data={} - doc_data["score"]=top_10_docs_score[d] - doc_data["id_txt"]=int(top_10_docs[d]) - doc_data["text"]=texts[int(top_10_docs[d])] + doc_data["score"]=top_docs_score[d] + doc_data["id_txt"]=int(top_docs[d]) + doc_data["text"]=""#texts[int(top_10_docs[d])] doc_data["sp_entities"]=get_associated_es(graphs[doc_data["id_txt"]].nodes()) doc_data["edges"]=getEdges4Draw(doc_data["sp_entities"],graphs[doc_data["id_txt"]].edges(data=True)) doc_data["relevant"]=None - final_data[doc_s]["top_10"].append(doc_data) + final_data[doc_s]["topk"].append(doc_data) inc+=1 pg.update(inc) diff --git a/exp_22_may.sh b/exp_22_may.sh new file mode 100755 index 0000000..ae037f3 --- /dev/null +++ b/exp_22_may.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +path_csv=/Users/jacquesfize/LOD_DATASETS/disambiguation +output_dir=data/graph_exp_may_25 +if [ "$1" == "generate" ]; then + + mkdir -p $output_dir/normal + #python3 generate_data_csv.py $path_csv $output_dir/normal asso.json normal; + + python3 generate_transform.py $output_dir/normal $output_dir/extension_1 extension -a 1; + python3 generate_transform.py $output_dir/normal $output_dir/extension_2 extension -a 2; + #python3 generate_transform.py $output_dir/normal $output_dir/extension_3 extension -a 3; + + #python3 generate_transform.py $output_dir/normal $output_dir/gen_all_1 generalisation -t all -n 1; + #python3 generate_transform.py $output_dir/normal $output_dir/gen_all_2 generalisation -t all -n 2; + + + python3 generate_transform.py $output_dir/normal $output_dir/gen_region generalisation -t bounded -b region; + #python3 generate_transform.py $output_dir/normal $output_dir/gen_capital generalisation -t bounded -b capital; + python3 generate_transform.py $output_dir/normal $output_dir/gen_country generalisation -t bounded -b country; +fi + +if [ "$1" == "eval" ]; then + ## Normal STR eval + original=data/graph_exp_may_24/normal + dir=normal; + mesure=("MCS" "VEO" "JACCARD" "HED" "GREEDY" "GED" "BOC" "BOWSE"); + for me in ${mesure[@]}; do + echo $me" for STR "$dir; + python3 eval.py "$me" "$path_texts" "$output_dir/$dir" "$output_dir/$dir/asso.json" "$original" -s "$output_dir/selected.json" -o "$output_dir/result_eval/$dir/"; + done; + + ## Generalised STR eval + dir=gen_all_1 + mesure=( "MCS" "VEO" "JACCARD" "HED" "GREEDY" "GED" "BOC" "BOWSE"); + for me in ${mesure[@]}; do + echo $me" for STR "$dir; + python3 eval.py $me $path_texts $output_dir/$dir $output_dir/$dir/asso.json $original -s $output_dir/selected.json -o $output_dir/result_eval/$dir/; + done; + +# dir=gen_all_2 +# mesure=( "MCS" "VEO" "JACCARD" "HED" "GREEDY" "BOC" "BOWSE"); +# for me in ${mesure[@]}; do +# echo $me" for STR "$dir; +# python3 eval.py $me $path_texts $output_dir/$dir $output_dir/$dir/asso.json $original -s $output_dir/selected.json -o $output_dir/result_eval/$dir/; +# done; + + dir=gen_region + for me in ${mesure[@]}; do + echo $me" for STR "$dir; + python3 eval.py $me $path_texts $output_dir/$dir $output_dir/$dir/asso.json $original -s $output_dir/selected.json -o $output_dir/result_eval/$dir/; + done; + + dir=gen_country + for me in ${mesure[@]}; do + echo $me" for STR "$dir; + python3 eval.py $me $path_texts $output_dir/$dir $output_dir/$dir/asso.json $original -s $output_dir/selected.json -o $output_dir/result_eval/$dir/; + done; + + ## Extended STR eval + dir=extension_1 + mesure=( "MCS" "VEO" "JACCARD" "BOC" "WLSUBTREE" "BOWSE"); + for me in ${mesure[@]}; do + echo $me" for STR "$dir; + python3 eval.py $me $path_texts $output_dir/$dir $output_dir/$dir/asso.json $original -s $output_dir/selected.json -o $output_dir/result_eval/$dir/; + done; + dir=extension_2 + + for me in ${mesure[@]}; do + echo $me" for STR "$dir; + python3 eval.py $me $path_texts $output_dir/$dir $output_dir/$dir/asso.json $original -s $output_dir/selected.json -o $output_dir/result_eval/$dir/; + done; +fi \ No newline at end of file diff --git a/generate_data.py b/generate_data.py index 3bc1a7b..b996601 100644 --- a/generate_data.py +++ b/generate_data.py @@ -177,7 +177,7 @@ with ThreadPoolExecutor(max_workers=4) as executor: pg.start() for lang in data: for id_doc in data[lang]: - future = executor.submit(workSTR,id_doc,texts_[id_doc],count_per_doc,associated_es, list_gs,pg,lang) + workSTR(id_doc,texts_[id_doc],count_per_doc,associated_es, list_gs,pg,lang) # print(id_doc) # if not texts_[id_doc]: # count_per_doc[id_doc] = {} diff --git a/generate_data_csv.py b/generate_data_csv.py index fffe0ff..5341d67 100644 --- a/generate_data_csv.py +++ b/generate_data_csv.py @@ -112,6 +112,7 @@ with ProgressBar(max_value=len(files_glob), id_ = int(re.findall("\d+", fn)[-1]) df = pd.read_csv(fn) # try: + df= df.fillna("O") df= df[-df["GID"].isin(['0','o','NR','O'])] #print(df) # except: @@ -124,6 +125,7 @@ with ProgressBar(max_value=len(files_glob), i+=1 pg.update(i) + # Save Metadata open(os.path.join(args.graphs_output_dir,args.metadata_output_fn),'w').write(json.dumps([associated_es,count_per_doc],indent=4)) diff --git a/generate_selected_document.py b/generate_selected_document.py index 531637e..cf95831 100644 --- a/generate_selected_document.py +++ b/generate_selected_document.py @@ -21,11 +21,11 @@ if median <=2: median=int(np.mean([len(g) for g in graphs.values()])) cat_interval=[ - [1,2], - [2,median], + [1,median], + [median,median*2], [median,1000000] ] - +print("Interval",cat_interval) size_selection=100 cat_size=[ size_selection/5, diff --git a/generate_transform.py b/generate_transform.py index 13750da..3a30c38 100644 --- a/generate_transform.py +++ b/generate_transform.py @@ -3,11 +3,13 @@ # coding = utf-8 import argparse import glob +import logging import time from concurrent.futures import ThreadPoolExecutor from progressbar import ProgressBar, Timer, Bar, ETA, Counter +from helpers.boundary import get_all_shapes from nlp.disambiguator.geodict_gaurav import * from pipeline import * @@ -83,7 +85,16 @@ if not graphs_: list_gs=[] i=0 +all_es=set([]) +for k,v in associated_es.items(): + for k2 in v: + all_es.add(k2) +logging.info("Get All Shapes from Database for all ES") +all_shapes=get_all_shapes(list(all_es)) + +for id_ in graphs_: + graphs_[id].set_all_shapes(all_shapes) def workSTR(id_doc,g,list_gs,pg,argu): global i diff --git a/gmatch4py/__init__.py b/gmatch4py/__init__.py index a4e2017..950f635 100644 --- a/gmatch4py/__init__.py +++ b/gmatch4py/__init__.py @@ -1 +1 @@ -__version__ = "0.1" +# coding = utf-8 \ No newline at end of file diff --git a/gmatch4py/ged/__init__.py b/gmatch4py/ged/__init__.py index 950f635..e5c6c3c 100644 --- a/gmatch4py/ged/__init__.py +++ b/gmatch4py/ged/__init__.py @@ -1 +1,2 @@ -# coding = utf-8 \ No newline at end of file +# coding = utf-8 + diff --git a/gmatch4py/ged/algorithm/edge_edit_dist.py b/gmatch4py/ged/algorithm/edge_edit_dist.py index 684dc09..74ef2e9 100644 --- a/gmatch4py/ged/algorithm/edge_edit_dist.py +++ b/gmatch4py/ged/algorithm/edge_edit_dist.py @@ -1,6 +1,6 @@ import sys -from gmatch4py.ged.algorithm.abstract_graph_edit_dist import AbstractGraphEditDistance +from gmatch4py_old.ged.algorithm.abstract_graph_edit_dist import AbstractGraphEditDistance class EdgeEditDistance(AbstractGraphEditDistance): diff --git a/gmatch4py/ged/algorithm/graph_edit_dist.py b/gmatch4py/ged/algorithm/graph_edit_dist.py index 2c23758..210e15e 100644 --- a/gmatch4py/ged/algorithm/graph_edit_dist.py +++ b/gmatch4py/ged/algorithm/graph_edit_dist.py @@ -4,9 +4,9 @@ import sys import networkx as nx -from gmatch4py.ged.algorithm.abstract_graph_edit_dist import AbstractGraphEditDistance -from gmatch4py.ged.algorithm.edge_edit_dist import EdgeEditDistance -from gmatch4py.ged.graph.edge_graph import EdgeGraph +from gmatch4py_old.ged.algorithm.abstract_graph_edit_dist import AbstractGraphEditDistance +from gmatch4py_old.ged.algorithm.edge_edit_dist import EdgeEditDistance +from gmatch4py_old.ged.graph.edge_graph import EdgeGraph def compare(g1, g2, print_details=False): diff --git a/gmatch4py/ged/graph/__init__.py b/gmatch4py/ged/graph/__init__.py index e69de29..950f635 100644 --- a/gmatch4py/ged/graph/__init__.py +++ b/gmatch4py/ged/graph/__init__.py @@ -0,0 +1 @@ +# coding = utf-8 \ No newline at end of file diff --git a/gmatch4py_cython/__init__.py b/gmatch4py_cython/__init__.py new file mode 100644 index 0000000..950f635 --- /dev/null +++ b/gmatch4py_cython/__init__.py @@ -0,0 +1 @@ +# coding = utf-8 \ No newline at end of file diff --git a/gmatch4py_cython/gmatch4py/deltacon.pyx b/gmatch4py_cython/gmatch4py/deltacon.pyx index 42244b8..6749994 100644 --- a/gmatch4py_cython/gmatch4py/deltacon.pyx +++ b/gmatch4py_cython/gmatch4py/deltacon.pyx @@ -9,27 +9,39 @@ class DeltaCon0(): __type__ = "sim" @staticmethod - def compare(list_gs): + def compare(list_gs,selected): n=len(list_gs) comparison_matrix = np.zeros((n,n)) for i in range(n): for j in range(i,n): g1,g2=list_gs[i],list_gs[j] + f=True + if not list_gs[i] or not list_gs[j]: + f=False + elif len(list_gs[i])== 0 or len(list_gs[j]) == 0: + f=False + if selected: + if not i in selected: + f=False + if f: + # S1 + epsilon = 1/(1+DeltaCon0.maxDegree(g1)) + D, A = DeltaCon0.degreeAndAdjacencyMatrix(g1) + S1 = np.linalg.inv(np.identity(len(g1))+(epsilon**2)*D -epsilon*A) - # S1 - epsilon = 1/(1+DeltaCon0.maxDegree(g1)) - D, A = DeltaCon0.degreeAndAdjacencyMatrix(g1) - S1 = np.linalg.inv(np.identity(len(g1))+(epsilon**2)*D -epsilon*A) + # S2 + D, A = DeltaCon0.degreeAndAdjacencyMatrix(g2) + epsilon = 1 / (1 + DeltaCon0.maxDegree(g2)) + S2 = np.linalg.inv(np.identity(len(g2))+(epsilon**2)*D -epsilon*A) - # S2 - D, A = DeltaCon0.degreeAndAdjacencyMatrix(g2) - epsilon = 1 / (1 + DeltaCon0.maxDegree(g2)) - S2 = np.linalg.inv(np.identity(len(g2))+(epsilon**2)*D -epsilon*A) + comparison_matrix[i,j] = 1/(1+DeltaCon0.rootED(S1,S2)) + comparison_matrix[j,i] = comparison_matrix[i,j] + else: + comparison_matrix[i, j] = 0. + comparison_matrix[j, i] = comparison_matrix[i, j] - comparison_matrix[i,j] = 1/(1+DeltaCon0.rootED(S1,S2)) - comparison_matrix[j,i] = comparison_matrix[i,j] return comparison_matrix diff --git a/gmatch4py_cython/gmatch4py/ged/algorithm/edge_edit_dist.pyx b/gmatch4py_cython/gmatch4py/ged/algorithm/edge_edit_dist.pyx index 80f24e7..6f0c587 100644 --- a/gmatch4py_cython/gmatch4py/ged/algorithm/edge_edit_dist.pyx +++ b/gmatch4py_cython/gmatch4py/ged/algorithm/edge_edit_dist.pyx @@ -1,6 +1,6 @@ import sys -from gmatch4py.ged.algorithm.abstract_graph_edit_dist import AbstractGraphEditDistance +from gmatch4py_old.ged.algorithm.abstract_graph_edit_dist import AbstractGraphEditDistance class EdgeEditDistance(AbstractGraphEditDistance): diff --git a/gmatch4py_cython/gmatch4py/ged/algorithm/graph_edit_dist.pyx b/gmatch4py_cython/gmatch4py/ged/algorithm/graph_edit_dist.pyx index cc38d08..1dcd1e9 100644 --- a/gmatch4py_cython/gmatch4py/ged/algorithm/graph_edit_dist.pyx +++ b/gmatch4py_cython/gmatch4py/ged/algorithm/graph_edit_dist.pyx @@ -4,9 +4,9 @@ import sys import networkx as nx -from gmatch4py.ged.algorithm.abstract_graph_edit_dist import AbstractGraphEditDistance -from gmatch4py.ged.algorithm.edge_edit_dist import EdgeEditDistance -from gmatch4py.ged.graph.edge_graph import EdgeGraph +from gmatch4py_old.ged.algorithm.abstract_graph_edit_dist import AbstractGraphEditDistance +from gmatch4py_old.ged.algorithm.edge_edit_dist import EdgeEditDistance +from gmatch4py_old.ged.graph.edge_graph import EdgeGraph def compare(g1, g2, print_details=False): diff --git a/gmatch4py_cython/gmatch4py/ged/approximate_ged.pyx b/gmatch4py_cython/gmatch4py/ged/approximate_ged.pyx index d77f522..5a50e9e 100644 --- a/gmatch4py_cython/gmatch4py/ged/approximate_ged.pyx +++ b/gmatch4py_cython/gmatch4py/ged/approximate_ged.pyx @@ -9,12 +9,22 @@ class ApproximateGraphEditDistance(): __type__ = "dist" @staticmethod - def compare(listgs,c_del_node=1,c_del_edge=1,c_ins_node=1,c_ins_edge=1): - n= len(listgs) + def compare(listgs,selected,c_del_node=1,c_del_edge=1,c_ins_node=1,c_ins_edge=1): + cdef int n= len(listgs) comparison_matrix = np.zeros((n,n)) for i in range(n): for j in range(i,n): - comparison_matrix[i,j]= GraphEditDistance(listgs[i],listgs[j],False,node_del=c_del_node,node_ins=c_ins_node,edge_del=c_del_edge,edge_ins=c_ins_edge).distance() - comparison_matrix[j,i]= comparison_matrix[i,j] # Unethical ! Since AGED is not a symmetric similarity measure ! - + f=True + if not listgs[i] or not listgs[j]: + f=False + elif len(listgs[i])== 0 or len(listgs[j]) == 0: + f=False + if selected: + if not i in selected: + f=False + if f: + comparison_matrix[i, j] = GraphEditDistance(listgs[i],listgs[j],False,node_del=c_del_node,node_ins=c_ins_node,edge_del=c_del_edge,edge_ins=c_ins_edge).distance() + else: + comparison_matrix[i, j] = 0. + comparison_matrix[j, i] = comparison_matrix[i, j] return comparison_matrix \ No newline at end of file diff --git a/gmatch4py_cython/gmatch4py/ged/bipartite_graph_matching_2.pyx b/gmatch4py_cython/gmatch4py/ged/bipartite_graph_matching_2.pyx index a09627a..772f73a 100644 --- a/gmatch4py_cython/gmatch4py/ged/bipartite_graph_matching_2.pyx +++ b/gmatch4py_cython/gmatch4py/ged/bipartite_graph_matching_2.pyx @@ -14,13 +14,24 @@ cdef class BP_2(): cdef int edge_ins @staticmethod - def compare(listgs, c_del_node=1, c_del_edge=1, c_ins_node=1, c_ins_edge=1): + def compare(listgs,selected, c_del_node=1, c_del_edge=1, c_ins_node=1, c_ins_edge=1): cdef int n = len(listgs) comparator = BP_2(c_del_node, c_ins_node, c_del_edge, c_ins_edge) cdef np.ndarray comparison_matrix = np.zeros((n, n)) for i in range(n): for j in range(i, n): - comparison_matrix[i, j] = comparator.bp2(listgs[i], listgs[j]) + f=True + if not listgs[i] or not listgs[j]: + f=False + elif len(listgs[i])== 0 or len(listgs[j]) == 0: + f=False + if selected: + if not i in selected: + f=False + if f: + comparison_matrix[i, j] = comparator.bp2(listgs[i], listgs[j]) + else: + comparison_matrix[i, j] = 0. comparison_matrix[j, i] = comparison_matrix[i, j] return comparison_matrix @@ -39,12 +50,12 @@ cdef class BP_2(): :param g2: second graph :return: """ - return min(self.distance(self.psi(g1,g2)),self.distance(self.psi(g2,g1))) + return np.min(self.distance(self.psi(g1,g2)),self.distance(self.psi(g2,g1))) def distance(self,e): return np.sum(e) - def psi(self,g1,g2): + cdef list psi(self,g1,g2): cdef list psi_=[] cdef list nodes1 = g1.nodes() cdef list nodes2 = g2.nodes() @@ -64,7 +75,7 @@ cdef class BP_2(): return psi_ - def fuv(self, g1, g2, n1, n2): + cdef float fuv(self, g1, g2, n1, n2): """ Compute the Node Distance function :param g1: first graph @@ -82,7 +93,7 @@ cdef class BP_2(): return 0. return (self.node_del + self.node_ins + self.hed_edge(g1, g2, n1, n2)) / 2 - def hed_edge(self, g1, g2, n1, n2): + cdef float hed_edge(self, g1, g2, n1, n2): """ Compute HEDistance between edges of n1 and n2, respectively in g1 and g2 :param g1: first graph @@ -93,20 +104,26 @@ cdef class BP_2(): """ return self.sum_gpq(g1, n1, g2, n2) + self.sum_gpq(g1, n1, g2, n2) - def get_edge_multigraph(self, g, node): + cdef list get_edge_multigraph(self, g, node): """ Get list of edge around a node in a Multigraph :param g: multigraph :param node: node in the multigraph :return: """ - edges = [] - for edge in g.edges(data=True): - if node == edge[0] or node == edge[1]: - edges.append("{0}-{1}-{2}".format(edge[0],edge[1],edge[2]["color"])) + + cdef list originals_ = g.edges(node, data=True) + cdef int n= len(originals_) + if n == 0: + return [] + + cdef list edges = [""]*n + for i in range(n): + edge=originals_[i] + edges[i]=("{0}-{1}".format(edge[0],edge[1])) return edges - def sum_gpq(self, g1, n1, g2, n2): + cdef float sum_gpq(self, g1, n1, g2, n2): """ Compute Nearest Neighbour Distance between edges around n1 in G1 and edges around n2 in G2 :param g1: first graph @@ -115,14 +132,8 @@ cdef class BP_2(): :param n2: node in the second graph :return: """ - - #if isinstance(g1, nx.MultiDiGraph): cdef list edges1 = self.get_edge_multigraph(g1, n1) cdef list edges2 = self.get_edge_multigraph(g2, n2) - #else: - #print(1) - #edges1 = [str(n1 + "-" + ef) for ef in list(g1.edge[n1].keys())] - #edges2 = [str(n2 + "-" + ef) for ef in list(g2.edge[n2].keys())] edges2.extend([None]) cdef np.ndarray min_sum = np.zeros(len(edges1)) for i in range(len(edges1)): @@ -132,7 +143,7 @@ cdef class BP_2(): min_sum[i] = np.min(min_i) return np.sum(min_sum) - def gpq(self, e1, e2): + cdef float gpq(self, e1, e2): """ Compute the edge distance function :param e1: edge1 diff --git a/gmatch4py_cython/gmatch4py/ged/greedy_edit_distance.pyx b/gmatch4py_cython/gmatch4py/ged/greedy_edit_distance.pyx index 96478dd..b297bea 100644 --- a/gmatch4py_cython/gmatch4py/ged/greedy_edit_distance.pyx +++ b/gmatch4py_cython/gmatch4py/ged/greedy_edit_distance.pyx @@ -14,14 +14,25 @@ class GreedyEditDistance(GraphEditDistance): """ __type__ = "dist" @staticmethod - def compare(listgs, c_del_node=1, c_del_edge=1, c_ins_node=1, c_ins_edge=1): + def compare(listgs, selected, c_del_node=1, c_del_edge=1, c_ins_node=1, c_ins_edge=1): cdef int n = len(listgs) cdef np.ndarray comparison_matrix = np.zeros((n, n)) for i in range(n): for j in range(i, n): - comparison_matrix[i, j] = GreedyEditDistance(listgs[i], listgs[j],False, node_del=c_del_node, + f=True + if not listgs[i] or not listgs[j]: + f=False + elif len(listgs[i])== 0 or len(listgs[j]) == 0: + f=False + if selected: + if not i in selected: + f=False + if f: + comparison_matrix[i, j] = GreedyEditDistance(listgs[i], listgs[j],False, node_del=c_del_node, node_ins=c_ins_node, edge_del=c_del_edge, edge_ins=c_ins_edge).distance() + else: + comparison_matrix[i, j] = 0. comparison_matrix[j, i] = comparison_matrix[i, j] diff --git a/gmatch4py_cython/gmatch4py/ged/hausdorff_edit_distance.pyx b/gmatch4py_cython/gmatch4py/ged/hausdorff_edit_distance.pyx index 11eb6c5..a3abc77 100644 --- a/gmatch4py_cython/gmatch4py/ged/hausdorff_edit_distance.pyx +++ b/gmatch4py_cython/gmatch4py/ged/hausdorff_edit_distance.pyx @@ -1,8 +1,8 @@ # coding = utf-8 - import numpy as np cimport numpy as np +#from libcpp.list cimport list as cpplist cdef class HED: """ Implementation of Hausdorff Edit Distance described in @@ -19,12 +19,17 @@ cdef class HED: __type__ = "dist" @staticmethod - def compare(list listgs, int c_del_node=1, int c_del_edge=1, int c_ins_node=1, int c_ins_edge=1): + def compare(list listgs, selected, int c_del_node=1, int c_del_edge=1, int c_ins_node=1, int c_ins_edge=1): cdef int n = len(listgs) comparator = HED(c_del_node, c_ins_node, c_del_edge, c_ins_edge) cdef np.ndarray comparison_matrix = np.zeros((n, n)) for i in range(n): for j in range(i, n): + if not listgs[i] or not listgs[j]: + continue + if selected: + if not i in selected: + continue comparison_matrix[i, j] = comparator.hed(listgs[i], listgs[j]) comparison_matrix[j, i] = comparison_matrix[i, j] @@ -102,13 +107,17 @@ cdef class HED: :param node: node in the multigraph :return: """ - cdef list edges = [] - for edge in g.edges(data=True): - if node == edge[0] or node == edge[1]: - try: - edges.append("{0}-{1}-{2}".format(edge[0],edge[1],edge[2]["color"])) - except: - edges.append("{0}-{1}".format(edge[0],edge[1])) + + cdef list originals_ = g.edges(node, data=True) + cdef int n= len(originals_) + if n == 0: + return [] + + + cdef list edges = [""]*n + for i in range(n): + edge=originals_[i] + edges[i]=("{0}-{1}".format(edge[0],edge[1])) return edges cdef float sum_gpq(self, g1, n1, g2, n2): @@ -153,4 +162,4 @@ cdef class HED: else: if e1 == e2: return 0 - return (self.edge_del + self.edge_ins) / 2 \ No newline at end of file + return (self.edge_del + self.edge_ins) / 2 diff --git a/gmatch4py_cython/gmatch4py/graph_matching_algorithm.pyx b/gmatch4py_cython/gmatch4py/graph_matching_algorithm.pyx new file mode 100644 index 0000000..5b2ed35 --- /dev/null +++ b/gmatch4py_cython/gmatch4py/graph_matching_algorithm.pyx @@ -0,0 +1,37 @@ +# coding = utf-8 +import numpy as np +cimport numpy as np + +cdef class GraphMatchingAlgorithm: + + def __init__(self,type="distance",max_value="inf"): + self.type=type + self.maxvalue=max_value + + def comparator(self,g1, g2, int c_del_node, int c_del_edge, int c_ins_node, int c_ins_edge,h): + pass + + def null_value(self): + if self.type == "distance": + return np.nan + else: # if similarity + return 0 + + def compare(self,list listgs, selected=None, int c_del_node=1, int c_del_edge=1, int c_ins_node=1, int c_ins_edge=1,int h=2): + n = len(listgs) + comparison_matrix = np.zeros((n, n)) + for i in range(n): + for j in range(i, n): + f=True + if not listgs[i] or not listgs[j]: + f=False + if selected: + if not i in selected: + f=False + if f: + comparison_matrix[i, j] = self.comparator(listgs[i], listgs[j],c_del_node=c_del_node, c_del_edge=c_del_edge, c_ins_node=c_ins_node, c_ins_edge=c_ins_edge,h=h) + else: + comparison_matrix[i, j] = self.null_value() + comparison_matrix[j, i] = comparison_matrix[i, j] + + return comparison_matrix diff --git a/gmatch4py_cython/gmatch4py/jaccard.pyx b/gmatch4py_cython/gmatch4py/jaccard.pyx index 237acd3..2699457 100644 --- a/gmatch4py_cython/gmatch4py/jaccard.pyx +++ b/gmatch4py_cython/gmatch4py/jaccard.pyx @@ -12,7 +12,7 @@ class Jaccard(): @staticmethod - def compare(listgs): + def compare(listgs,selected): cdef int n = len(listgs) cdef np.ndarray comparison_matrix = np.zeros((n, n)) cdef i=0 @@ -21,12 +21,20 @@ class Jaccard(): for j in range(i,n): g1 = listgs[i] g2 = listgs[j] - inter_ver,inter_ed = Jaccard.intersect_graph(g1,g2) - try : + f=True + if not listgs[i] or not listgs[j]: + f=False + elif len(listgs[i])== 0 or len(listgs[j]) == 0: + f=False + if selected: + if not i in selected: + f=False + if f: + inter_ver,inter_ed = Jaccard.intersect_graph(g1,g2) comparison_matrix[i,j]=(len(inter_ver)/len(Jaccard.union_nodes(g1,g2)))*(len(inter_ed)/len(Jaccard.union_edges(g1,g2))) - comparison_matrix[j,i]=comparison_matrix[i,j] - except ZeroDivisionError: - pass # oui je suis flemmard ! X) + else: + comparison_matrix[i, j] = 0. + comparison_matrix[j, i] = comparison_matrix[i, j] return comparison_matrix diff --git a/gmatch4py_cython/gmatch4py/kernels/random_walk_kernel.pyx b/gmatch4py_cython/gmatch4py/kernels/random_walk_kernel.pyx new file mode 100644 index 0000000..d780eb0 --- /dev/null +++ b/gmatch4py_cython/gmatch4py/kernels/random_walk_kernel.pyx @@ -0,0 +1,93 @@ +# coding = utf-8 + +import networkx as nx +import numpy as np + +class GeometricRandomWalkKernel(): + __type__ = "sim" + @staticmethod + def maxDegree(G): + degree_sequence = sorted(nx.degree(G).values(), reverse=True) # degree sequence + + # print "Degree sequence", degree_sequence + dmax = max(degree_sequence) + return dmax + @staticmethod + def compare(listgs): + + n = len(listgs) + comparison_matrix=np.zeros((n,n)) + for i in range(n): + for j in range(i,n): + if len(listgs[i]) <1 or len(listgs[j]) <1: + comparison_matrix[i, j] = 0 + comparison_matrix[j, i] = 0 + continue + direct_product_graph=nx.tensor_product(listgs[i],listgs[j]) + Ax = nx.adjacency_matrix(direct_product_graph).todense() + try: + la = 1/ ((GeometricRandomWalkKernel.maxDegree(direct_product_graph)**2)+1) # lambda value + except: + la= pow(1,-6) + eps = pow(10,-10) + I=np.identity(Ax.shape[0]) + I_vec=np.ones(Ax.shape[0]) + x=I_vec.copy() + x_pre=np.zeros(Ax.shape[0]) + c=0 + + while (np.linalg.norm(x-x_pre)) > eps: + if c > 100: + break + x_pre=x + + x= I_vec + la*np.dot(Ax,x_pre.T) + c+=1 + comparison_matrix[i,j]=np.sum(x) + comparison_matrix[j,i]=comparison_matrix[i,j] + print(comparison_matrix) + for i in range(n): + for j in range(i,n): + comparison_matrix[i,j] = (comparison_matrix[i,j]/np.sqrt(comparison_matrix[i,i]*comparison_matrix[j,j])) + comparison_matrix[j,i]=comparison_matrix[i,j] + return comparison_matrix + +class KStepRandomWalkKernel(): + __type__ = "sim" + @staticmethod + def maxDegree(G): + degree_sequence = sorted(nx.degree(G).values(), reverse=True) # degree sequence + # print "Degree sequence", degree_sequence + dmax = max(degree_sequence) + return dmax + @staticmethod + def compare(listgs,lambda_list=[1,1,1]): + k=len(lambda_list) + if not len(lambda_list) == k: + raise AttributeError + n = len(listgs) + comparison_matrix=np.zeros((n,n)) + for i in range(n): + for j in range(i,n): + if len(listgs[i]) <1 or len(listgs[j]) <1: + comparison_matrix[i, j] = 0 + comparison_matrix[j, i] = 0 + continue + direct_product_graph=nx.tensor_product(listgs[i],listgs[j]) + Ax = nx.adjacency_matrix(direct_product_graph).todense() + eps = pow(10,-10) + I=np.identity(Ax.shape[0]) + ax_pow = I.copy() + sum_ = lambda_list[0] * I + for kk in range(1, k): + ax_pow *= Ax + sum_ += lambda_list[kk] * ax_pow + + comparison_matrix[i, j] = np.sum(sum_)/(len(listgs[i])**2 * len(listgs[j])**2) + comparison_matrix[j,i] = comparison_matrix[i,j] + + for i in range(n): + for j in range(i,n): + comparison_matrix[i,j] = comparison_matrix[i,j]/np.sqrt(comparison_matrix[i,i]*comparison_matrix[j,j]) + comparison_matrix[j,i]=comparison_matrix[i,j] + return comparison_matrix \ No newline at end of file diff --git a/gmatch4py_cython/gmatch4py/kernels/shortest_path_kernel.pyx b/gmatch4py_cython/gmatch4py/kernels/shortest_path_kernel.pyx new file mode 100644 index 0000000..e7e7444 --- /dev/null +++ b/gmatch4py_cython/gmatch4py/kernels/shortest_path_kernel.pyx @@ -0,0 +1,88 @@ +# coding = utf-8 + +""" +Shortest-Path graph kernel. +Python implementation based on: "Shortest-path kernels on graphs", by +Borgwardt, K.M.; Kriegel, H.-P., in Data Mining, Fifth IEEE +International Conference on , vol., no., pp.8 pp.-, 27-30 Nov. 2005 +doi: 10.1109/ICDM.2005.132 +Author : Sandro Vega-Pons, Emanuele Olivetti +Modified by : Jacques Fize +""" + +import networkx as nx +import numpy as np + + +class ShortestPathGraphKernel: + """ + Shorthest path graph kernel. + """ + __type__ = "sim" + @staticmethod + def compare( g_1, g_2, verbose=False): + """Compute the kernel value (similarity) between two graphs. + Parameters + ---------- + g1 : networkx.Graph + First graph. + g2 : networkx.Graph + Second graph. + Returns + ------- + k : The similarity value between g1 and g2. + """ + # Diagonal superior matrix of the floyd warshall shortest + # paths: + fwm1 = np.array(nx.floyd_warshall_numpy(g_1)) + fwm1 = np.where(fwm1 == np.inf, 0, fwm1) + fwm1 = np.where(fwm1 == np.nan, 0, fwm1) + fwm1 = np.triu(fwm1, k=1) + bc1 = np.bincount(fwm1.reshape(-1).astype(int)) + + fwm2 = np.array(nx.floyd_warshall_numpy(g_2)) + fwm2 = np.where(fwm2 == np.inf, 0, fwm2) + fwm2 = np.where(fwm2 == np.nan, 0, fwm2) + fwm2 = np.triu(fwm2, k=1) + bc2 = np.bincount(fwm2.reshape(-1).astype(int)) + + # Copy into arrays with the same length the non-zero shortests + # paths: + v1 = np.zeros(max(len(bc1), len(bc2)) - 1) + v1[range(0, len(bc1)-1)] = bc1[1:] + + v2 = np.zeros(max(len(bc1), len(bc2)) - 1) + v2[range(0, len(bc2)-1)] = bc2[1:] + + return np.sum(v1 * v2) + + + @staticmethod + def compare_list(graph_list, verbose=False): + """Compute the all-pairs kernel values for a list of graphs. + This function can be used to directly compute the kernel + matrix for a list of graphs. The direct computation of the + kernel matrix is faster than the computation of all individual + pairwise kernel values. + Parameters + ---------- + graph_list: list + A list of graphs (list of networkx graphs) + Return + ------ + K: numpy.array, shape = (len(graph_list), len(graph_list)) + The similarity matrix of all graphs in graph_list. + """ + n = len(graph_list) + k = np.zeros((n, n)) + for i in range(n): + for j in range(i, n): + k[i, j] = ShortestPathGraphKernel.compare(graph_list[i], graph_list[j]) + k[j, i] = k[i, j] + + k_norm = np.zeros(k.shape) + for i in range(k.shape[0]): + for j in range(k.shape[1]): + k_norm[i, j] = k[i, j] / np.sqrt(k[i, i] * k[j, j]) + + return k_norm \ No newline at end of file diff --git a/gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman.pyx b/gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman.pyx new file mode 100644 index 0000000..809fb27 --- /dev/null +++ b/gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman.pyx @@ -0,0 +1,143 @@ +# coding = utf-8 + +"""Weisfeiler_Lehman graph kernel. + +Python implementation based on: "Weisfeiler-Lehman Graph Kernels", by: +Nino Shervashidze, Pascal Schweitzer, Erik J. van Leeuwen, Kurt +Mehlhorn, Karsten M. Borgwardt, JMLR, 2012. +http://jmlr.csail.mit.edu/papers/v12/shervashidze11a.html + +Author : Sandro Vega-Pons, Emanuele Olivetti +Source : https://github.com/emanuele/jstsp2015/blob/master/gk_weisfeiler_lehman.py +Modified by : Jacques Fizen +""" + +import copy + +import networkx as nx +import numpy as np +cimport numpy as np + + +class WeisfeleirLehmanKernel(object): + __type__ = "sim" + @staticmethod + def compare(graph_list,h=2): + """Compute the all-pairs kernel values for a list of graphs. + This function can be used to directly compute the kernel + matrix for a list of graphs. The direct computation of the + kernel matrix is faster than the computation of all individual + pairwise kernel values. + Parameters + ---------- + graph_list: list + A list of graphs (list of networkx graphs) + h : interger + Number of iterations. + node_label : boolean + Whether to use original node labels. True for using node labels + saved in the attribute 'node_label'. False for using the node + degree of each node as node attribute. + Return + ------ + K: numpy.array, shape = (len(graph_list), len(graph_list)) + The similarity matrix of all graphs in graph_list. + """ + + cdef int n = len(graph_list) + cdef np.ndarray phi + cdef int n_nodes = 0 + cdef int n_max = 0 + cdef int i,j + # Compute adjacency lists and n_nodes, the total number of + # nodes in the dataset. + for i in range(n): + n_nodes += graph_list[i].number_of_nodes() + + # Computing the maximum number of nodes in the graphs. It + # will be used in the computation of vectorial + # representation. + if (n_max < graph_list[i].number_of_nodes()): + n_max = graph_list[i].number_of_nodes() + + phi = np.zeros((n_nodes, n), dtype=np.uint64) + + # INITIALIZATION: initialize the nodes labels for each graph + # with their labels or with degrees (for unlabeled graphs) + + cdef list labels = [0] * n + cdef dict label_lookup = {} + cdef int label_counter = 0 + + + # label_lookup is an associative array, which will contain the + # mapping from multiset labels (strings) to short labels + # (integers) + + cdef list nodes + for i in range(n): + nodes = graph_list[i].nodes() + # It is assumed that the graph has an attribute + # 'node_label' + labels[i] = np.zeros(len(nodes), dtype=np.int32) + + for j in range(len(nodes)): + if not (nodes[j] in label_lookup): + label_lookup[nodes[j]] = str(label_counter) + labels[i][j] = label_counter + label_counter += 1 + else: + labels[i][j] = label_lookup[nodes[j]] + # labels are associated to a natural number + # starting with 0. + + phi[labels[i][j], i] += 1 + + graph_list[i]=nx.relabel_nodes(graph_list[i],label_lookup) + + cdef np.ndarray[np.float64_t] k + k = np.dot(phi.transpose(), phi) + + # MAIN LOOP + cdef int it = 0 + + new_labels = copy.deepcopy(labels) # Can't work without it !!! + + while it < h: + # create an empty lookup table + label_lookup = {} + label_counter = 0 + + phi = np.zeros((n_nodes, n)) + for i in range(n): + nodes = graph_list[i].nodes() + for v in range(len(nodes)): + # form a multiset label of the node v of the i'th graph + # and convert it to a string + + long_label = [] + long_label.extend(nx.neighbors(graph_list[i],nodes[v])) + + long_label_string = "".join(long_label) + # if the multiset label has not yet occurred, add it to the + # lookup table and assign a number to it + if not (long_label_string in label_lookup): + label_lookup[long_label_string] = str(label_counter) + new_labels[i][v] = label_counter + label_counter += 1 + else: + new_labels[i][v] = label_lookup[long_label_string] + # fill the column for i'th graph in phi + aux = np.bincount(new_labels[i]) + phi[new_labels[i], i] += aux[new_labels[i]] + + k += np.dot(phi.transpose(), phi) + it = it + 1 + + # Compute the normalized version of the kernel + cdef np.ndarray[np.float64_t] k_norm = np.zeros((k.shape[0],k.shape[1])) + for i in range(k.shape[0]): + for j in range(k.shape[1]): + k_norm[i, j] = k[i, j] / np.sqrt(k[i, i] * k[j, j]) + + return k_norm \ No newline at end of file diff --git a/gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman_edge.pyx b/gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman_edge.pyx new file mode 100644 index 0000000..367e099 --- /dev/null +++ b/gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman_edge.pyx @@ -0,0 +1,192 @@ +# coding = utf-8 + +# coding = utf-8# coding = utf-8 + +from helpers.gazeteer_helpers import get_data,get_data_by_wikidata_id + +# coding = utf-8 + +"""Weisfeiler_Lehman GEO graph kernel. + +""" + +import numpy as np +import networkx as nx +import copy + +class WeisfeleirLehmanKernelEdge(object): + __type__ = "sim" + + + @staticmethod + def compare(graph_list,h=3): + """Compute the all-pairs kernel values for a list of graphs. + This function can be used to directly compute the kernel + matrix for a list of graphs. The direct computation of the + kernel matrix is faster than the computation of all individual + pairwise kernel values. + Parameters + ---------- + graph_list: list + A list of graphs (list of networkx graphs) + h : interger + Number of iterations. + node_label : boolean + Whether to use original node labels. True for using node labels + saved in the attribute 'node_label'. False for using the node + degree of each node as node attribute. + Return + ------ + K: numpy.array, shape = (len(graph_list), len(graph_list)) + The similarity matrix of all graphs in graph_list. + """ + + n = len(graph_list) + k = [0] * (h + 1) + n_nodes = 0 + n_max = 0 + ams=[nx.adjacency_matrix(g).todense() for g in graph_list] + inclusion_dictionnary={} + + # Compute adjacency lists and n_nodes, the total number of + # nodes in the dataset. + for i in range(n): + n_nodes += graph_list[i].number_of_nodes() + + """ + Store Inclusion Informations + """ + for node in graph_list[i].nodes(): + graph_list[i].node[node]["id_GD"]=node + if not node in inclusion_dictionnary: + inc_list = [] + try: + inc_list = get_data(node)["inc_P131"] + except: + try: + inc_list=get_data_by_wikidata_id(get_data(node)["continent"])["id"] + except: + pass # No inclusion + if inc_list: + inc_list = inc_list if isinstance(inc_list,list) else [inc_list] + + inclusion_dictionnary[node]=inc_list[0] + for j in range(1,len(inc_list)): + if j+1 < len(inc_list): + inclusion_dictionnary[inc_list[j]]=inc_list[j+1] + + + + + # Computing the maximum number of nodes in the graphs. It + # will be used in the computation of vectorial + # representation. + if (n_max < graph_list[i].number_of_nodes()): + n_max = graph_list[i].number_of_nodes() + + phi = np.zeros((n_nodes, n), dtype=np.uint64) + #print(inclusion_dictionnary) + # INITIALIZATION: initialize the nodes labels for each graph + # with their labels or with degrees (for unlabeled graphs) + + labels = [0] * n + label_lookup = {} + label_counter = 0 + + # label_lookup is an associative array, which will contain the + # mapping from multiset labels (strings) to short labels + # (integers) + for i in range(n): + nodes = graph_list[i].nodes() + # It is assumed that the graph has an attribute + # 'node_label' + labels[i] = np.zeros(len(nodes), dtype=np.int32) + + for j in range(len(nodes)): + if not (nodes[j] in label_lookup): + label_lookup[nodes[j]] = str(label_counter) + labels[i][j] = label_counter + label_counter += 1 + else: + labels[i][j] = label_lookup[nodes[j]] + # labels are associated to a natural number + # starting with 0. + + phi[labels[i][j], i] += 1 + + graph_list[i]=nx.relabel_nodes(graph_list[i],label_lookup) + + L=label_counter + print("L1",L) + ed=np.zeros((np.int((L*(L+1))),n)) + # MAIN LOOP + it = 0 + new_labels = copy.deepcopy(labels) # Can't work without it !!! + + for i in range(n): + labels_aux = np.tile(new_labels[i].reshape(-1,1),len(new_labels[i])) + a=np.minimum(labels_aux,labels_aux.T) + b=np.maximum(labels_aux,np.transpose(labels_aux)) + I=np.triu((ams[i] !=0),1) + a_i=np.extract(I,a) + b_i = np.extract(I, b) + Ind=np.abs(np.multiply((a[I]-1),(2*L+2-a[I])/2+b[I]-a[I]+1).astype(int)) + minind=np.min(Ind) + aux=np.bincount(Ind) + ed[Ind,i]=aux[Ind] + + mask=np.sum(ed,1) !=0 + ed= ed[mask] + k=np.dot(ed.T,ed) + + it = 0 + new_labels = copy.deepcopy(new_labels) # Can't work without it !!! + + while it < h: + label_lookup={} + label_counter=0 + for i in range(n): + nodes = graph_list[i].nodes() + for v in range(len(nodes)): + # form a multiset label of the node v of the i'th graph + # and convert it to a string + + long_label = [] + long_label.extend(nx.neighbors(graph_list[i],nodes[v])) + + long_label_string = "".join(long_label) + # if the multiset label has not yet occurred, add it to the + # lookup table and assign a number to it + if not (long_label_string in label_lookup): + label_lookup[long_label_string] = str(label_counter) + new_labels[i][v] = label_counter + label_counter += 1 + else: + new_labels[i][v] = label_lookup[long_label_string] + + L = label_counter + print("L2",L) + ed = np.zeros((np.int((L * (L + 1))), n)) + for i in range(n): + labels_aux = np.tile(new_labels[i].reshape(-1, 1), len(new_labels[i])) + a = np.minimum(labels_aux, labels_aux.T) + b = np.maximum(labels_aux, np.transpose(labels_aux)) + I = np.triu((ams[i] != 0), 1) + a_i = np.extract(I, a) + b_i = np.extract(I, b) + Ind = np.abs(np.multiply((a[I] - 1), (2 * L + 2 - a[I]) / 2 + b[I] - a[I] + 1).astype(int)) + minind = np.min(Ind) + aux = np.bincount(Ind) + ed[Ind, i] = aux[Ind] + + mask = np.sum(ed, 1) != 0 + ed = ed[mask] + k += np.dot(ed.T, ed) + print(k) + it+=1 + k_norm = np.zeros(k.shape) + for i in range(k.shape[0]): + for j in range(k.shape[1]): + k_norm[i, j] = k[i, j] / np.sqrt(k[i, i] * k[j, j]) + + return k_norm \ No newline at end of file diff --git a/gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman_geo.pyx b/gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman_geo.pyx new file mode 100644 index 0000000..59c2b1b --- /dev/null +++ b/gmatch4py_cython/gmatch4py/kernels/weisfeiler_lehman_geo.pyx @@ -0,0 +1,165 @@ +# coding = utf-8 + +from helpers.gazeteer_helpers import get_data,get_data_by_wikidata_id + +# coding = utf-8 + +"""Weisfeiler_Lehman GEO graph kernel. + +""" + +import numpy as np +import networkx as nx +import copy + + +class WeisfeleirLehmanKernelGEO(object): + __type__ = "sim" + __depreciated__=True + + @staticmethod + def compare(graph_list,h=2,verbose=False): + """Compute the all-pairs kernel values for a list of graphs. + This function can be used to directly compute the kernel + matrix for a list of graphs. The direct computation of the + kernel matrix is faster than the computation of all individual + pairwise kernel values. + Parameters + ---------- + graph_list: list + A list of graphs (list of networkx graphs) + h : interger + Number of iterations. + node_label : boolean + Whether to use original node labels. True for using node labels + saved in the attribute 'node_label'. False for using the node + degree of each node as node attribute. + Return + ------ + K: numpy.array, shape = (len(graph_list), len(graph_list)) + The similarity matrix of all graphs in graph_list. + """ + + n = len(graph_list) + k = [0] * (h + 1) + n_nodes = 0 + n_max = 0 + + inclusion_dictionnary={} + + # Compute adjacency lists and n_nodes, the total number of + # nodes in the dataset. + for i in range(n): + n_nodes += graph_list[i].number_of_nodes() + + """ + Store Inclusion Informations + """ + for node in graph_list[i].nodes(): + graph_list[i].node[node]["id_GD"]=node + if not node in inclusion_dictionnary: + inc_list = [] + try: + inc_list = get_data(node)["inc_P131"] + except: + try: + inc_list=get_data_by_wikidata_id(get_data(node)["continent"])["id"] + except: + pass # No inclusion + if inc_list: + inc_list = inc_list if isinstance(inc_list,list) else [inc_list] + + inclusion_dictionnary[node]=inc_list[0] + for j in range(1,len(inc_list)): + if j+1 < len(inc_list): + inclusion_dictionnary[inc_list[j]]=inc_list[j+1] + + + + + # Computing the maximum number of nodes in the graphs. It + # will be used in the computation of vectorial + # representation. + if (n_max < graph_list[i].number_of_nodes()): + n_max = graph_list[i].number_of_nodes() + + phi = np.zeros((n_nodes, n), dtype=np.uint64) + if verbose: print(inclusion_dictionnary) + # INITIALIZATION: initialize the nodes labels for each graph + # with their labels or with degrees (for unlabeled graphs) + + labels = [0] * n + label_lookup = {} + label_counter = 0 + + # label_lookup is an associative array, which will contain the + # mapping from multiset labels (strings) to short labels + # (integers) + for i in range(n): + nodes = graph_list[i].nodes() + # It is assumed that the graph has an attribute + # 'node_label' + labels[i] = np.zeros(len(nodes), dtype=np.int32) + + for j in range(len(nodes)): + if not (nodes[j] in label_lookup): + label_lookup[nodes[j]] = str(label_counter) + labels[i][j] = label_counter + label_counter += 1 + else: + labels[i][j] = label_lookup[nodes[j]] + # labels are associated to a natural number + # starting with 0. + + phi[labels[i][j], i] += 1 + + graph_list[i]=nx.relabel_nodes(graph_list[i],label_lookup) + k = np.dot(phi.transpose(), phi).astype(np.float64) + + # MAIN LOOP + it = 0 + new_labels = copy.deepcopy(labels) # Can't work without it !!! + + while it < h: + # create an empty lookup table + label_lookup = {} + label_counter = 0 + + phi = np.zeros((n_nodes, n)) + for i in range(n): + nodes = graph_list[i].nodes() + for v in range(len(nodes)): + # form a multiset label of the node v of the i'th graph + # and convert it to a string + + id_GD = graph_list[i].node[nodes[v]]['id_GD'] + if id_GD in inclusion_dictionnary: + + long_label_string = inclusion_dictionnary[id_GD] + graph_list[i].node[nodes[v]]['id_GD']=inclusion_dictionnary[id_GD] + else: + long_label_string = id_GD + + + # if the multiset label has not yet occurred, add it to the + # lookup table and assign a number to it + if not (long_label_string in label_lookup): + label_lookup[long_label_string] = str(label_counter) + new_labels[i][v] = label_counter + label_counter += 1 + else: + new_labels[i][v] = label_lookup[long_label_string] + # fill the column for i'th graph in phi + aux = np.bincount(new_labels[i]) + phi[new_labels[i], i] += (1/(it+2))*aux[new_labels[i]] # +2 because it0 =0 + + k += np.dot(phi.transpose(), phi) + it = it + 1 + + # Compute the normalized version of the kernel + k_norm = np.zeros(k.shape) + for i in range(k.shape[0]): + for j in range(k.shape[1]): + k_norm[i, j] = k[i, j] / np.sqrt(k[i, i] * k[j, j]) + + return k_norm \ No newline at end of file diff --git a/gmatch4py_cython/gmatch4py/mcs.pyx b/gmatch4py_cython/gmatch4py/mcs.pyx index 17a8fd0..93365ef 100644 --- a/gmatch4py_cython/gmatch4py/mcs.pyx +++ b/gmatch4py_cython/gmatch4py/mcs.pyx @@ -9,19 +9,27 @@ class MCS(): Pattern Recognition Letters, 1998* """ @staticmethod - def compare(listgs): + def compare(listgs,selected): cdef int n = len(listgs) cdef np.ndarray comparison_matrix = np.zeros((n, n)) for i in range(n): for j in range(i, n): - g1 = listgs[i] - g2 = listgs[j] - if len(g1)== 0 or len(g2) == 0: - continue - comparison_matrix[i, j] = MCS.s_mcs(g1,g2) + f=True + if not listgs[i] or not listgs[j]: + f=False + elif len(listgs[i])== 0 or len(listgs[j]) == 0: + f=False + if selected: + if not i in selected: + f=False + if f: + comparison_matrix[i, j] = MCS.s_mcs(listgs[i],listgs[j]) + else: + comparison_matrix[i, j] = 0. comparison_matrix[j, i] = comparison_matrix[i, j] return comparison_matrix + @staticmethod def intersect(a, b): return list(set(a) & set(b)) @@ -62,5 +70,5 @@ class MCS(): @staticmethod def s_mcs(g1, g2): - return len(MCS.maximum_common_subgraph(g1, g2)) / max(len(g1), len(g2)) + return len(MCS.maximum_common_subgraph(g1, g2)) / float(max(len(g1), len(g2))) diff --git a/gmatch4py_cython/setup.py b/gmatch4py_cython/setup.py index c8df67b..8f84375 100644 --- a/gmatch4py_cython/setup.py +++ b/gmatch4py_cython/setup.py @@ -29,7 +29,8 @@ def makeExtension(extName): return Extension( extName, [extPath], - extra_compile_args = ["-O3", "-Wall"] + language="c++", + extra_compile_args = ["-O3", "-Wall",'-std=c++11', '-v'], ) # get the list of extensions diff --git a/gmatch4py/README.md b/gmatch4py_old/README.md similarity index 100% rename from gmatch4py/README.md rename to gmatch4py_old/README.md diff --git a/gmatch4py_old/__init__.py b/gmatch4py_old/__init__.py new file mode 100644 index 0000000..a4e2017 --- /dev/null +++ b/gmatch4py_old/__init__.py @@ -0,0 +1 @@ +__version__ = "0.1" diff --git a/gmatch4py/bag_of_cliques.py b/gmatch4py_old/bag_of_cliques.py similarity index 100% rename from gmatch4py/bag_of_cliques.py rename to gmatch4py_old/bag_of_cliques.py diff --git a/gmatch4py_old/data/source/source1.txt b/gmatch4py_old/data/source/source1.txt new file mode 100644 index 0000000..de26da6 --- /dev/null +++ b/gmatch4py_old/data/source/source1.txt @@ -0,0 +1,36 @@ +{ + "id": "source1.txt-1", + "sentenceNumber": 1, + "length": 17, + "tokens": [{ + "id": "1", + "lemma": "Haakon", + "deprel": "nsubj", + "word": "Haakon", + "rel": "4", + "pos": "NNP" + }, { + "id": "2", + "lemma": "be", + "deprel": "cop", + "word": "is", + "rel": "4", + "pos": "VBZ" + }, { + "id": "3", + "lemma": "my", + "deprel": "poss", + "word": "my", + "rel": "4", + "pos": "PRP$" + }, { + "id": "4", + "lemma": "name", + "deprel": "null", + "word": "name", + "rel": "0", + "pos": "NN" + }], + "filename": "source1.txt", + "offset": 0 +} diff --git a/gmatch4py/deltacon.py b/gmatch4py_old/deltacon.py similarity index 100% rename from gmatch4py/deltacon.py rename to gmatch4py_old/deltacon.py diff --git a/gmatch4py_old/exception/__init__.py b/gmatch4py_old/exception/__init__.py new file mode 100644 index 0000000..1d997a2 --- /dev/null +++ b/gmatch4py_old/exception/__init__.py @@ -0,0 +1,7 @@ +# coding = utf-8 +from termcolor import colored +class NotFoundDistance(Exception): + def __init__(self,dd,distanceFunctionDict): + # Call the base class constructor with the parameters it needs + super(Exception, self).__init__(colored("{0} is not an edit distance implemented ! Select a distance from : {1}".format(dd,",".join(distanceFunctionDict.keys())),"red")) + diff --git a/gmatch4py_old/ged/__init__.py b/gmatch4py_old/ged/__init__.py new file mode 100644 index 0000000..950f635 --- /dev/null +++ b/gmatch4py_old/ged/__init__.py @@ -0,0 +1 @@ +# coding = utf-8 \ No newline at end of file diff --git a/gmatch4py_old/ged/algorithm/__init__.py b/gmatch4py_old/ged/algorithm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gmatch4py_old/ged/algorithm/abstract_graph_edit_dist.py b/gmatch4py_old/ged/algorithm/abstract_graph_edit_dist.py new file mode 100644 index 0000000..e0a1d3b --- /dev/null +++ b/gmatch4py_old/ged/algorithm/abstract_graph_edit_dist.py @@ -0,0 +1,112 @@ +# -*- coding: UTF-8 -*- +from __future__ import print_function + +import sys + +import numpy as np +from scipy.optimize import linear_sum_assignment + + +class AbstractGraphEditDistance(object): + def __init__(self, g1, g2,debug=False,**kwargs): + self.g1 = g1 + self.g2 = g2 + self.debug=debug + + self.node_del = kwargs.get("node_del",1) + self.node_ins = kwargs.get("node_ins",1) + self.edge_del = kwargs.get("edge_del",1) + self.edge_ins = kwargs.get("edge_ins",1) + + + def distance(self): + opt_path = self.edit_costs() + if self.debug: + print("Edit path for ",str(self.__class__.__name__),"\n",opt_path) + return sum(opt_path) + + def print_operations(self,cost_matrix,row_ind,col_ind): + nodes1 = self.g1.nodes() + nodes2 = self.g2.nodes() + dn1 = self.g1.node + dn2 = self.g2.node + + n,m=len(nodes1),len(nodes2) + for i in range(len(row_ind)): + y,x=row_ind[i],col_ind[i] + val=cost_matrix[row_ind[i]][col_ind[i]] + if x<m and y<n: + print("SUB {0} to {1} cost = {2}".format(dn1[nodes1[y]]["label"],dn2[nodes2[x]]["label"],val)) + elif x <m and y>=n: + print("ADD {0} cost = {1}".format(dn2[nodes2[y-n]]["label"],val)) + elif x>=m and y<n: + print("DEL {0} cost = {1}".format(dn1[nodes1[m-x]]["label"],val)) + + def edit_costs(self): + cost_matrix = self.create_cost_matrix() + if self.debug: + np.set_printoptions(precision=3) + print("Cost Matrix for ",str(self.__class__.__name__),"\n",cost_matrix) + + row_ind,col_ind = linear_sum_assignment(cost_matrix) + if self.debug: + self.print_operations(cost_matrix,row_ind,col_ind) + return [cost_matrix[row_ind[i]][col_ind[i]] for i in range(len(row_ind))] + + def create_cost_matrix(self): + """ + Creates a |N+M| X |N+M| cost matrix between all nodes in + graphs g1 and g2 + Each cost represents the cost of substituting, + deleting or inserting a node + The cost matrix consists of four regions: + + substitute | insert costs + ------------------------------- + delete | delete -> delete + + The delete -> delete region is filled with zeros + """ + n = len(self.g1) + m = len(self.g2) + cost_matrix = np.zeros((n+m,n+m)) + #cost_matrix = [[0 for i in range(n + m)] for j in range(n + m)] + nodes1 = self.g1.nodes() + nodes2 = self.g2.nodes() + + for i in range(n): + for j in range(m): + cost_matrix[i,j] = self.substitute_cost(nodes1[i], nodes2[j]) + + for i in range(m): + for j in range(m): + cost_matrix[i+n,j] = self.insert_cost(i, j, nodes2) + + for i in range(n): + for j in range(n): + cost_matrix[j,i+m] = self.delete_cost(i, j, nodes1) + + self.cost_matrix = cost_matrix + return cost_matrix + + def insert_cost(self, i, j): + raise NotImplementedError + + def delete_cost(self, i, j): + raise NotImplementedError + + def substitute_cost(self, nodes1, nodes2): + raise NotImplementedError + + def print_matrix(self): + print("cost matrix:") + print(self.g1.nodes()) + print(self.g2.nodes()) + print(np.array(self.create_cost_matrix())) + for column in self.create_cost_matrix(): + for row in column: + if row == sys.maxsize: + print ("inf\t") + else: + print ("%.2f\t" % float(row)) + print("") diff --git a/gmatch4py_old/ged/algorithm/edge_edit_dist.py b/gmatch4py_old/ged/algorithm/edge_edit_dist.py new file mode 100644 index 0000000..74ef2e9 --- /dev/null +++ b/gmatch4py_old/ged/algorithm/edge_edit_dist.py @@ -0,0 +1,29 @@ +import sys + +from gmatch4py_old.ged.algorithm.abstract_graph_edit_dist import AbstractGraphEditDistance + + +class EdgeEditDistance(AbstractGraphEditDistance): + """ + Calculates the graph edit distance between two edges. + A node in this context is interpreted as a graph, + and edges are interpreted as nodes. + """ + + def __init__(self, g1, g2,**kwargs): + AbstractGraphEditDistance.__init__(self, g1, g2,**kwargs) + + def insert_cost(self, i, j, nodes2): + if i == j: + return self.edge_ins + return sys.maxsize + + def delete_cost(self, i, j, nodes1): + if i == j: + return self.edge_del + return sys.maxsize + + def substitute_cost(self, edge1, edge2): + if edge1 == edge2: + return 0. + return self.edge_del+self.edge_ins diff --git a/gmatch4py_old/ged/algorithm/graph_edit_dist.py b/gmatch4py_old/ged/algorithm/graph_edit_dist.py new file mode 100644 index 0000000..210e15e --- /dev/null +++ b/gmatch4py_old/ged/algorithm/graph_edit_dist.py @@ -0,0 +1,71 @@ +# -*- coding: UTF-8 -*- + +import sys + +import networkx as nx + +from gmatch4py_old.ged.algorithm.abstract_graph_edit_dist import AbstractGraphEditDistance +from gmatch4py_old.ged.algorithm.edge_edit_dist import EdgeEditDistance +from gmatch4py_old.ged.graph.edge_graph import EdgeGraph + + +def compare(g1, g2, print_details=False): + ged = GraphEditDistance(g1, g2,print_details) + return ged.distance() + + +class GraphEditDistance(AbstractGraphEditDistance): + + def __init__(self, g1, g2,debug=False,**kwargs): + AbstractGraphEditDistance.__init__(self, g1, g2,debug,**kwargs) + + def substitute_cost(self, node1, node2): + return self.relabel_cost(node1, node2) + self.edge_diff(node1, node2) + + def relabel_cost(self, node1, node2): + if node1 == node2: + edges1=set(self.get_edge_multigraph(self.g1,node1)) + edges2=set(self.get_edge_multigraph(self.g2,node2)) + return abs(len(edges2.difference(edges1))) # Take in account if there is a different number of edges + else: + return self.node_ins+self.node_del + + def delete_cost(self, i, j, nodes1): + if i == j: + return self.node_del+self.g1.degree(nodes1[i]) # Deleting a node implicate to delete in and out edges + return sys.maxsize + + def insert_cost(self, i, j, nodes2): + if i == j: + deg=self.g2.degree(nodes2[j]) + if isinstance(deg,dict):deg=0 + return self.node_ins+deg + else: + return sys.maxsize + + def get_edge_multigraph(self,g,node): + edges=[] + for id_,val in g.edge[node].items(): + if not 0 in val: + edges.append(str(id_) + val["color"]) + else: + for _,edge in val.items(): + edges.append(str(id_)+edge["color"]) + return edges + + def edge_diff(self, node1, node2): + if isinstance(self.g1,nx.MultiDiGraph): + edges1 = self.get_edge_multigraph(self.g1,node1) + edges2 = self.get_edge_multigraph(self.g2,node2) + else: + edges1 = list(self.g1.edge[node1].keys()) + edges2 = list(self.g2.edge[node2].keys()) + if len(edges1) == 0 or len(edges2) == 0: + return max(len(edges1), len(edges2)) + + edit_edit_dist = EdgeEditDistance( + EdgeGraph(node1,edges1), + EdgeGraph(node2,edges2), + edge_del=self.edge_del,edge_ins=self.edge_ins,node_ins=self.node_ins,node_del=self.node_del + ) + return edit_edit_dist.distance() diff --git a/gmatch4py_cython/ged/approximate_ged.pyx b/gmatch4py_old/ged/approximate_ged.py similarity index 100% rename from gmatch4py_cython/ged/approximate_ged.pyx rename to gmatch4py_old/ged/approximate_ged.py diff --git a/gmatch4py_cython/ged/bipartite_graph_matching_2.pyx b/gmatch4py_old/ged/bipartite_graph_matching_2.py similarity index 100% rename from gmatch4py_cython/ged/bipartite_graph_matching_2.pyx rename to gmatch4py_old/ged/bipartite_graph_matching_2.py diff --git a/gmatch4py_old/ged/graph/__init__.py b/gmatch4py_old/ged/graph/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gmatch4py_old/ged/graph/edge_graph.py b/gmatch4py_old/ged/graph/edge_graph.py new file mode 100644 index 0000000..24b8bda --- /dev/null +++ b/gmatch4py_old/ged/graph/edge_graph.py @@ -0,0 +1,16 @@ +# -*- coding: UTF-8 -*- + + +class EdgeGraph(): + + def __init__(self, init_node, nodes): + self.init_node=init_node + self.nodes_ = nodes + self.edge=nodes + def nodes(self): + return self.nodes_ + + def size(self): + return len(self.nodes) + def __len__(self): + return len(self.nodes_) diff --git a/gmatch4py_cython/ged/greedy_edit_distance.pyx b/gmatch4py_old/ged/greedy_edit_distance.py similarity index 100% rename from gmatch4py_cython/ged/greedy_edit_distance.pyx rename to gmatch4py_old/ged/greedy_edit_distance.py diff --git a/gmatch4py_cython/ged/hausdorff_edit_distance.pyx b/gmatch4py_old/ged/hausdorff_edit_distance.py similarity index 100% rename from gmatch4py_cython/ged/hausdorff_edit_distance.pyx rename to gmatch4py_old/ged/hausdorff_edit_distance.py diff --git a/gmatch4py_old/helpers/__init__.py b/gmatch4py_old/helpers/__init__.py new file mode 100644 index 0000000..950f635 --- /dev/null +++ b/gmatch4py_old/helpers/__init__.py @@ -0,0 +1 @@ +# coding = utf-8 \ No newline at end of file diff --git a/gmatch4py_old/helpers/networkx_parser.py b/gmatch4py_old/helpers/networkx_parser.py new file mode 100644 index 0000000..d67049a --- /dev/null +++ b/gmatch4py_old/helpers/networkx_parser.py @@ -0,0 +1,148 @@ +# coding = utf-8 + +import networkx as nx +import graph_tool as gt + + + +def get_prop_type(value, key=None): + """ + Performs typing and value conversion for the graph_tool PropertyMap class. + If a key is provided, it also ensures the key is in a format that can be + used with the PropertyMap. Returns a tuple, (type name, value, key) + """ + # Deal with the value + if isinstance(value, bool): + tname = 'bool' + + elif isinstance(value, int): + tname = 'float' + value = float(value) + + elif isinstance(value, float): + tname = 'float' + + elif isinstance(value, str): + tname = 'string' + value = str(value) + + elif isinstance(value, dict): + tname = 'object' + + else: + tname = 'string' + value = str(value) + + return tname, value, key + + +def nx2gt(nxG): + """ + Converts a networkx graph to a graph-tool graph. + """ + # Phase 0: Create a directed or undirected graph-tool Graph + gtG = gt.Graph(directed=nxG.is_directed()) + + # Add the Graph properties as "internal properties" + for key, value in nxG.graph.items(): + # Convert the value and key into a type for graph-tool + tname, value, key = get_prop_type(value, key) + + prop = gtG.new_graph_property(tname) # Create the PropertyMap + gtG.graph_properties[key] = prop # Set the PropertyMap + gtG.graph_properties[key] = value # Set the actual value + + # Phase 1: Add the vertex and edge property maps + # Go through all nodes and edges and add seen properties + # Add the node properties first + nprops = set() # cache keys to only add properties once + for node, data in nxG.nodes_iter(data=True): + + # Go through all the properties if not seen and add them. + for key, val in data.items(): + if key in nprops: continue # Skip properties already added + + # Convert the value and key into a type for graph-tool + tname, _, key = get_prop_type(val, key) + + prop = gtG.new_vertex_property(tname) # Create the PropertyMap + gtG.vertex_properties[key] = prop # Set the PropertyMap + + # Add the key to the already seen properties + nprops.add(key) + + # Also add the node id: in NetworkX a node can be any hashable type, but + # in graph-tool node are defined as indices. So we capture any strings + # in a special PropertyMap called 'id' -- modify as needed! + gtG.vertex_properties['id'] = gtG.new_vertex_property('string') + + # Add the edge properties second + eprops = set() # cache keys to only add properties once + for src, dst, data in nxG.edges_iter(data=True): + + # Go through all the edge properties if not seen and add them. + for key, val in data.items(): + if key in eprops: continue # Skip properties already added + + # Convert the value and key into a type for graph-tool + tname, _, key = get_prop_type(val, key) + + prop = gtG.new_edge_property(tname) # Create the PropertyMap + gtG.edge_properties[key] = prop # Set the PropertyMap + + # Add the key to the already seen properties + eprops.add(key) + + # Phase 2: Actually add all the nodes and vertices with their properties + # Add the nodes + vertices = {} # vertex mapping for tracking edges later + for node, data in nxG.nodes_iter(data=True): + + # Create the vertex and annotate for our edges later + v = gtG.add_vertex() + vertices[node] = v + + # Set the vertex properties, not forgetting the id property + data['id'] = str(node) + for key, value in data.items(): + gtG.vp[key][v] = value # vp is short for vertex_properties + + # Add the edges + for src, dst, data in nxG.edges_iter(data=True): + + # Look up the vertex structs from our vertices mapping and add edge. + e = gtG.add_edge(vertices[src], vertices[dst]) + + # Add the edge properties + for key, value in data.items(): + gtG.ep[key][e] = value # ep is short for edge_properties + + # Done, finally! + return gtG + + +if __name__ == '__main__': + + # Create the networkx graph + nxG = nx.Graph(name="Undirected Graph") + nxG.add_node("v1", name="alpha", color="red") + nxG.add_node("v2", name="bravo", color="blue") + nxG.add_node("v3", name="charlie", color="blue") + nxG.add_node("v4", name="hub", color="purple") + nxG.add_node("v5", name="delta", color="red") + nxG.add_node("v6", name="echo", color="red") + + nxG.add_edge("v1", "v2", weight=0.5, label="follows") + nxG.add_edge("v1", "v3", weight=0.25, label="follows") + nxG.add_edge("v2", "v4", weight=0.05, label="follows") + nxG.add_edge("v3", "v4", weight=0.35, label="follows") + nxG.add_edge("v5", "v4", weight=0.65, label="follows") + nxG.add_edge("v6", "v4", weight=0.53, label="follows") + nxG.add_edge("v5", "v6", weight=0.21, label="follows") + + for item in nxG.edges_iter(data=True): + print(item) + + # Convert to graph-tool graph + gtG = nx2gt(nxG) + gtG.list_properties() \ No newline at end of file diff --git a/gmatch4py/jaccard.py b/gmatch4py_old/jaccard.py similarity index 100% rename from gmatch4py/jaccard.py rename to gmatch4py_old/jaccard.py diff --git a/gmatch4py_old/kernels/__init__.py b/gmatch4py_old/kernels/__init__.py new file mode 100644 index 0000000..950f635 --- /dev/null +++ b/gmatch4py_old/kernels/__init__.py @@ -0,0 +1 @@ +# coding = utf-8 \ No newline at end of file diff --git a/gmatch4py_old/kernels/random_walk_kernel.py b/gmatch4py_old/kernels/random_walk_kernel.py new file mode 100644 index 0000000..d780eb0 --- /dev/null +++ b/gmatch4py_old/kernels/random_walk_kernel.py @@ -0,0 +1,93 @@ +# coding = utf-8 + +import networkx as nx +import numpy as np + +class GeometricRandomWalkKernel(): + __type__ = "sim" + @staticmethod + def maxDegree(G): + degree_sequence = sorted(nx.degree(G).values(), reverse=True) # degree sequence + + # print "Degree sequence", degree_sequence + dmax = max(degree_sequence) + return dmax + @staticmethod + def compare(listgs): + + n = len(listgs) + comparison_matrix=np.zeros((n,n)) + for i in range(n): + for j in range(i,n): + if len(listgs[i]) <1 or len(listgs[j]) <1: + comparison_matrix[i, j] = 0 + comparison_matrix[j, i] = 0 + continue + direct_product_graph=nx.tensor_product(listgs[i],listgs[j]) + Ax = nx.adjacency_matrix(direct_product_graph).todense() + try: + la = 1/ ((GeometricRandomWalkKernel.maxDegree(direct_product_graph)**2)+1) # lambda value + except: + la= pow(1,-6) + eps = pow(10,-10) + I=np.identity(Ax.shape[0]) + I_vec=np.ones(Ax.shape[0]) + x=I_vec.copy() + x_pre=np.zeros(Ax.shape[0]) + c=0 + + while (np.linalg.norm(x-x_pre)) > eps: + if c > 100: + break + x_pre=x + + x= I_vec + la*np.dot(Ax,x_pre.T) + c+=1 + comparison_matrix[i,j]=np.sum(x) + comparison_matrix[j,i]=comparison_matrix[i,j] + print(comparison_matrix) + for i in range(n): + for j in range(i,n): + comparison_matrix[i,j] = (comparison_matrix[i,j]/np.sqrt(comparison_matrix[i,i]*comparison_matrix[j,j])) + comparison_matrix[j,i]=comparison_matrix[i,j] + return comparison_matrix + +class KStepRandomWalkKernel(): + __type__ = "sim" + @staticmethod + def maxDegree(G): + degree_sequence = sorted(nx.degree(G).values(), reverse=True) # degree sequence + # print "Degree sequence", degree_sequence + dmax = max(degree_sequence) + return dmax + @staticmethod + def compare(listgs,lambda_list=[1,1,1]): + k=len(lambda_list) + if not len(lambda_list) == k: + raise AttributeError + n = len(listgs) + comparison_matrix=np.zeros((n,n)) + for i in range(n): + for j in range(i,n): + if len(listgs[i]) <1 or len(listgs[j]) <1: + comparison_matrix[i, j] = 0 + comparison_matrix[j, i] = 0 + continue + direct_product_graph=nx.tensor_product(listgs[i],listgs[j]) + Ax = nx.adjacency_matrix(direct_product_graph).todense() + eps = pow(10,-10) + I=np.identity(Ax.shape[0]) + ax_pow = I.copy() + sum_ = lambda_list[0] * I + for kk in range(1, k): + ax_pow *= Ax + sum_ += lambda_list[kk] * ax_pow + + comparison_matrix[i, j] = np.sum(sum_)/(len(listgs[i])**2 * len(listgs[j])**2) + comparison_matrix[j,i] = comparison_matrix[i,j] + + for i in range(n): + for j in range(i,n): + comparison_matrix[i,j] = comparison_matrix[i,j]/np.sqrt(comparison_matrix[i,i]*comparison_matrix[j,j]) + comparison_matrix[j,i]=comparison_matrix[i,j] + return comparison_matrix \ No newline at end of file diff --git a/gmatch4py_old/kernels/shortest_path_kernel.py b/gmatch4py_old/kernels/shortest_path_kernel.py new file mode 100644 index 0000000..e7e7444 --- /dev/null +++ b/gmatch4py_old/kernels/shortest_path_kernel.py @@ -0,0 +1,88 @@ +# coding = utf-8 + +""" +Shortest-Path graph kernel. +Python implementation based on: "Shortest-path kernels on graphs", by +Borgwardt, K.M.; Kriegel, H.-P., in Data Mining, Fifth IEEE +International Conference on , vol., no., pp.8 pp.-, 27-30 Nov. 2005 +doi: 10.1109/ICDM.2005.132 +Author : Sandro Vega-Pons, Emanuele Olivetti +Modified by : Jacques Fize +""" + +import networkx as nx +import numpy as np + + +class ShortestPathGraphKernel: + """ + Shorthest path graph kernel. + """ + __type__ = "sim" + @staticmethod + def compare( g_1, g_2, verbose=False): + """Compute the kernel value (similarity) between two graphs. + Parameters + ---------- + g1 : networkx.Graph + First graph. + g2 : networkx.Graph + Second graph. + Returns + ------- + k : The similarity value between g1 and g2. + """ + # Diagonal superior matrix of the floyd warshall shortest + # paths: + fwm1 = np.array(nx.floyd_warshall_numpy(g_1)) + fwm1 = np.where(fwm1 == np.inf, 0, fwm1) + fwm1 = np.where(fwm1 == np.nan, 0, fwm1) + fwm1 = np.triu(fwm1, k=1) + bc1 = np.bincount(fwm1.reshape(-1).astype(int)) + + fwm2 = np.array(nx.floyd_warshall_numpy(g_2)) + fwm2 = np.where(fwm2 == np.inf, 0, fwm2) + fwm2 = np.where(fwm2 == np.nan, 0, fwm2) + fwm2 = np.triu(fwm2, k=1) + bc2 = np.bincount(fwm2.reshape(-1).astype(int)) + + # Copy into arrays with the same length the non-zero shortests + # paths: + v1 = np.zeros(max(len(bc1), len(bc2)) - 1) + v1[range(0, len(bc1)-1)] = bc1[1:] + + v2 = np.zeros(max(len(bc1), len(bc2)) - 1) + v2[range(0, len(bc2)-1)] = bc2[1:] + + return np.sum(v1 * v2) + + + @staticmethod + def compare_list(graph_list, verbose=False): + """Compute the all-pairs kernel values for a list of graphs. + This function can be used to directly compute the kernel + matrix for a list of graphs. The direct computation of the + kernel matrix is faster than the computation of all individual + pairwise kernel values. + Parameters + ---------- + graph_list: list + A list of graphs (list of networkx graphs) + Return + ------ + K: numpy.array, shape = (len(graph_list), len(graph_list)) + The similarity matrix of all graphs in graph_list. + """ + n = len(graph_list) + k = np.zeros((n, n)) + for i in range(n): + for j in range(i, n): + k[i, j] = ShortestPathGraphKernel.compare(graph_list[i], graph_list[j]) + k[j, i] = k[i, j] + + k_norm = np.zeros(k.shape) + for i in range(k.shape[0]): + for j in range(k.shape[1]): + k_norm[i, j] = k[i, j] / np.sqrt(k[i, i] * k[j, j]) + + return k_norm \ No newline at end of file diff --git a/gmatch4py_old/kernels/weisfeiler_lehman.py b/gmatch4py_old/kernels/weisfeiler_lehman.py new file mode 100644 index 0000000..e7139c7 --- /dev/null +++ b/gmatch4py_old/kernels/weisfeiler_lehman.py @@ -0,0 +1,136 @@ +# coding = utf-8 + +"""Weisfeiler_Lehman graph kernel. + +Python implementation based on: "Weisfeiler-Lehman Graph Kernels", by: +Nino Shervashidze, Pascal Schweitzer, Erik J. van Leeuwen, Kurt +Mehlhorn, Karsten M. Borgwardt, JMLR, 2012. +http://jmlr.csail.mit.edu/papers/v12/shervashidze11a.html + +Author : Sandro Vega-Pons, Emanuele Olivetti +Source : https://github.com/emanuele/jstsp2015/blob/master/gk_weisfeiler_lehman.py +Modified by : Jacques Fizen +""" + +import copy + +import networkx as nx +import numpy as np + + +class WeisfeleirLehmanKernel(object): + __type__ = "sim" + @staticmethod + def compare(graph_list,h=2): + """Compute the all-pairs kernel values for a list of graphs. + This function can be used to directly compute the kernel + matrix for a list of graphs. The direct computation of the + kernel matrix is faster than the computation of all individual + pairwise kernel values. + Parameters + ---------- + graph_list: list + A list of graphs (list of networkx graphs) + h : interger + Number of iterations. + node_label : boolean + Whether to use original node labels. True for using node labels + saved in the attribute 'node_label'. False for using the node + degree of each node as node attribute. + Return + ------ + K: numpy.array, shape = (len(graph_list), len(graph_list)) + The similarity matrix of all graphs in graph_list. + """ + + n = len(graph_list) + k = [0] * (h + 1) + n_nodes = 0 + n_max = 0 + + # Compute adjacency lists and n_nodes, the total number of + # nodes in the dataset. + for i in range(n): + n_nodes += graph_list[i].number_of_nodes() + + # Computing the maximum number of nodes in the graphs. It + # will be used in the computation of vectorial + # representation. + if (n_max < graph_list[i].number_of_nodes()): + n_max = graph_list[i].number_of_nodes() + + phi = np.zeros((n_nodes, n), dtype=np.uint64) + + # INITIALIZATION: initialize the nodes labels for each graph + # with their labels or with degrees (for unlabeled graphs) + + labels = [0] * n + label_lookup = {} + label_counter = 0 + + # label_lookup is an associative array, which will contain the + # mapping from multiset labels (strings) to short labels + # (integers) + for i in range(n): + nodes = graph_list[i].nodes() + # It is assumed that the graph has an attribute + # 'node_label' + labels[i] = np.zeros(len(nodes), dtype=np.int32) + + for j in range(len(nodes)): + if not (nodes[j] in label_lookup): + label_lookup[nodes[j]] = str(label_counter) + labels[i][j] = label_counter + label_counter += 1 + else: + labels[i][j] = label_lookup[nodes[j]] + # labels are associated to a natural number + # starting with 0. + + phi[labels[i][j], i] += 1 + + graph_list[i]=nx.relabel_nodes(graph_list[i],label_lookup) + k = np.dot(phi.transpose(), phi).astype(np.float64) + + # MAIN LOOP + it = 0 + new_labels = copy.deepcopy(labels) # Can't work without it !!! + + while it < h: + # create an empty lookup table + label_lookup = {} + label_counter = 0 + + phi = np.zeros((n_nodes, n)) + for i in range(n): + nodes = graph_list[i].nodes() + for v in range(len(nodes)): + # form a multiset label of the node v of the i'th graph + # and convert it to a string + + long_label = [] + long_label.extend(nx.neighbors(graph_list[i],nodes[v])) + + long_label_string = "".join(long_label) + # if the multiset label has not yet occurred, add it to the + # lookup table and assign a number to it + if not (long_label_string in label_lookup): + label_lookup[long_label_string] = str(label_counter) + new_labels[i][v] = label_counter + label_counter += 1 + else: + new_labels[i][v] = label_lookup[long_label_string] + # fill the column for i'th graph in phi + aux = np.bincount(new_labels[i]) + phi[new_labels[i], i] += aux[new_labels[i]] + + k += np.dot(phi.transpose(), phi) + it = it + 1 + + # Compute the normalized version of the kernel + k_norm = np.zeros(k.shape) + for i in range(k.shape[0]): + for j in range(k.shape[1]): + k_norm[i, j] = k[i, j] / np.sqrt(k[i, i] * k[j, j]) + + return k_norm \ No newline at end of file diff --git a/gmatch4py_old/kernels/weisfeiler_lehman_edge.py b/gmatch4py_old/kernels/weisfeiler_lehman_edge.py new file mode 100644 index 0000000..367e099 --- /dev/null +++ b/gmatch4py_old/kernels/weisfeiler_lehman_edge.py @@ -0,0 +1,192 @@ +# coding = utf-8 + +# coding = utf-8# coding = utf-8 + +from helpers.gazeteer_helpers import get_data,get_data_by_wikidata_id + +# coding = utf-8 + +"""Weisfeiler_Lehman GEO graph kernel. + +""" + +import numpy as np +import networkx as nx +import copy + +class WeisfeleirLehmanKernelEdge(object): + __type__ = "sim" + + + @staticmethod + def compare(graph_list,h=3): + """Compute the all-pairs kernel values for a list of graphs. + This function can be used to directly compute the kernel + matrix for a list of graphs. The direct computation of the + kernel matrix is faster than the computation of all individual + pairwise kernel values. + Parameters + ---------- + graph_list: list + A list of graphs (list of networkx graphs) + h : interger + Number of iterations. + node_label : boolean + Whether to use original node labels. True for using node labels + saved in the attribute 'node_label'. False for using the node + degree of each node as node attribute. + Return + ------ + K: numpy.array, shape = (len(graph_list), len(graph_list)) + The similarity matrix of all graphs in graph_list. + """ + + n = len(graph_list) + k = [0] * (h + 1) + n_nodes = 0 + n_max = 0 + ams=[nx.adjacency_matrix(g).todense() for g in graph_list] + inclusion_dictionnary={} + + # Compute adjacency lists and n_nodes, the total number of + # nodes in the dataset. + for i in range(n): + n_nodes += graph_list[i].number_of_nodes() + + """ + Store Inclusion Informations + """ + for node in graph_list[i].nodes(): + graph_list[i].node[node]["id_GD"]=node + if not node in inclusion_dictionnary: + inc_list = [] + try: + inc_list = get_data(node)["inc_P131"] + except: + try: + inc_list=get_data_by_wikidata_id(get_data(node)["continent"])["id"] + except: + pass # No inclusion + if inc_list: + inc_list = inc_list if isinstance(inc_list,list) else [inc_list] + + inclusion_dictionnary[node]=inc_list[0] + for j in range(1,len(inc_list)): + if j+1 < len(inc_list): + inclusion_dictionnary[inc_list[j]]=inc_list[j+1] + + + + + # Computing the maximum number of nodes in the graphs. It + # will be used in the computation of vectorial + # representation. + if (n_max < graph_list[i].number_of_nodes()): + n_max = graph_list[i].number_of_nodes() + + phi = np.zeros((n_nodes, n), dtype=np.uint64) + #print(inclusion_dictionnary) + # INITIALIZATION: initialize the nodes labels for each graph + # with their labels or with degrees (for unlabeled graphs) + + labels = [0] * n + label_lookup = {} + label_counter = 0 + + # label_lookup is an associative array, which will contain the + # mapping from multiset labels (strings) to short labels + # (integers) + for i in range(n): + nodes = graph_list[i].nodes() + # It is assumed that the graph has an attribute + # 'node_label' + labels[i] = np.zeros(len(nodes), dtype=np.int32) + + for j in range(len(nodes)): + if not (nodes[j] in label_lookup): + label_lookup[nodes[j]] = str(label_counter) + labels[i][j] = label_counter + label_counter += 1 + else: + labels[i][j] = label_lookup[nodes[j]] + # labels are associated to a natural number + # starting with 0. + + phi[labels[i][j], i] += 1 + + graph_list[i]=nx.relabel_nodes(graph_list[i],label_lookup) + + L=label_counter + print("L1",L) + ed=np.zeros((np.int((L*(L+1))),n)) + # MAIN LOOP + it = 0 + new_labels = copy.deepcopy(labels) # Can't work without it !!! + + for i in range(n): + labels_aux = np.tile(new_labels[i].reshape(-1,1),len(new_labels[i])) + a=np.minimum(labels_aux,labels_aux.T) + b=np.maximum(labels_aux,np.transpose(labels_aux)) + I=np.triu((ams[i] !=0),1) + a_i=np.extract(I,a) + b_i = np.extract(I, b) + Ind=np.abs(np.multiply((a[I]-1),(2*L+2-a[I])/2+b[I]-a[I]+1).astype(int)) + minind=np.min(Ind) + aux=np.bincount(Ind) + ed[Ind,i]=aux[Ind] + + mask=np.sum(ed,1) !=0 + ed= ed[mask] + k=np.dot(ed.T,ed) + + it = 0 + new_labels = copy.deepcopy(new_labels) # Can't work without it !!! + + while it < h: + label_lookup={} + label_counter=0 + for i in range(n): + nodes = graph_list[i].nodes() + for v in range(len(nodes)): + # form a multiset label of the node v of the i'th graph + # and convert it to a string + + long_label = [] + long_label.extend(nx.neighbors(graph_list[i],nodes[v])) + + long_label_string = "".join(long_label) + # if the multiset label has not yet occurred, add it to the + # lookup table and assign a number to it + if not (long_label_string in label_lookup): + label_lookup[long_label_string] = str(label_counter) + new_labels[i][v] = label_counter + label_counter += 1 + else: + new_labels[i][v] = label_lookup[long_label_string] + + L = label_counter + print("L2",L) + ed = np.zeros((np.int((L * (L + 1))), n)) + for i in range(n): + labels_aux = np.tile(new_labels[i].reshape(-1, 1), len(new_labels[i])) + a = np.minimum(labels_aux, labels_aux.T) + b = np.maximum(labels_aux, np.transpose(labels_aux)) + I = np.triu((ams[i] != 0), 1) + a_i = np.extract(I, a) + b_i = np.extract(I, b) + Ind = np.abs(np.multiply((a[I] - 1), (2 * L + 2 - a[I]) / 2 + b[I] - a[I] + 1).astype(int)) + minind = np.min(Ind) + aux = np.bincount(Ind) + ed[Ind, i] = aux[Ind] + + mask = np.sum(ed, 1) != 0 + ed = ed[mask] + k += np.dot(ed.T, ed) + print(k) + it+=1 + k_norm = np.zeros(k.shape) + for i in range(k.shape[0]): + for j in range(k.shape[1]): + k_norm[i, j] = k[i, j] / np.sqrt(k[i, i] * k[j, j]) + + return k_norm \ No newline at end of file diff --git a/gmatch4py_old/kernels/weisfeiler_lehman_geo.py b/gmatch4py_old/kernels/weisfeiler_lehman_geo.py new file mode 100644 index 0000000..59c2b1b --- /dev/null +++ b/gmatch4py_old/kernels/weisfeiler_lehman_geo.py @@ -0,0 +1,165 @@ +# coding = utf-8 + +from helpers.gazeteer_helpers import get_data,get_data_by_wikidata_id + +# coding = utf-8 + +"""Weisfeiler_Lehman GEO graph kernel. + +""" + +import numpy as np +import networkx as nx +import copy + + +class WeisfeleirLehmanKernelGEO(object): + __type__ = "sim" + __depreciated__=True + + @staticmethod + def compare(graph_list,h=2,verbose=False): + """Compute the all-pairs kernel values for a list of graphs. + This function can be used to directly compute the kernel + matrix for a list of graphs. The direct computation of the + kernel matrix is faster than the computation of all individual + pairwise kernel values. + Parameters + ---------- + graph_list: list + A list of graphs (list of networkx graphs) + h : interger + Number of iterations. + node_label : boolean + Whether to use original node labels. True for using node labels + saved in the attribute 'node_label'. False for using the node + degree of each node as node attribute. + Return + ------ + K: numpy.array, shape = (len(graph_list), len(graph_list)) + The similarity matrix of all graphs in graph_list. + """ + + n = len(graph_list) + k = [0] * (h + 1) + n_nodes = 0 + n_max = 0 + + inclusion_dictionnary={} + + # Compute adjacency lists and n_nodes, the total number of + # nodes in the dataset. + for i in range(n): + n_nodes += graph_list[i].number_of_nodes() + + """ + Store Inclusion Informations + """ + for node in graph_list[i].nodes(): + graph_list[i].node[node]["id_GD"]=node + if not node in inclusion_dictionnary: + inc_list = [] + try: + inc_list = get_data(node)["inc_P131"] + except: + try: + inc_list=get_data_by_wikidata_id(get_data(node)["continent"])["id"] + except: + pass # No inclusion + if inc_list: + inc_list = inc_list if isinstance(inc_list,list) else [inc_list] + + inclusion_dictionnary[node]=inc_list[0] + for j in range(1,len(inc_list)): + if j+1 < len(inc_list): + inclusion_dictionnary[inc_list[j]]=inc_list[j+1] + + + + + # Computing the maximum number of nodes in the graphs. It + # will be used in the computation of vectorial + # representation. + if (n_max < graph_list[i].number_of_nodes()): + n_max = graph_list[i].number_of_nodes() + + phi = np.zeros((n_nodes, n), dtype=np.uint64) + if verbose: print(inclusion_dictionnary) + # INITIALIZATION: initialize the nodes labels for each graph + # with their labels or with degrees (for unlabeled graphs) + + labels = [0] * n + label_lookup = {} + label_counter = 0 + + # label_lookup is an associative array, which will contain the + # mapping from multiset labels (strings) to short labels + # (integers) + for i in range(n): + nodes = graph_list[i].nodes() + # It is assumed that the graph has an attribute + # 'node_label' + labels[i] = np.zeros(len(nodes), dtype=np.int32) + + for j in range(len(nodes)): + if not (nodes[j] in label_lookup): + label_lookup[nodes[j]] = str(label_counter) + labels[i][j] = label_counter + label_counter += 1 + else: + labels[i][j] = label_lookup[nodes[j]] + # labels are associated to a natural number + # starting with 0. + + phi[labels[i][j], i] += 1 + + graph_list[i]=nx.relabel_nodes(graph_list[i],label_lookup) + k = np.dot(phi.transpose(), phi).astype(np.float64) + + # MAIN LOOP + it = 0 + new_labels = copy.deepcopy(labels) # Can't work without it !!! + + while it < h: + # create an empty lookup table + label_lookup = {} + label_counter = 0 + + phi = np.zeros((n_nodes, n)) + for i in range(n): + nodes = graph_list[i].nodes() + for v in range(len(nodes)): + # form a multiset label of the node v of the i'th graph + # and convert it to a string + + id_GD = graph_list[i].node[nodes[v]]['id_GD'] + if id_GD in inclusion_dictionnary: + + long_label_string = inclusion_dictionnary[id_GD] + graph_list[i].node[nodes[v]]['id_GD']=inclusion_dictionnary[id_GD] + else: + long_label_string = id_GD + + + # if the multiset label has not yet occurred, add it to the + # lookup table and assign a number to it + if not (long_label_string in label_lookup): + label_lookup[long_label_string] = str(label_counter) + new_labels[i][v] = label_counter + label_counter += 1 + else: + new_labels[i][v] = label_lookup[long_label_string] + # fill the column for i'th graph in phi + aux = np.bincount(new_labels[i]) + phi[new_labels[i], i] += (1/(it+2))*aux[new_labels[i]] # +2 because it0 =0 + + k += np.dot(phi.transpose(), phi) + it = it + 1 + + # Compute the normalized version of the kernel + k_norm = np.zeros(k.shape) + for i in range(k.shape[0]): + for j in range(k.shape[1]): + k_norm[i, j] = k[i, j] / np.sqrt(k[i, i] * k[j, j]) + + return k_norm \ No newline at end of file diff --git a/gmatch4py/mcs.py b/gmatch4py_old/mcs.py similarity index 90% rename from gmatch4py/mcs.py rename to gmatch4py_old/mcs.py index 4b902a3..357507a 100644 --- a/gmatch4py/mcs.py +++ b/gmatch4py_old/mcs.py @@ -16,6 +16,10 @@ class MCS(): for j in range(i, n): g1 = listgs[i] g2 = listgs[j] + if not g1 or not g2: + comparison_matrix[i, j] = np.nan + comparison_matrix[j, i] = comparison_matrix[j, i] + continue if len(g1)== 0 or len(g2) == 0: continue comparison_matrix[i, j] = MCS.s_mcs(g1,g2) diff --git a/gmatch4py/utils.py b/gmatch4py_old/utils.py similarity index 100% rename from gmatch4py/utils.py rename to gmatch4py_old/utils.py diff --git a/gmatch4py/vertex_edge_overlap.py b/gmatch4py_old/vertex_edge_overlap.py similarity index 100% rename from gmatch4py/vertex_edge_overlap.py rename to gmatch4py_old/vertex_edge_overlap.py diff --git a/gmatch4py/vertex_ranking.py b/gmatch4py_old/vertex_ranking.py similarity index 100% rename from gmatch4py/vertex_ranking.py rename to gmatch4py_old/vertex_ranking.py diff --git a/gui_graph_viewer/server.py b/gui_graph_viewer/server.py index ab5db49..15f7076 100644 --- a/gui_graph_viewer/server.py +++ b/gui_graph_viewer/server.py @@ -67,8 +67,8 @@ def index(gmmeasure=None): max_={} min_={} for k,d_ in data.items(): - max_[int(k)]=d_["top_10"][-1]["score"] - min_[int(k)] = d_["top_10"][0]["score"] + max_[int(k)]=d_["topk"][-1]["score"] + min_[int(k)] = d_["topk"][0]["score"] if math.isnan(max_[int(k)]): max_[int(k)]=0.0 if math.isnan(min_[int(k)]): diff --git a/gui_graph_viewer/templates/index.html b/gui_graph_viewer/templates/index.html index 6ff9500..e404995 100644 --- a/gui_graph_viewer/templates/index.html +++ b/gui_graph_viewer/templates/index.html @@ -93,7 +93,7 @@ max_={{max |safe}}; min_={{min |safe}}; mainmap=generate_map("main_map",points,json[id]["edges"]); - var top_10=json[id]["top_10"]; + var top_10=json[id]["topk"]; $(".top10-item").remove(); var measure="{{measure |safe}}"; var rank=0; diff --git a/helpers/boundary.py b/helpers/boundary.py index 866736f..1c0222d 100644 --- a/helpers/boundary.py +++ b/helpers/boundary.py @@ -8,17 +8,40 @@ from helpers.gazeteer_helpers import get_data from scipy.spatial import ConvexHull from shapely.geometry import Polygon, Point, shape from config.configuration import config +from .collision_c import collide __collisions={} +def parseHull(hull_object,points): + hull=[] + for simplex in hull_object.simplices: + hull.append(points[simplex[0]]) + hull.append(points[simplex[1]]) + return hull + +def getConvexHull(path): + data=json.load(open(os.path.join(config.osm_boundaries_directory,path))) + boundaries=data["geometry"]["coordinates"] + if data["geometry"]["type"]== "Polygon": + hull = parseHull(ConvexHull(boundaries[-1]),boundaries[-1]) + return [hull] + else: + hull=[] + for bound in boundaries[-1]: + hull.append(parseHull(ConvexHull(bound),bound)) + return hull + def get_all_shapes(ids_list): shapes = {} for p in ids_list: d = get_data(p) + #print(d["path"]) if "path" in d: - shapes[p] = shape(json.load(open(config.osm_boundaries_directory + "/" + d["path"]))["geometry"]) + #shapes[p] = shape(json.load(open(config.osm_boundaries_directory + "/" + d["path"]))["geometry"]) + shapes[p] = getConvexHull(config.osm_boundaries_directory + "/" + d["path"])[0] elif "coord" in d: - shapes[p] = Point([d["coord"]["lat"], d["coord"]["lon"]]) + #shapes[p] = Point([d["coord"]["lat"], d["coord"]["lon"]]) + shapes[p] = [[d["coord"]["lat"], d["coord"]["lon"]]] return shapes def get_adjacency_relationships(shapes): @@ -28,10 +51,10 @@ def get_adjacency_relationships(shapes): if s != s2: if not s in collisions and s2 in collisions: if not s in collisions[s2]: - collisions[s2][s]=shapes[s2].convex_hull.intersects(shapes[s].convex_hull) + collisions[s2][s]=collide(shapes[s],shapes[s2])#shapes[s2].convex_hull.intersects(shapes[s].convex_hull) elif not s2 in collisions and s in collisions: if not s2 in collisions[s]: - collisions[s][s2]=shapes[s].convex_hull.intersects(shapes[s2].convex_hull) + collisions[s][s2]=collide(shapes[s],shapes[s2])#shapes[s].convex_hull.intersects(shapes[s2].convex_hull) return collisions def is_intersect(id1,id2,shapes): @@ -47,7 +70,7 @@ def is_intersect(id1,id2,shapes): if id1 in shapes and id2 in shapes: if not id1 in __collisions:__collisions[id1]={} if not id2 in __collisions: __collisions[id2] = {} - __collisions[id1][id2]=shapes[id1].convex_hull.intersects(shapes[id2].convex_hull) + __collisions[id1][id2]=collide(shapes[id1],shapes[id2]) __collisions[id2][id1]=__collisions[id1][id2] return __collisions[id1][id2] else: diff --git a/helpers/collision_c.pyx b/helpers/collision_c.pyx new file mode 100644 index 0000000..8df40d5 --- /dev/null +++ b/helpers/collision_c.pyx @@ -0,0 +1,99 @@ +import numpy as np +cimport numpy as np + +ctypedef np.ndarray numpy_array # for return np array +""" +Source : https://hackmd.io/s/ryFmIZrsl# +""" +cdef is_separating_axis(o, list p1, list p2): + """ + Return True and the push vector if o is a separating axis of p1 and p2. + Otherwise, return False and None. + """ + cdef float min1,max1,min2,max2 + cdef np.float_t projection + min1, max1 = float('+inf'), float('-inf') + min2, max2 = float('+inf'), float('-inf') + + for v in p1: + projection = np.dot(v, o) + + min1 = min(min1, projection) + max1 = max(max1, projection) + + for v in p2: + projection = np.dot(v, o) + + min2 = min(min2, projection) + max2 = max(max2, projection) + + if max1 >= min2 and max2 >= min1: + d = min(max2 - min1, max1 - min2) + # push a bit more than needed so the shapes do not overlap in future + # tests due to float precision + d_over_o_squared = d/np.dot(o, o) + 1e-10 + pv = d_over_o_squared*o + return False, pv + else: + return True, None + + +cdef list edges_of(list vertices): + """ + Return the vectors for the edges of the polygon p. + + p is a polygon. + """ + cdef list edges = [] + cdef int N = len(vertices) + + for i in range(N): + edge = vertices[(i + 1)%N] - vertices[i] + edges.append(edge) + + return edges + +cdef numpy_array orthogonal(v): + """ + Return a 90 degree clockwise rotation of the vector v. + """ + return np.array([-v[1], v[0]]) + + +def collide(p1, p2): + ''' + Return True and the MPV if the shapes collide. Otherwise, return False and + None. + + p1 and p2 are lists of ordered pairs, the vertices of the polygons in the + counterclockwise direction. + ''' + + p1 = [np.array(v, 'float64') for v in p1] + p2 = [np.array(v, 'float64') for v in p2] + cdef list edges + edges = edges_of(p1) + edges += edges_of(p2) + orthogonals = [orthogonal(e) for e in edges] + + cdef push_vectors = [] + for o in orthogonals: + separates, pv = is_separating_axis(o, p1, p2) + + if separates: + # they do not collide and there is no push vector + return False + else: + push_vectors.append(pv) + + return True + + +cdef float centers_displacement(p1, p2): + """ + Return the displacement between the geometric center of p1 and p2. + """ + # geometric center + c1 = np.mean(np.array(p1), axis=0) + c2 = np.mean(np.array(p2), axis=0) + return c2 - c1 \ No newline at end of file diff --git a/helpers/collision_with_gazetteer_data.py b/helpers/collision_with_gazetteer_data.py index 2857020..9cc8aff 100644 --- a/helpers/collision_with_gazetteer_data.py +++ b/helpers/collision_with_gazetteer_data.py @@ -7,7 +7,7 @@ from shapely.geometry import Polygon, Point, shape from config.configuration import config from helpers.gazeteer_helpers import get_data -from .collision import collide +from .collision_c import collide __cache={} __cache_adjacency={} @@ -77,7 +77,7 @@ def collisionTwoSEBoundaries(id_SE1,id_SE2): for h1 in hull_1: for h2 in hull_2: - if collide(h1,h2)[0] and not include_in(h1,h2): + if collide(h1,h2) and not include_in(h1,h2): __cache_adjacency[id_SE1][id_SE2] = True return True __cache_adjacency[id_SE1][id_SE2]=False diff --git a/helpers/gazeteer_helpers.py b/helpers/gazeteer_helpers.py index 6de2bb1..be39e22 100644 --- a/helpers/gazeteer_helpers.py +++ b/helpers/gazeteer_helpers.py @@ -168,4 +168,18 @@ def get_most_common_id_v3(label,lang='fr'): return id_,score return None,-1 +def count_of_se(label, lang): + query = {"query": {"bool": {"must": [{"term": {lang: label}}], "must_not": [], "should": []}}} + response = es.count('gazetteer', 'place', body=query) + return response["count"] + + +def get_most_most_probable_candidates(label, lang="fr",n=5): + res = es.search("gazetteer", "place", + body={"query":{"bool":{"must":[{"fuzzy":{lang:{"value":label}}}],"must_not":[],"should":[]}},"from":0,"size":n,"sort": [{'score':"desc"}],"aggs":{}}) + results=[] + if res["hits"]["total"] > 0: + for hit in res["hits"]["hits"]: + results.append(hit["_source"]) + return results diff --git a/models/str.py b/models/str.py index ce3b777..88eef86 100644 --- a/models/str.py +++ b/models/str.py @@ -81,6 +81,7 @@ class STR(object): sp_en[id_] = label str_ = STR(tagged_, sp_en, shapes) + str_.build() return str_ @staticmethod @@ -256,12 +257,12 @@ class STR(object): if se1 in p47se2: f = True if not f: - if not self.shapes: - if collisionTwoSEBoundaries(se1, se2): - f = True - else: - if is_intersect(se1, se2, self.shapes): - f = True + #if not self.shapes: + if collisionTwoSEBoundaries(se1, se2): + f = True + #else: + #if is_intersect(se1, se2, self.shapes): + #f = True self.add_adjacency_rel(se1, se2,f) @@ -333,3 +334,5 @@ class STR(object): self.add_adjacency_rel(edge[0],edge[1]) elif edge[2]["color"] == "red": self.add_inclusion_rel(edge[0], edge[1]) + def set_all_shapes(self,shapes): + self.shapes=shapes diff --git a/nlp/disambiguator/models/__init__.py b/nlp/disambiguator/models/__init__.py new file mode 100644 index 0000000..950f635 --- /dev/null +++ b/nlp/disambiguator/models/__init__.py @@ -0,0 +1 @@ +# coding = utf-8 \ No newline at end of file diff --git a/nlp/disambiguator/models/bigram.py b/nlp/disambiguator/models/bigram.py new file mode 100644 index 0000000..aa50f70 --- /dev/null +++ b/nlp/disambiguator/models/bigram.py @@ -0,0 +1,41 @@ +# coding = utf-8 + +class BigramModel: + def __init__(self,freq={},count={}): + self.cooc_freq=freq + self.count_associated=count + + def append(self,uri1,uri2): + + if not uri1 in self.cooc_freq: + self.cooc_freq[uri1]={} + if not uri2 in self.cooc_freq[uri1]: + self.cooc_freq[uri1][uri2]=0 + self.cooc_freq[uri1][uri2]+=1 + + self.increment_count(uri2) + + def increment_count(self,uri): + if not uri in self.count_associated: + self.count_associated[uri]=0 + self.count_associated[uri]+=1 + + def get_coocurence_probability_dict(self,*args): + if len(args) <2: + print("Only one URI indicated") + return 0. + res_=1. + for u in range(1,len(args)): + res_*=self.get_bigram_probability(args[0],args[u]) + return res_ + + + def get_bigram_probability(self,uri1,uri2): + try: + return (self.cooc_freq[uri1][uri2] / self.count_associated[uri1]) + except Exception as e: + try: + return (self.cooc_freq[uri2][uri1] / self.count_associated[uri1]) + except Exception as e: + return 0.00000000000000001 + diff --git a/nlp/disambiguator/most_common.py b/nlp/disambiguator/most_common.py index affd138..30be9af 100644 --- a/nlp/disambiguator/most_common.py +++ b/nlp/disambiguator/most_common.py @@ -29,7 +29,7 @@ class MostCommonDisambiguator(Disambiguator): selected_en = {} for en in se_: id_,score=self.disambiguate_(en,lang) - if not id_ =="O": + if not id_ =="O" and id_: selected_en[id_] = en new_count[id_] = count[en] @@ -38,7 +38,7 @@ class MostCommonDisambiguator(Disambiguator): def disambiguate_(self, label, lang='fr'): if re.match("^\d+$", label): return 'O', -1 - if label.lower() in stop_words[lang] or label.lower() in common_words[lang]: + if label.lower().rstrip("s") in stop_words[lang] or label.lower().rstrip("s") in common_words[lang]: return 'O', -1 plural = label.rstrip("s") + "s" @@ -55,5 +55,5 @@ class MostCommonDisambiguator(Disambiguator): if id_alias and score_alias: if score_alias > score: id_, score = id_alias, score_alias - + print(label,id_,score) return id_, score diff --git a/nlp/disambiguator/wikipedia_cooc.py b/nlp/disambiguator/wikipedia_cooc.py new file mode 100644 index 0000000..d441218 --- /dev/null +++ b/nlp/disambiguator/wikipedia_cooc.py @@ -0,0 +1,45 @@ +# coding = utf-8 +from nlp.disambiguator.disambiguator import Disambiguator +from nlp.disambiguator.models.bigram import BigramModel +import pickle +from config.configuration import config +from helpers.gazeteer_helpers import get_data,count_of_se,get_most_common_id_v3 +from .most_common import stop_words,common_words + +def read_pickle(fn): + return pickle.load(open(fn,'rb')) + +class WikipediaDisambiguator(Disambiguator): + + def __init__(self): + Disambiguator.__init__(self) + # Load model + self.model=BigramModel(read_pickle(config.wiki_cooc_dis.cooc_freq),read_pickle(config.wiki_cooc_dis.count)) + + def disambiguate(self, ner_result, lang="en"): + count, se_ = self.extract_se_entities(ner_result) + new_count = {} + selected_en = {} + fixed_se=set([]) + for en in se_: + if count_of_se(en,lang) == 1 : + fixed_se.add(en) + if len(fixed_se) >0: + selected_en = self.part_ambiguous(list(set(se_)-fixed_se),list(fixed_se)) + else: + selected_en = self.all_ambiguous(se_) + for en in se_: + id_,score=self.disambiguate_(en,lang) + if not id_ =="O" and id_: + selected_en[id_] = en + new_count[id_] = count[en] + + return new_count, selected_en + + + + def all_ambiguous(self,entities): + pass + + def part_ambiguous(self,ambiguous_entities,fixed_entities): + pass \ No newline at end of file diff --git a/notebooks/Cython Enhancement on HED.ipynb b/notebooks/Cython Enhancement on HED.ipynb index b651169..da3d156 100644 --- a/notebooks/Cython Enhancement on HED.ipynb +++ b/notebooks/Cython Enhancement on HED.ipynb @@ -5,8 +5,8 @@ "execution_count": 1, "metadata": { "ExecuteTime": { - "end_time": "2018-04-20T07:03:06.266539Z", - "start_time": "2018-04-20T07:03:05.937225Z" + "end_time": "2018-05-23T21:50:39.883856Z", + "start_time": "2018-05-23T21:50:39.493652Z" } }, "outputs": [], @@ -16,500 +16,41 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 10, "metadata": { "ExecuteTime": { - "end_time": "2018-04-20T07:03:06.281912Z", - "start_time": "2018-04-20T07:03:06.268809Z" + "end_time": "2018-05-23T21:54:10.988353Z", + "start_time": "2018-05-23T21:54:10.406034Z" } }, "outputs": [ { - "data": { - "text/html": [ - "<!DOCTYPE html>\n", - "<!-- Generated by Cython 0.25.2 -->\n", - "<html>\n", - "<head>\n", - " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n", - " <title>Cython: _cython_magic_fcaa11e6595f50de5667d45b47247f97.pyx</title>\n", - " <style type=\"text/css\">\n", - " \n", - "body.cython { font-family: courier; font-size: 12; }\n", - "\n", - ".cython.tag { }\n", - ".cython.line { margin: 0em }\n", - ".cython.code { font-size: 9; color: #444444; display: none; margin: 0px 0px 0px 8px; border-left: 8px none; }\n", - "\n", - ".cython.line .run { background-color: #B0FFB0; }\n", - ".cython.line .mis { background-color: #FFB0B0; }\n", - ".cython.code.run { border-left: 8px solid #B0FFB0; }\n", - ".cython.code.mis { border-left: 8px solid #FFB0B0; }\n", - "\n", - ".cython.code .py_c_api { color: red; }\n", - ".cython.code .py_macro_api { color: #FF7000; }\n", - ".cython.code .pyx_c_api { color: #FF3000; }\n", - ".cython.code .pyx_macro_api { color: #FF7000; }\n", - ".cython.code .refnanny { color: #FFA000; }\n", - ".cython.code .trace { color: #FFA000; }\n", - ".cython.code .error_goto { color: #FFA000; }\n", - "\n", - ".cython.code .coerce { color: #008000; border: 1px dotted #008000 }\n", - ".cython.code .py_attr { color: #FF0000; font-weight: bold; }\n", - ".cython.code .c_attr { color: #0000FF; }\n", - ".cython.code .py_call { color: #FF0000; font-weight: bold; }\n", - ".cython.code .c_call { color: #0000FF; }\n", - "\n", - ".cython.score-0 {background-color: #FFFFff;}\n", - ".cython.score-1 {background-color: #FFFFe7;}\n", - ".cython.score-2 {background-color: #FFFFd4;}\n", - ".cython.score-3 {background-color: #FFFFc4;}\n", - ".cython.score-4 {background-color: #FFFFb6;}\n", - ".cython.score-5 {background-color: #FFFFaa;}\n", - ".cython.score-6 {background-color: #FFFF9f;}\n", - ".cython.score-7 {background-color: #FFFF96;}\n", - ".cython.score-8 {background-color: #FFFF8d;}\n", - ".cython.score-9 {background-color: #FFFF86;}\n", - ".cython.score-10 {background-color: #FFFF7f;}\n", - ".cython.score-11 {background-color: #FFFF79;}\n", - ".cython.score-12 {background-color: #FFFF73;}\n", - ".cython.score-13 {background-color: #FFFF6e;}\n", - ".cython.score-14 {background-color: #FFFF6a;}\n", - ".cython.score-15 {background-color: #FFFF66;}\n", - ".cython.score-16 {background-color: #FFFF62;}\n", - ".cython.score-17 {background-color: #FFFF5e;}\n", - ".cython.score-18 {background-color: #FFFF5b;}\n", - ".cython.score-19 {background-color: #FFFF57;}\n", - ".cython.score-20 {background-color: #FFFF55;}\n", - ".cython.score-21 {background-color: #FFFF52;}\n", - ".cython.score-22 {background-color: #FFFF4f;}\n", - ".cython.score-23 {background-color: #FFFF4d;}\n", - ".cython.score-24 {background-color: #FFFF4b;}\n", - ".cython.score-25 {background-color: #FFFF48;}\n", - ".cython.score-26 {background-color: #FFFF46;}\n", - ".cython.score-27 {background-color: #FFFF44;}\n", - ".cython.score-28 {background-color: #FFFF43;}\n", - ".cython.score-29 {background-color: #FFFF41;}\n", - ".cython.score-30 {background-color: #FFFF3f;}\n", - ".cython.score-31 {background-color: #FFFF3e;}\n", - ".cython.score-32 {background-color: #FFFF3c;}\n", - ".cython.score-33 {background-color: #FFFF3b;}\n", - ".cython.score-34 {background-color: #FFFF39;}\n", - ".cython.score-35 {background-color: #FFFF38;}\n", - ".cython.score-36 {background-color: #FFFF37;}\n", - ".cython.score-37 {background-color: #FFFF36;}\n", - ".cython.score-38 {background-color: #FFFF35;}\n", - ".cython.score-39 {background-color: #FFFF34;}\n", - ".cython.score-40 {background-color: #FFFF33;}\n", - ".cython.score-41 {background-color: #FFFF32;}\n", - ".cython.score-42 {background-color: #FFFF31;}\n", - ".cython.score-43 {background-color: #FFFF30;}\n", - ".cython.score-44 {background-color: #FFFF2f;}\n", - ".cython.score-45 {background-color: #FFFF2e;}\n", - ".cython.score-46 {background-color: #FFFF2d;}\n", - ".cython.score-47 {background-color: #FFFF2c;}\n", - ".cython.score-48 {background-color: #FFFF2b;}\n", - ".cython.score-49 {background-color: #FFFF2b;}\n", - ".cython.score-50 {background-color: #FFFF2a;}\n", - ".cython.score-51 {background-color: #FFFF29;}\n", - ".cython.score-52 {background-color: #FFFF29;}\n", - ".cython.score-53 {background-color: #FFFF28;}\n", - ".cython.score-54 {background-color: #FFFF27;}\n", - ".cython.score-55 {background-color: #FFFF27;}\n", - ".cython.score-56 {background-color: #FFFF26;}\n", - ".cython.score-57 {background-color: #FFFF26;}\n", - ".cython.score-58 {background-color: #FFFF25;}\n", - ".cython.score-59 {background-color: #FFFF24;}\n", - ".cython.score-60 {background-color: #FFFF24;}\n", - ".cython.score-61 {background-color: #FFFF23;}\n", - ".cython.score-62 {background-color: #FFFF23;}\n", - ".cython.score-63 {background-color: #FFFF22;}\n", - ".cython.score-64 {background-color: #FFFF22;}\n", - ".cython.score-65 {background-color: #FFFF22;}\n", - ".cython.score-66 {background-color: #FFFF21;}\n", - ".cython.score-67 {background-color: #FFFF21;}\n", - ".cython.score-68 {background-color: #FFFF20;}\n", - ".cython.score-69 {background-color: #FFFF20;}\n", - ".cython.score-70 {background-color: #FFFF1f;}\n", - ".cython.score-71 {background-color: #FFFF1f;}\n", - ".cython.score-72 {background-color: #FFFF1f;}\n", - ".cython.score-73 {background-color: #FFFF1e;}\n", - ".cython.score-74 {background-color: #FFFF1e;}\n", - ".cython.score-75 {background-color: #FFFF1e;}\n", - ".cython.score-76 {background-color: #FFFF1d;}\n", - ".cython.score-77 {background-color: #FFFF1d;}\n", - ".cython.score-78 {background-color: #FFFF1c;}\n", - ".cython.score-79 {background-color: #FFFF1c;}\n", - ".cython.score-80 {background-color: #FFFF1c;}\n", - ".cython.score-81 {background-color: #FFFF1c;}\n", - ".cython.score-82 {background-color: #FFFF1b;}\n", - ".cython.score-83 {background-color: #FFFF1b;}\n", - ".cython.score-84 {background-color: #FFFF1b;}\n", - ".cython.score-85 {background-color: #FFFF1a;}\n", - ".cython.score-86 {background-color: #FFFF1a;}\n", - ".cython.score-87 {background-color: #FFFF1a;}\n", - ".cython.score-88 {background-color: #FFFF1a;}\n", - ".cython.score-89 {background-color: #FFFF19;}\n", - ".cython.score-90 {background-color: #FFFF19;}\n", - ".cython.score-91 {background-color: #FFFF19;}\n", - ".cython.score-92 {background-color: #FFFF19;}\n", - ".cython.score-93 {background-color: #FFFF18;}\n", - ".cython.score-94 {background-color: #FFFF18;}\n", - ".cython.score-95 {background-color: #FFFF18;}\n", - ".cython.score-96 {background-color: #FFFF18;}\n", - ".cython.score-97 {background-color: #FFFF17;}\n", - ".cython.score-98 {background-color: #FFFF17;}\n", - ".cython.score-99 {background-color: #FFFF17;}\n", - ".cython.score-100 {background-color: #FFFF17;}\n", - ".cython.score-101 {background-color: #FFFF16;}\n", - ".cython.score-102 {background-color: #FFFF16;}\n", - ".cython.score-103 {background-color: #FFFF16;}\n", - ".cython.score-104 {background-color: #FFFF16;}\n", - ".cython.score-105 {background-color: #FFFF16;}\n", - ".cython.score-106 {background-color: #FFFF15;}\n", - ".cython.score-107 {background-color: #FFFF15;}\n", - ".cython.score-108 {background-color: #FFFF15;}\n", - ".cython.score-109 {background-color: #FFFF15;}\n", - ".cython.score-110 {background-color: #FFFF15;}\n", - ".cython.score-111 {background-color: #FFFF15;}\n", - ".cython.score-112 {background-color: #FFFF14;}\n", - ".cython.score-113 {background-color: #FFFF14;}\n", - ".cython.score-114 {background-color: #FFFF14;}\n", - ".cython.score-115 {background-color: #FFFF14;}\n", - ".cython.score-116 {background-color: #FFFF14;}\n", - ".cython.score-117 {background-color: #FFFF14;}\n", - ".cython.score-118 {background-color: #FFFF13;}\n", - ".cython.score-119 {background-color: #FFFF13;}\n", - ".cython.score-120 {background-color: #FFFF13;}\n", - ".cython.score-121 {background-color: #FFFF13;}\n", - ".cython.score-122 {background-color: #FFFF13;}\n", - ".cython.score-123 {background-color: #FFFF13;}\n", - ".cython.score-124 {background-color: #FFFF13;}\n", - ".cython.score-125 {background-color: #FFFF12;}\n", - ".cython.score-126 {background-color: #FFFF12;}\n", - ".cython.score-127 {background-color: #FFFF12;}\n", - ".cython.score-128 {background-color: #FFFF12;}\n", - ".cython.score-129 {background-color: #FFFF12;}\n", - ".cython.score-130 {background-color: #FFFF12;}\n", - ".cython.score-131 {background-color: #FFFF12;}\n", - ".cython.score-132 {background-color: #FFFF11;}\n", - ".cython.score-133 {background-color: #FFFF11;}\n", - ".cython.score-134 {background-color: #FFFF11;}\n", - ".cython.score-135 {background-color: #FFFF11;}\n", - ".cython.score-136 {background-color: #FFFF11;}\n", - ".cython.score-137 {background-color: #FFFF11;}\n", - ".cython.score-138 {background-color: #FFFF11;}\n", - ".cython.score-139 {background-color: #FFFF11;}\n", - ".cython.score-140 {background-color: #FFFF11;}\n", - ".cython.score-141 {background-color: #FFFF10;}\n", - ".cython.score-142 {background-color: #FFFF10;}\n", - ".cython.score-143 {background-color: #FFFF10;}\n", - ".cython.score-144 {background-color: #FFFF10;}\n", - ".cython.score-145 {background-color: #FFFF10;}\n", - ".cython.score-146 {background-color: #FFFF10;}\n", - ".cython.score-147 {background-color: #FFFF10;}\n", - ".cython.score-148 {background-color: #FFFF10;}\n", - ".cython.score-149 {background-color: #FFFF10;}\n", - ".cython.score-150 {background-color: #FFFF0f;}\n", - ".cython.score-151 {background-color: #FFFF0f;}\n", - ".cython.score-152 {background-color: #FFFF0f;}\n", - ".cython.score-153 {background-color: #FFFF0f;}\n", - ".cython.score-154 {background-color: #FFFF0f;}\n", - ".cython.score-155 {background-color: #FFFF0f;}\n", - ".cython.score-156 {background-color: #FFFF0f;}\n", - ".cython.score-157 {background-color: #FFFF0f;}\n", - ".cython.score-158 {background-color: #FFFF0f;}\n", - ".cython.score-159 {background-color: #FFFF0f;}\n", - ".cython.score-160 {background-color: #FFFF0f;}\n", - ".cython.score-161 {background-color: #FFFF0e;}\n", - ".cython.score-162 {background-color: #FFFF0e;}\n", - ".cython.score-163 {background-color: #FFFF0e;}\n", - ".cython.score-164 {background-color: #FFFF0e;}\n", - ".cython.score-165 {background-color: #FFFF0e;}\n", - ".cython.score-166 {background-color: #FFFF0e;}\n", - ".cython.score-167 {background-color: #FFFF0e;}\n", - ".cython.score-168 {background-color: #FFFF0e;}\n", - ".cython.score-169 {background-color: #FFFF0e;}\n", - ".cython.score-170 {background-color: #FFFF0e;}\n", - ".cython.score-171 {background-color: #FFFF0e;}\n", - ".cython.score-172 {background-color: #FFFF0e;}\n", - ".cython.score-173 {background-color: #FFFF0d;}\n", - ".cython.score-174 {background-color: #FFFF0d;}\n", - ".cython.score-175 {background-color: #FFFF0d;}\n", - ".cython.score-176 {background-color: #FFFF0d;}\n", - ".cython.score-177 {background-color: #FFFF0d;}\n", - ".cython.score-178 {background-color: #FFFF0d;}\n", - ".cython.score-179 {background-color: #FFFF0d;}\n", - ".cython.score-180 {background-color: #FFFF0d;}\n", - ".cython.score-181 {background-color: #FFFF0d;}\n", - ".cython.score-182 {background-color: #FFFF0d;}\n", - ".cython.score-183 {background-color: #FFFF0d;}\n", - ".cython.score-184 {background-color: #FFFF0d;}\n", - ".cython.score-185 {background-color: #FFFF0d;}\n", - ".cython.score-186 {background-color: #FFFF0d;}\n", - ".cython.score-187 {background-color: #FFFF0c;}\n", - ".cython.score-188 {background-color: #FFFF0c;}\n", - ".cython.score-189 {background-color: #FFFF0c;}\n", - ".cython.score-190 {background-color: #FFFF0c;}\n", - ".cython.score-191 {background-color: #FFFF0c;}\n", - ".cython.score-192 {background-color: #FFFF0c;}\n", - ".cython.score-193 {background-color: #FFFF0c;}\n", - ".cython.score-194 {background-color: #FFFF0c;}\n", - ".cython.score-195 {background-color: #FFFF0c;}\n", - ".cython.score-196 {background-color: #FFFF0c;}\n", - ".cython.score-197 {background-color: #FFFF0c;}\n", - ".cython.score-198 {background-color: #FFFF0c;}\n", - ".cython.score-199 {background-color: #FFFF0c;}\n", - ".cython.score-200 {background-color: #FFFF0c;}\n", - ".cython.score-201 {background-color: #FFFF0c;}\n", - ".cython.score-202 {background-color: #FFFF0c;}\n", - ".cython.score-203 {background-color: #FFFF0b;}\n", - ".cython.score-204 {background-color: #FFFF0b;}\n", - ".cython.score-205 {background-color: #FFFF0b;}\n", - ".cython.score-206 {background-color: #FFFF0b;}\n", - ".cython.score-207 {background-color: #FFFF0b;}\n", - ".cython.score-208 {background-color: #FFFF0b;}\n", - ".cython.score-209 {background-color: #FFFF0b;}\n", - ".cython.score-210 {background-color: #FFFF0b;}\n", - ".cython.score-211 {background-color: #FFFF0b;}\n", - ".cython.score-212 {background-color: #FFFF0b;}\n", - ".cython.score-213 {background-color: #FFFF0b;}\n", - ".cython.score-214 {background-color: #FFFF0b;}\n", - ".cython.score-215 {background-color: #FFFF0b;}\n", - ".cython.score-216 {background-color: #FFFF0b;}\n", - ".cython.score-217 {background-color: #FFFF0b;}\n", - ".cython.score-218 {background-color: #FFFF0b;}\n", - ".cython.score-219 {background-color: #FFFF0b;}\n", - ".cython.score-220 {background-color: #FFFF0b;}\n", - ".cython.score-221 {background-color: #FFFF0b;}\n", - ".cython.score-222 {background-color: #FFFF0a;}\n", - ".cython.score-223 {background-color: #FFFF0a;}\n", - ".cython.score-224 {background-color: #FFFF0a;}\n", - ".cython.score-225 {background-color: #FFFF0a;}\n", - ".cython.score-226 {background-color: #FFFF0a;}\n", - ".cython.score-227 {background-color: #FFFF0a;}\n", - ".cython.score-228 {background-color: #FFFF0a;}\n", - ".cython.score-229 {background-color: #FFFF0a;}\n", - ".cython.score-230 {background-color: #FFFF0a;}\n", - ".cython.score-231 {background-color: #FFFF0a;}\n", - ".cython.score-232 {background-color: #FFFF0a;}\n", - ".cython.score-233 {background-color: #FFFF0a;}\n", - ".cython.score-234 {background-color: #FFFF0a;}\n", - ".cython.score-235 {background-color: #FFFF0a;}\n", - ".cython.score-236 {background-color: #FFFF0a;}\n", - ".cython.score-237 {background-color: #FFFF0a;}\n", - ".cython.score-238 {background-color: #FFFF0a;}\n", - ".cython.score-239 {background-color: #FFFF0a;}\n", - ".cython.score-240 {background-color: #FFFF0a;}\n", - ".cython.score-241 {background-color: #FFFF0a;}\n", - ".cython.score-242 {background-color: #FFFF0a;}\n", - ".cython.score-243 {background-color: #FFFF0a;}\n", - ".cython.score-244 {background-color: #FFFF0a;}\n", - ".cython.score-245 {background-color: #FFFF0a;}\n", - ".cython.score-246 {background-color: #FFFF09;}\n", - ".cython.score-247 {background-color: #FFFF09;}\n", - ".cython.score-248 {background-color: #FFFF09;}\n", - ".cython.score-249 {background-color: #FFFF09;}\n", - ".cython.score-250 {background-color: #FFFF09;}\n", - ".cython.score-251 {background-color: #FFFF09;}\n", - ".cython.score-252 {background-color: #FFFF09;}\n", - ".cython.score-253 {background-color: #FFFF09;}\n", - ".cython.score-254 {background-color: #FFFF09;}\n", - ".cython .hll { background-color: #ffffcc }\n", - ".cython { background: #f8f8f8; }\n", - ".cython .c { color: #408080; font-style: italic } /* Comment */\n", - ".cython .err { border: 1px solid #FF0000 } /* Error */\n", - ".cython .k { color: #008000; font-weight: bold } /* Keyword */\n", - ".cython .o { color: #666666 } /* Operator */\n", - ".cython .ch { color: #408080; font-style: italic } /* Comment.Hashbang */\n", - ".cython .cm { color: #408080; font-style: italic } /* Comment.Multiline */\n", - ".cython .cp { color: #BC7A00 } /* Comment.Preproc */\n", - ".cython .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */\n", - ".cython .c1 { color: #408080; font-style: italic } /* Comment.Single */\n", - ".cython .cs { color: #408080; font-style: italic } /* Comment.Special */\n", - ".cython .gd { color: #A00000 } /* Generic.Deleted */\n", - ".cython .ge { font-style: italic } /* Generic.Emph */\n", - ".cython .gr { color: #FF0000 } /* Generic.Error */\n", - ".cython .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n", - ".cython .gi { color: #00A000 } /* Generic.Inserted */\n", - ".cython .go { color: #888888 } /* Generic.Output */\n", - ".cython .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n", - ".cython .gs { font-weight: bold } /* Generic.Strong */\n", - ".cython .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n", - ".cython .gt { color: #0044DD } /* Generic.Traceback */\n", - ".cython .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n", - ".cython .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n", - ".cython .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n", - ".cython .kp { color: #008000 } /* Keyword.Pseudo */\n", - ".cython .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n", - ".cython .kt { color: #B00040 } /* Keyword.Type */\n", - ".cython .m { color: #666666 } /* Literal.Number */\n", - ".cython .s { color: #BA2121 } /* Literal.String */\n", - ".cython .na { color: #7D9029 } /* Name.Attribute */\n", - ".cython .nb { color: #008000 } /* Name.Builtin */\n", - ".cython .nc { color: #0000FF; font-weight: bold } /* Name.Class */\n", - ".cython .no { color: #880000 } /* Name.Constant */\n", - ".cython .nd { color: #AA22FF } /* Name.Decorator */\n", - ".cython .ni { color: #999999; font-weight: bold } /* Name.Entity */\n", - ".cython .ne { color: #D2413A; font-weight: bold } /* Name.Exception */\n", - ".cython .nf { color: #0000FF } /* Name.Function */\n", - ".cython .nl { color: #A0A000 } /* Name.Label */\n", - ".cython .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */\n", - ".cython .nt { color: #008000; font-weight: bold } /* Name.Tag */\n", - ".cython .nv { color: #19177C } /* Name.Variable */\n", - ".cython .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */\n", - ".cython .w { color: #bbbbbb } /* Text.Whitespace */\n", - ".cython .mb { color: #666666 } /* Literal.Number.Bin */\n", - ".cython .mf { color: #666666 } /* Literal.Number.Float */\n", - ".cython .mh { color: #666666 } /* Literal.Number.Hex */\n", - ".cython .mi { color: #666666 } /* Literal.Number.Integer */\n", - ".cython .mo { color: #666666 } /* Literal.Number.Oct */\n", - ".cython .sa { color: #BA2121 } /* Literal.String.Affix */\n", - ".cython .sb { color: #BA2121 } /* Literal.String.Backtick */\n", - ".cython .sc { color: #BA2121 } /* Literal.String.Char */\n", - ".cython .dl { color: #BA2121 } /* Literal.String.Delimiter */\n", - ".cython .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n", - ".cython .s2 { color: #BA2121 } /* Literal.String.Double */\n", - ".cython .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */\n", - ".cython .sh { color: #BA2121 } /* Literal.String.Heredoc */\n", - ".cython .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */\n", - ".cython .sx { color: #008000 } /* Literal.String.Other */\n", - ".cython .sr { color: #BB6688 } /* Literal.String.Regex */\n", - ".cython .s1 { color: #BA2121 } /* Literal.String.Single */\n", - ".cython .ss { color: #19177C } /* Literal.String.Symbol */\n", - ".cython .bp { color: #008000 } /* Name.Builtin.Pseudo */\n", - ".cython .fm { color: #0000FF } /* Name.Function.Magic */\n", - ".cython .vc { color: #19177C } /* Name.Variable.Class */\n", - ".cython .vg { color: #19177C } /* Name.Variable.Global */\n", - ".cython .vi { color: #19177C } /* Name.Variable.Instance */\n", - ".cython .vm { color: #19177C } /* Name.Variable.Magic */\n", - ".cython .il { color: #666666 } /* Literal.Number.Integer.Long */\n", - " </style>\n", - " <script>\n", - " function toggleDiv(id) {\n", - " theDiv = id.nextElementSibling\n", - " if (theDiv.style.display != 'block') theDiv.style.display = 'block';\n", - " else theDiv.style.display = 'none';\n", - " }\n", - " </script>\n", - "</head>\n", - "<body class=\"cython\">\n", - "<p><span style=\"border-bottom: solid 1px grey;\">Generated by Cython 0.25.2</span></p>\n", - "<p>\n", - " <span style=\"background-color: #FFFF00\">Yellow lines</span> hint at Python interaction.<br />\n", - " Click on a line that starts with a \"<code>+</code>\" to see the C code that Cython generated for it.\n", - "</p>\n", - "<div class=\"cython\"><pre class=\"cython line score-17\" onclick='toggleDiv(this)'>+<span class=\"\">1</span>: <span class=\"k\">def</span> <span class=\"nf\">foo</span><span class=\"p\">():</span></pre>\n", - "<pre class='cython code score-17 '>/* Python wrapper */\n", - "static PyObject *__pyx_pw_46_cython_magic_fcaa11e6595f50de5667d45b47247f97_1foo(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/\n", - "static PyMethodDef __pyx_mdef_46_cython_magic_fcaa11e6595f50de5667d45b47247f97_1foo = {\"foo\", (PyCFunction)__pyx_pw_46_cython_magic_fcaa11e6595f50de5667d45b47247f97_1foo, METH_NOARGS, 0};\n", - "static PyObject *__pyx_pw_46_cython_magic_fcaa11e6595f50de5667d45b47247f97_1foo(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {\n", - " PyObject *__pyx_r = 0;\n", - " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", - " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"foo (wrapper)\", 0);\n", - " __pyx_r = __pyx_pf_46_cython_magic_fcaa11e6595f50de5667d45b47247f97_foo(__pyx_self);\n", - "\n", - " /* function exit code */\n", - " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", - " return __pyx_r;\n", - "}\n", - "\n", - "static PyObject *__pyx_pf_46_cython_magic_fcaa11e6595f50de5667d45b47247f97_foo(CYTHON_UNUSED PyObject *__pyx_self) {\n", - " PyObject *__pyx_v_i = NULL;\n", - " PyObject *__pyx_r = NULL;\n", - " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", - " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"foo\", 0);\n", - "/* … */\n", - " /* function exit code */\n", - " __pyx_r = Py_None; <span class='pyx_macro_api'>__Pyx_INCREF</span>(Py_None);\n", - " goto __pyx_L0;\n", - " __pyx_L1_error:;\n", - " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);\n", - " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2);\n", - " <span class='pyx_c_api'>__Pyx_AddTraceback</span>(\"_cython_magic_fcaa11e6595f50de5667d45b47247f97.foo\", __pyx_clineno, __pyx_lineno, __pyx_filename);\n", - " __pyx_r = NULL;\n", - " __pyx_L0:;\n", - " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_i);\n", - " <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r);\n", - " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", - " return __pyx_r;\n", - "}\n", - "/* … */\n", - " __pyx_tuple__2 = <span class='py_c_api'>PyTuple_Pack</span>(1, __pyx_n_s_i); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 1, __pyx_L1_error)\n", - " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_tuple__2);\n", - " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_tuple__2);\n", - "/* … */\n", - " __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_46_cython_magic_fcaa11e6595f50de5667d45b47247f97_1foo, NULL, __pyx_n_s_cython_magic_fcaa11e6595f50de56); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)\n", - " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", - " if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_foo, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)\n", - " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", - "</pre><pre class=\"cython line score-54\" onclick='toggleDiv(this)'>+<span class=\"\">2</span>: <span class=\"k\">for</span> <span class=\"n\">i</span> <span class=\"ow\">in</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"mf\">50000</span><span class=\"p\">):</span></pre>\n", - "<pre class='cython code score-54 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_builtin_range, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)\n", - " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", - " if (likely(<span class='py_c_api'>PyList_CheckExact</span>(__pyx_t_1)) || <span class='py_c_api'>PyTuple_CheckExact</span>(__pyx_t_1)) {\n", - " __pyx_t_2 = __pyx_t_1; <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_2); __pyx_t_3 = 0;\n", - " __pyx_t_4 = NULL;\n", - " } else {\n", - " __pyx_t_3 = -1; __pyx_t_2 = <span class='py_c_api'>PyObject_GetIter</span>(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error)\n", - " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", - " __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 2, __pyx_L1_error)\n", - " }\n", - " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", - " for (;;) {\n", - " if (likely(!__pyx_t_4)) {\n", - " if (likely(<span class='py_c_api'>PyList_CheckExact</span>(__pyx_t_2))) {\n", - " if (__pyx_t_3 >= <span class='py_macro_api'>PyList_GET_SIZE</span>(__pyx_t_2)) break;\n", - " #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS\n", - " __pyx_t_1 = <span class='py_macro_api'>PyList_GET_ITEM</span>(__pyx_t_2, __pyx_t_3); <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2, __pyx_L1_error)\n", - " #else\n", - " __pyx_t_1 = <span class='py_macro_api'>PySequence_ITEM</span>(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)\n", - " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", - " #endif\n", - " } else {\n", - " if (__pyx_t_3 >= <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_t_2)) break;\n", - " #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS\n", - " __pyx_t_1 = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_t_2, __pyx_t_3); <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 2, __pyx_L1_error)\n", - " #else\n", - " __pyx_t_1 = <span class='py_macro_api'>PySequence_ITEM</span>(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)\n", - " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", - " #endif\n", - " }\n", - " } else {\n", - " __pyx_t_1 = __pyx_t_4(__pyx_t_2);\n", - " if (unlikely(!__pyx_t_1)) {\n", - " PyObject* exc_type = <span class='py_c_api'>PyErr_Occurred</span>();\n", - " if (exc_type) {\n", - " if (likely(exc_type == PyExc_StopIteration || <span class='py_c_api'>PyErr_GivenExceptionMatches</span>(exc_type, PyExc_StopIteration))) <span class='py_c_api'>PyErr_Clear</span>();\n", - " else __PYX_ERR(0, 2, __pyx_L1_error)\n", - " }\n", - " break;\n", - " }\n", - " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", - " }\n", - " <span class='pyx_macro_api'>__Pyx_XDECREF_SET</span>(__pyx_v_i, __pyx_t_1);\n", - " __pyx_t_1 = 0;\n", - "/* … */\n", - " }\n", - " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", - "/* … */\n", - " __pyx_tuple_ = <span class='py_c_api'>PyTuple_Pack</span>(1, __pyx_int_50000); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 2, __pyx_L1_error)\n", - " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_tuple_);\n", - " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_tuple_);\n", - "</pre><pre class=\"cython line score-6\" onclick='toggleDiv(this)'>+<span class=\"\">3</span>: <span class=\"n\">i</span><span class=\"o\">*</span><span class=\"n\">i</span></pre>\n", - "<pre class='cython code score-6 '> __pyx_t_1 = <span class='py_c_api'>PyNumber_Multiply</span>(__pyx_v_i, __pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error)\n", - " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", - " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", - "</pre></div></body></html>" - ], - "text/plain": [ - "<IPython.core.display.HTML object>" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "0.75\n" + ] } ], + "source": [ + "%%cython\n", + "cimport numpy as np\n", + "cdef np.int32_t g,gg\n", + "g=2\n", + "gg=4\n", + "print(len([1,2,3])/gg)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2018-05-22T08:48:45.091366Z", + "start_time": "2018-05-22T08:48:44.050657Z" + } + }, + "outputs": [], "source": [ "%%cython --annotate\n", "def foo():\n", @@ -519,30 +60,21 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2018-04-20T07:03:06.289592Z", - "start_time": "2018-04-20T07:03:06.283966Z" + "end_time": "2018-05-22T08:48:45.923157Z", + "start_time": "2018-05-22T08:48:45.916752Z" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "CPU times: user 1.91 ms, sys: 3 µs, total: 1.92 ms\n", - "Wall time: 1.93 ms\n" - ] - } - ], + "outputs": [], "source": [ "%time foo()\n" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-04-20T07:03:06.296109Z", @@ -560,31 +92,21 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-04-20T07:03:06.302224Z", "start_time": "2018-04-20T07:03:06.298061Z" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['Le ', 'pont ', \"d'\", 'avignon ', 'est ', '-', 'sympa ']\n", - "CPU times: user 70 µs, sys: 29 µs, total: 99 µs\n", - "Wall time: 83.9 µs\n" - ] - } - ], + "outputs": [], "source": [ "%time foo()" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-04-20T07:03:06.307291Z", @@ -600,31 +122,21 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-04-20T07:03:06.312937Z", "start_time": "2018-04-20T07:03:06.309325Z" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['Le ', 'pont ', \"d'\", 'avignon ', 'est ', '-', 'sympa ']\n", - "CPU times: user 49 µs, sys: 20 µs, total: 69 µs\n", - "Wall time: 59.8 µs\n" - ] - } - ], + "outputs": [], "source": [ "%time foo()" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-04-20T07:03:06.320412Z", @@ -648,32 +160,14 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-04-20T07:03:19.194254Z", "start_time": "2018-04-20T07:03:06.323051Z" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.58 µs ± 15.5 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n" - ] - }, - { - "data": { - "text/plain": [ - "2.43290200817664e+18" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "\n", "\n", @@ -684,32 +178,14 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-04-20T07:03:27.738161Z", "start_time": "2018-04-20T07:03:19.196269Z" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.05 µs ± 6.72 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)\n" - ] - }, - { - "data": { - "text/plain": [ - "2.43290200817664e+18" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "%timeit cyfac_double(20.0)\n", "cyfac_double(20.0)" @@ -717,7 +193,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-04-20T07:03:27.745810Z", @@ -736,227 +212,2430 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-04-20T07:03:37.326307Z", "start_time": "2018-04-20T07:03:27.748079Z" } }, + "outputs": [], + "source": [ + "%timeit cyfac_double_fast(20.0)\n", + "cyfac_double_fast(20.0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2018-04-20T07:03:37.332486Z", + "start_time": "2018-04-20T07:03:37.328492Z" + } + }, + "outputs": [], + "source": [ + "cd .." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "ExecuteTime": { + "end_time": "2018-05-22T11:40:23.149581Z", + "start_time": "2018-05-22T11:40:23.039534Z" + } + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "class PureHED():\n", + " \"\"\"\n", + " Implementation of Hausdorff Edit Distance described in\n", + "\n", + " Improved quadratic time approximation of graph edit distance by Hausdorff matching and greedy assignement\n", + " Andreas Fischer, Kaspar Riesen, Horst Bunke\n", + " 2016\n", + " \"\"\"\n", + " __type__ = \"dist\"\n", + " @staticmethod\n", + " def compare(listgs, c_del_node=1, c_del_edge=1, c_ins_node=1, c_ins_edge=1):\n", + " n = len(listgs)\n", + " comparator = PureHED(c_del_node, c_ins_node, c_del_edge, c_ins_edge)\n", + " comparison_matrix = np.zeros((n, n))\n", + " for i in range(n):\n", + " for j in range(i, n):\n", + " comparison_matrix[i, j] = comparator.hed(listgs[i], listgs[j])\n", + " comparison_matrix[j, i] = comparison_matrix[i, j]\n", + "\n", + " return comparison_matrix\n", + "\n", + "\n", + " def __init__(self, node_del=1, node_ins=1, edge_del=1, edge_ins=1):\n", + " \"\"\"Constructor for HED\"\"\"\n", + " self.node_del = node_del\n", + " self.node_ins = node_ins\n", + " self.edge_del = edge_del\n", + " self.edge_ins = edge_ins\n", + "\n", + " def hed(self, g1, g2):\n", + " \"\"\"\n", + " Compute de Hausdorff Edit Distance\n", + " :param g1: first graph\n", + " :param g2: second graph\n", + " :return:\n", + " \"\"\"\n", + " return self.sum_fuv(g1, g2) + self.sum_fuv(g2, g1)\n", + "\n", + " def sum_fuv(self, g1, g2):\n", + " \"\"\"\n", + " Compute Nearest Neighbour Distance between G1 and G2\n", + " :param g1: First Graph\n", + " :param g2: Second Graph\n", + " :return:\n", + " \"\"\"\n", + " min_sum = np.zeros(len(g1))\n", + " nodes1 = g1.nodes()\n", + " nodes2 = g2.nodes()\n", + " nodes2.extend([None])\n", + " for i in range(len(nodes1)):\n", + " min_i = np.zeros(len(nodes2))\n", + " for j in range(len(nodes2)):\n", + " min_i[j] = self.fuv(g1, g2, nodes1[i], nodes2[j])\n", + " min_sum[i] = np.min(min_i)\n", + " return np.sum(min_sum)\n", + "\n", + " def fuv(self, g1, g2, n1, n2):\n", + " \"\"\"\n", + " Compute the Node Distance function\n", + " :param g1: first graph\n", + " :param g2: second graph\n", + " :param n1: node of the first graph\n", + " :param n2: node of the second graph\n", + " :return:\n", + " \"\"\"\n", + " if n2 == None: # Del\n", + " return self.node_del + ((self.edge_del / 2) * g1.degree(n1))\n", + " if n1 == None: # Insert\n", + " return self.node_ins + ((self.edge_ins / 2) * g2.degree(n2))\n", + " else:\n", + " if n1 == n2:\n", + " return 0.\n", + " return (self.node_del + self.node_ins + self.hed_edge(g1, g2, n1, n2)) / 2\n", + "\n", + " def hed_edge(self, g1, g2, n1, n2):\n", + " \"\"\"\n", + " Compute HEDistance between edges of n1 and n2, respectively in g1 and g2\n", + " :param g1: first graph\n", + " :param g2: second graph\n", + " :param n1: node of the first graph\n", + " :param n2: node of the second graph\n", + " :return:\n", + " \"\"\"\n", + " return self.sum_gpq(g1, n1, g2, n2) + self.sum_gpq(g1, n1, g2, n2)\n", + "\n", + " def get_edge_multigraph(self, g, node):\n", + " \"\"\"\n", + " Get list of edge around a node in a Multigraph\n", + " :param g: multigraph\n", + " :param node: node in the multigraph\n", + " :return:\n", + " \"\"\"\n", + " edges = []\n", + " for edge in g.edges(data=True):\n", + " if node == edge[0] or node == edge[1]:\n", + " edges.append(\"{0}-{1}\".format(edge[0],edge[1]))\n", + " return edges\n", + "\n", + " def sum_gpq(self, g1, n1, g2, n2):\n", + " \"\"\"\n", + " Compute Nearest Neighbour Distance between edges around n1 in G1 and edges around n2 in G2\n", + " :param g1: first graph\n", + " :param n1: node in the first graph\n", + " :param g2: second graph\n", + " :param n2: node in the second graph\n", + " :return:\n", + " \"\"\"\n", + "\n", + " #if isinstance(g1, nx.MultiDiGraph):\n", + " edges1 = self.get_edge_multigraph(g1, n1)\n", + " edges2 = self.get_edge_multigraph(g2, n2)\n", + "\n", + " #else:\n", + " #edges1 = [str(n1 + \"-\" + ef) for ef in list(g1.edge[n1].keys())]\n", + " #edges2 = [str(n2 + \"-\" + ef) for ef in list(g2.edge[n2].keys())]\n", + "\n", + " min_sum = np.zeros(len(edges1))\n", + " edges2.extend([None])\n", + " for i in range(len(edges1)):\n", + " min_i = np.zeros(len(edges2))\n", + " for j in range(len(edges2)):\n", + " min_i[j] = self.gpq(edges1[i], edges2[j])\n", + " min_sum[i] = np.min(min_i)\n", + " return np.sum(min_sum)\n", + "\n", + " def gpq(self, e1, e2):\n", + " \"\"\"\n", + " Compute the edge distance function\n", + " :param e1: edge1\n", + " :param e2: edge2\n", + " :return:\n", + " \"\"\"\n", + " if e2 == None: # Del\n", + " return self.edge_del\n", + " if e1 == None: # Insert\n", + " return self.edge_ins\n", + " else:\n", + " if e1 == e2:\n", + " return 0\n", + " return (self.edge_del + self.edge_ins) / 2\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2018-05-22T11:40:21.270815Z", + "start_time": "2018-05-22T11:40:18.702869Z" + } + }, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "117 ns ± 4.03 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)\n" - ] - }, { "data": { + "text/html": [ + "<!DOCTYPE html>\n", + "<!-- Generated by Cython 0.28.2 -->\n", + "<html>\n", + "<head>\n", + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n", + " <title>Cython: _cython_magic_dda4cdebdc96d9140091621511971356.pyx</title>\n", + " <style type=\"text/css\">\n", + " \n", + "body.cython { font-family: courier; font-size: 12; }\n", + "\n", + ".cython.tag { }\n", + ".cython.line { margin: 0em }\n", + ".cython.code { font-size: 9; color: #444444; display: none; margin: 0px 0px 0px 8px; border-left: 8px none; }\n", + "\n", + ".cython.line .run { background-color: #B0FFB0; }\n", + ".cython.line .mis { background-color: #FFB0B0; }\n", + ".cython.code.run { border-left: 8px solid #B0FFB0; }\n", + ".cython.code.mis { border-left: 8px solid #FFB0B0; }\n", + "\n", + ".cython.code .py_c_api { color: red; }\n", + ".cython.code .py_macro_api { color: #FF7000; }\n", + ".cython.code .pyx_c_api { color: #FF3000; }\n", + ".cython.code .pyx_macro_api { color: #FF7000; }\n", + ".cython.code .refnanny { color: #FFA000; }\n", + ".cython.code .trace { color: #FFA000; }\n", + ".cython.code .error_goto { color: #FFA000; }\n", + "\n", + ".cython.code .coerce { color: #008000; border: 1px dotted #008000 }\n", + ".cython.code .py_attr { color: #FF0000; font-weight: bold; }\n", + ".cython.code .c_attr { color: #0000FF; }\n", + ".cython.code .py_call { color: #FF0000; font-weight: bold; }\n", + ".cython.code .c_call { color: #0000FF; }\n", + "\n", + ".cython.score-0 {background-color: #FFFFff;}\n", + ".cython.score-1 {background-color: #FFFFe7;}\n", + ".cython.score-2 {background-color: #FFFFd4;}\n", + ".cython.score-3 {background-color: #FFFFc4;}\n", + ".cython.score-4 {background-color: #FFFFb6;}\n", + ".cython.score-5 {background-color: #FFFFaa;}\n", + ".cython.score-6 {background-color: #FFFF9f;}\n", + ".cython.score-7 {background-color: #FFFF96;}\n", + ".cython.score-8 {background-color: #FFFF8d;}\n", + ".cython.score-9 {background-color: #FFFF86;}\n", + ".cython.score-10 {background-color: #FFFF7f;}\n", + ".cython.score-11 {background-color: #FFFF79;}\n", + ".cython.score-12 {background-color: #FFFF73;}\n", + ".cython.score-13 {background-color: #FFFF6e;}\n", + ".cython.score-14 {background-color: #FFFF6a;}\n", + ".cython.score-15 {background-color: #FFFF66;}\n", + ".cython.score-16 {background-color: #FFFF62;}\n", + ".cython.score-17 {background-color: #FFFF5e;}\n", + ".cython.score-18 {background-color: #FFFF5b;}\n", + ".cython.score-19 {background-color: #FFFF57;}\n", + ".cython.score-20 {background-color: #FFFF55;}\n", + ".cython.score-21 {background-color: #FFFF52;}\n", + ".cython.score-22 {background-color: #FFFF4f;}\n", + ".cython.score-23 {background-color: #FFFF4d;}\n", + ".cython.score-24 {background-color: #FFFF4b;}\n", + ".cython.score-25 {background-color: #FFFF48;}\n", + ".cython.score-26 {background-color: #FFFF46;}\n", + ".cython.score-27 {background-color: #FFFF44;}\n", + ".cython.score-28 {background-color: #FFFF43;}\n", + ".cython.score-29 {background-color: #FFFF41;}\n", + ".cython.score-30 {background-color: #FFFF3f;}\n", + ".cython.score-31 {background-color: #FFFF3e;}\n", + ".cython.score-32 {background-color: #FFFF3c;}\n", + ".cython.score-33 {background-color: #FFFF3b;}\n", + ".cython.score-34 {background-color: #FFFF39;}\n", + ".cython.score-35 {background-color: #FFFF38;}\n", + ".cython.score-36 {background-color: #FFFF37;}\n", + ".cython.score-37 {background-color: #FFFF36;}\n", + ".cython.score-38 {background-color: #FFFF35;}\n", + ".cython.score-39 {background-color: #FFFF34;}\n", + ".cython.score-40 {background-color: #FFFF33;}\n", + ".cython.score-41 {background-color: #FFFF32;}\n", + ".cython.score-42 {background-color: #FFFF31;}\n", + ".cython.score-43 {background-color: #FFFF30;}\n", + ".cython.score-44 {background-color: #FFFF2f;}\n", + ".cython.score-45 {background-color: #FFFF2e;}\n", + ".cython.score-46 {background-color: #FFFF2d;}\n", + ".cython.score-47 {background-color: #FFFF2c;}\n", + ".cython.score-48 {background-color: #FFFF2b;}\n", + ".cython.score-49 {background-color: #FFFF2b;}\n", + ".cython.score-50 {background-color: #FFFF2a;}\n", + ".cython.score-51 {background-color: #FFFF29;}\n", + ".cython.score-52 {background-color: #FFFF29;}\n", + ".cython.score-53 {background-color: #FFFF28;}\n", + ".cython.score-54 {background-color: #FFFF27;}\n", + ".cython.score-55 {background-color: #FFFF27;}\n", + ".cython.score-56 {background-color: #FFFF26;}\n", + ".cython.score-57 {background-color: #FFFF26;}\n", + ".cython.score-58 {background-color: #FFFF25;}\n", + ".cython.score-59 {background-color: #FFFF24;}\n", + ".cython.score-60 {background-color: #FFFF24;}\n", + ".cython.score-61 {background-color: #FFFF23;}\n", + ".cython.score-62 {background-color: #FFFF23;}\n", + ".cython.score-63 {background-color: #FFFF22;}\n", + ".cython.score-64 {background-color: #FFFF22;}\n", + ".cython.score-65 {background-color: #FFFF22;}\n", + ".cython.score-66 {background-color: #FFFF21;}\n", + ".cython.score-67 {background-color: #FFFF21;}\n", + ".cython.score-68 {background-color: #FFFF20;}\n", + ".cython.score-69 {background-color: #FFFF20;}\n", + ".cython.score-70 {background-color: #FFFF1f;}\n", + ".cython.score-71 {background-color: #FFFF1f;}\n", + ".cython.score-72 {background-color: #FFFF1f;}\n", + ".cython.score-73 {background-color: #FFFF1e;}\n", + ".cython.score-74 {background-color: #FFFF1e;}\n", + ".cython.score-75 {background-color: #FFFF1e;}\n", + ".cython.score-76 {background-color: #FFFF1d;}\n", + ".cython.score-77 {background-color: #FFFF1d;}\n", + ".cython.score-78 {background-color: #FFFF1c;}\n", + ".cython.score-79 {background-color: #FFFF1c;}\n", + ".cython.score-80 {background-color: #FFFF1c;}\n", + ".cython.score-81 {background-color: #FFFF1c;}\n", + ".cython.score-82 {background-color: #FFFF1b;}\n", + ".cython.score-83 {background-color: #FFFF1b;}\n", + ".cython.score-84 {background-color: #FFFF1b;}\n", + ".cython.score-85 {background-color: #FFFF1a;}\n", + ".cython.score-86 {background-color: #FFFF1a;}\n", + ".cython.score-87 {background-color: #FFFF1a;}\n", + ".cython.score-88 {background-color: #FFFF1a;}\n", + ".cython.score-89 {background-color: #FFFF19;}\n", + ".cython.score-90 {background-color: #FFFF19;}\n", + ".cython.score-91 {background-color: #FFFF19;}\n", + ".cython.score-92 {background-color: #FFFF19;}\n", + ".cython.score-93 {background-color: #FFFF18;}\n", + ".cython.score-94 {background-color: #FFFF18;}\n", + ".cython.score-95 {background-color: #FFFF18;}\n", + ".cython.score-96 {background-color: #FFFF18;}\n", + ".cython.score-97 {background-color: #FFFF17;}\n", + ".cython.score-98 {background-color: #FFFF17;}\n", + ".cython.score-99 {background-color: #FFFF17;}\n", + ".cython.score-100 {background-color: #FFFF17;}\n", + ".cython.score-101 {background-color: #FFFF16;}\n", + ".cython.score-102 {background-color: #FFFF16;}\n", + ".cython.score-103 {background-color: #FFFF16;}\n", + ".cython.score-104 {background-color: #FFFF16;}\n", + ".cython.score-105 {background-color: #FFFF16;}\n", + ".cython.score-106 {background-color: #FFFF15;}\n", + ".cython.score-107 {background-color: #FFFF15;}\n", + ".cython.score-108 {background-color: #FFFF15;}\n", + ".cython.score-109 {background-color: #FFFF15;}\n", + ".cython.score-110 {background-color: #FFFF15;}\n", + ".cython.score-111 {background-color: #FFFF15;}\n", + ".cython.score-112 {background-color: #FFFF14;}\n", + ".cython.score-113 {background-color: #FFFF14;}\n", + ".cython.score-114 {background-color: #FFFF14;}\n", + ".cython.score-115 {background-color: #FFFF14;}\n", + ".cython.score-116 {background-color: #FFFF14;}\n", + ".cython.score-117 {background-color: #FFFF14;}\n", + ".cython.score-118 {background-color: #FFFF13;}\n", + ".cython.score-119 {background-color: #FFFF13;}\n", + ".cython.score-120 {background-color: #FFFF13;}\n", + ".cython.score-121 {background-color: #FFFF13;}\n", + ".cython.score-122 {background-color: #FFFF13;}\n", + ".cython.score-123 {background-color: #FFFF13;}\n", + ".cython.score-124 {background-color: #FFFF13;}\n", + ".cython.score-125 {background-color: #FFFF12;}\n", + ".cython.score-126 {background-color: #FFFF12;}\n", + ".cython.score-127 {background-color: #FFFF12;}\n", + ".cython.score-128 {background-color: #FFFF12;}\n", + ".cython.score-129 {background-color: #FFFF12;}\n", + ".cython.score-130 {background-color: #FFFF12;}\n", + ".cython.score-131 {background-color: #FFFF12;}\n", + ".cython.score-132 {background-color: #FFFF11;}\n", + ".cython.score-133 {background-color: #FFFF11;}\n", + ".cython.score-134 {background-color: #FFFF11;}\n", + ".cython.score-135 {background-color: #FFFF11;}\n", + ".cython.score-136 {background-color: #FFFF11;}\n", + ".cython.score-137 {background-color: #FFFF11;}\n", + ".cython.score-138 {background-color: #FFFF11;}\n", + ".cython.score-139 {background-color: #FFFF11;}\n", + ".cython.score-140 {background-color: #FFFF11;}\n", + ".cython.score-141 {background-color: #FFFF10;}\n", + ".cython.score-142 {background-color: #FFFF10;}\n", + ".cython.score-143 {background-color: #FFFF10;}\n", + ".cython.score-144 {background-color: #FFFF10;}\n", + ".cython.score-145 {background-color: #FFFF10;}\n", + ".cython.score-146 {background-color: #FFFF10;}\n", + ".cython.score-147 {background-color: #FFFF10;}\n", + ".cython.score-148 {background-color: #FFFF10;}\n", + ".cython.score-149 {background-color: #FFFF10;}\n", + ".cython.score-150 {background-color: #FFFF0f;}\n", + ".cython.score-151 {background-color: #FFFF0f;}\n", + ".cython.score-152 {background-color: #FFFF0f;}\n", + ".cython.score-153 {background-color: #FFFF0f;}\n", + ".cython.score-154 {background-color: #FFFF0f;}\n", + ".cython.score-155 {background-color: #FFFF0f;}\n", + ".cython.score-156 {background-color: #FFFF0f;}\n", + ".cython.score-157 {background-color: #FFFF0f;}\n", + ".cython.score-158 {background-color: #FFFF0f;}\n", + ".cython.score-159 {background-color: #FFFF0f;}\n", + ".cython.score-160 {background-color: #FFFF0f;}\n", + ".cython.score-161 {background-color: #FFFF0e;}\n", + ".cython.score-162 {background-color: #FFFF0e;}\n", + ".cython.score-163 {background-color: #FFFF0e;}\n", + ".cython.score-164 {background-color: #FFFF0e;}\n", + ".cython.score-165 {background-color: #FFFF0e;}\n", + ".cython.score-166 {background-color: #FFFF0e;}\n", + ".cython.score-167 {background-color: #FFFF0e;}\n", + ".cython.score-168 {background-color: #FFFF0e;}\n", + ".cython.score-169 {background-color: #FFFF0e;}\n", + ".cython.score-170 {background-color: #FFFF0e;}\n", + ".cython.score-171 {background-color: #FFFF0e;}\n", + ".cython.score-172 {background-color: #FFFF0e;}\n", + ".cython.score-173 {background-color: #FFFF0d;}\n", + ".cython.score-174 {background-color: #FFFF0d;}\n", + ".cython.score-175 {background-color: #FFFF0d;}\n", + ".cython.score-176 {background-color: #FFFF0d;}\n", + ".cython.score-177 {background-color: #FFFF0d;}\n", + ".cython.score-178 {background-color: #FFFF0d;}\n", + ".cython.score-179 {background-color: #FFFF0d;}\n", + ".cython.score-180 {background-color: #FFFF0d;}\n", + ".cython.score-181 {background-color: #FFFF0d;}\n", + ".cython.score-182 {background-color: #FFFF0d;}\n", + ".cython.score-183 {background-color: #FFFF0d;}\n", + ".cython.score-184 {background-color: #FFFF0d;}\n", + ".cython.score-185 {background-color: #FFFF0d;}\n", + ".cython.score-186 {background-color: #FFFF0d;}\n", + ".cython.score-187 {background-color: #FFFF0c;}\n", + ".cython.score-188 {background-color: #FFFF0c;}\n", + ".cython.score-189 {background-color: #FFFF0c;}\n", + ".cython.score-190 {background-color: #FFFF0c;}\n", + ".cython.score-191 {background-color: #FFFF0c;}\n", + ".cython.score-192 {background-color: #FFFF0c;}\n", + ".cython.score-193 {background-color: #FFFF0c;}\n", + ".cython.score-194 {background-color: #FFFF0c;}\n", + ".cython.score-195 {background-color: #FFFF0c;}\n", + ".cython.score-196 {background-color: #FFFF0c;}\n", + ".cython.score-197 {background-color: #FFFF0c;}\n", + ".cython.score-198 {background-color: #FFFF0c;}\n", + ".cython.score-199 {background-color: #FFFF0c;}\n", + ".cython.score-200 {background-color: #FFFF0c;}\n", + ".cython.score-201 {background-color: #FFFF0c;}\n", + ".cython.score-202 {background-color: #FFFF0c;}\n", + ".cython.score-203 {background-color: #FFFF0b;}\n", + ".cython.score-204 {background-color: #FFFF0b;}\n", + ".cython.score-205 {background-color: #FFFF0b;}\n", + ".cython.score-206 {background-color: #FFFF0b;}\n", + ".cython.score-207 {background-color: #FFFF0b;}\n", + ".cython.score-208 {background-color: #FFFF0b;}\n", + ".cython.score-209 {background-color: #FFFF0b;}\n", + ".cython.score-210 {background-color: #FFFF0b;}\n", + ".cython.score-211 {background-color: #FFFF0b;}\n", + ".cython.score-212 {background-color: #FFFF0b;}\n", + ".cython.score-213 {background-color: #FFFF0b;}\n", + ".cython.score-214 {background-color: #FFFF0b;}\n", + ".cython.score-215 {background-color: #FFFF0b;}\n", + ".cython.score-216 {background-color: #FFFF0b;}\n", + ".cython.score-217 {background-color: #FFFF0b;}\n", + ".cython.score-218 {background-color: #FFFF0b;}\n", + ".cython.score-219 {background-color: #FFFF0b;}\n", + ".cython.score-220 {background-color: #FFFF0b;}\n", + ".cython.score-221 {background-color: #FFFF0b;}\n", + ".cython.score-222 {background-color: #FFFF0a;}\n", + ".cython.score-223 {background-color: #FFFF0a;}\n", + ".cython.score-224 {background-color: #FFFF0a;}\n", + ".cython.score-225 {background-color: #FFFF0a;}\n", + ".cython.score-226 {background-color: #FFFF0a;}\n", + ".cython.score-227 {background-color: #FFFF0a;}\n", + ".cython.score-228 {background-color: #FFFF0a;}\n", + ".cython.score-229 {background-color: #FFFF0a;}\n", + ".cython.score-230 {background-color: #FFFF0a;}\n", + ".cython.score-231 {background-color: #FFFF0a;}\n", + ".cython.score-232 {background-color: #FFFF0a;}\n", + ".cython.score-233 {background-color: #FFFF0a;}\n", + ".cython.score-234 {background-color: #FFFF0a;}\n", + ".cython.score-235 {background-color: #FFFF0a;}\n", + ".cython.score-236 {background-color: #FFFF0a;}\n", + ".cython.score-237 {background-color: #FFFF0a;}\n", + ".cython.score-238 {background-color: #FFFF0a;}\n", + ".cython.score-239 {background-color: #FFFF0a;}\n", + ".cython.score-240 {background-color: #FFFF0a;}\n", + ".cython.score-241 {background-color: #FFFF0a;}\n", + ".cython.score-242 {background-color: #FFFF0a;}\n", + ".cython.score-243 {background-color: #FFFF0a;}\n", + ".cython.score-244 {background-color: #FFFF0a;}\n", + ".cython.score-245 {background-color: #FFFF0a;}\n", + ".cython.score-246 {background-color: #FFFF09;}\n", + ".cython.score-247 {background-color: #FFFF09;}\n", + ".cython.score-248 {background-color: #FFFF09;}\n", + ".cython.score-249 {background-color: #FFFF09;}\n", + ".cython.score-250 {background-color: #FFFF09;}\n", + ".cython.score-251 {background-color: #FFFF09;}\n", + ".cython.score-252 {background-color: #FFFF09;}\n", + ".cython.score-253 {background-color: #FFFF09;}\n", + ".cython.score-254 {background-color: #FFFF09;}\n", + ".cython .hll { background-color: #ffffcc }\n", + ".cython { background: #f8f8f8; }\n", + ".cython .c { color: #408080; font-style: italic } /* Comment */\n", + ".cython .err { border: 1px solid #FF0000 } /* Error */\n", + ".cython .k { color: #008000; font-weight: bold } /* Keyword */\n", + ".cython .o { color: #666666 } /* Operator */\n", + ".cython .ch { color: #408080; font-style: italic } /* Comment.Hashbang */\n", + ".cython .cm { color: #408080; font-style: italic } /* Comment.Multiline */\n", + ".cython .cp { color: #BC7A00 } /* Comment.Preproc */\n", + ".cython .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */\n", + ".cython .c1 { color: #408080; font-style: italic } /* Comment.Single */\n", + ".cython .cs { color: #408080; font-style: italic } /* Comment.Special */\n", + ".cython .gd { color: #A00000 } /* Generic.Deleted */\n", + ".cython .ge { font-style: italic } /* Generic.Emph */\n", + ".cython .gr { color: #FF0000 } /* Generic.Error */\n", + ".cython .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n", + ".cython .gi { color: #00A000 } /* Generic.Inserted */\n", + ".cython .go { color: #888888 } /* Generic.Output */\n", + ".cython .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n", + ".cython .gs { font-weight: bold } /* Generic.Strong */\n", + ".cython .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n", + ".cython .gt { color: #0044DD } /* Generic.Traceback */\n", + ".cython .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n", + ".cython .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n", + ".cython .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n", + ".cython .kp { color: #008000 } /* Keyword.Pseudo */\n", + ".cython .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n", + ".cython .kt { color: #B00040 } /* Keyword.Type */\n", + ".cython .m { color: #666666 } /* Literal.Number */\n", + ".cython .s { color: #BA2121 } /* Literal.String */\n", + ".cython .na { color: #7D9029 } /* Name.Attribute */\n", + ".cython .nb { color: #008000 } /* Name.Builtin */\n", + ".cython .nc { color: #0000FF; font-weight: bold } /* Name.Class */\n", + ".cython .no { color: #880000 } /* Name.Constant */\n", + ".cython .nd { color: #AA22FF } /* Name.Decorator */\n", + ".cython .ni { color: #999999; font-weight: bold } /* Name.Entity */\n", + ".cython .ne { color: #D2413A; font-weight: bold } /* Name.Exception */\n", + ".cython .nf { color: #0000FF } /* Name.Function */\n", + ".cython .nl { color: #A0A000 } /* Name.Label */\n", + ".cython .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */\n", + ".cython .nt { color: #008000; font-weight: bold } /* Name.Tag */\n", + ".cython .nv { color: #19177C } /* Name.Variable */\n", + ".cython .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */\n", + ".cython .w { color: #bbbbbb } /* Text.Whitespace */\n", + ".cython .mb { color: #666666 } /* Literal.Number.Bin */\n", + ".cython .mf { color: #666666 } /* Literal.Number.Float */\n", + ".cython .mh { color: #666666 } /* Literal.Number.Hex */\n", + ".cython .mi { color: #666666 } /* Literal.Number.Integer */\n", + ".cython .mo { color: #666666 } /* Literal.Number.Oct */\n", + ".cython .sa { color: #BA2121 } /* Literal.String.Affix */\n", + ".cython .sb { color: #BA2121 } /* Literal.String.Backtick */\n", + ".cython .sc { color: #BA2121 } /* Literal.String.Char */\n", + ".cython .dl { color: #BA2121 } /* Literal.String.Delimiter */\n", + ".cython .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n", + ".cython .s2 { color: #BA2121 } /* Literal.String.Double */\n", + ".cython .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */\n", + ".cython .sh { color: #BA2121 } /* Literal.String.Heredoc */\n", + ".cython .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */\n", + ".cython .sx { color: #008000 } /* Literal.String.Other */\n", + ".cython .sr { color: #BB6688 } /* Literal.String.Regex */\n", + ".cython .s1 { color: #BA2121 } /* Literal.String.Single */\n", + ".cython .ss { color: #19177C } /* Literal.String.Symbol */\n", + ".cython .bp { color: #008000 } /* Name.Builtin.Pseudo */\n", + ".cython .fm { color: #0000FF } /* Name.Function.Magic */\n", + ".cython .vc { color: #19177C } /* Name.Variable.Class */\n", + ".cython .vg { color: #19177C } /* Name.Variable.Global */\n", + ".cython .vi { color: #19177C } /* Name.Variable.Instance */\n", + ".cython .vm { color: #19177C } /* Name.Variable.Magic */\n", + ".cython .il { color: #666666 } /* Literal.Number.Integer.Long */\n", + " </style>\n", + "</head>\n", + "<body class=\"cython\">\n", + "<p><span style=\"border-bottom: solid 1px grey;\">Generated by Cython 0.28.2</span></p>\n", + "<p>\n", + " <span style=\"background-color: #FFFF00\">Yellow lines</span> hint at Python interaction.<br />\n", + " Click on a line that starts with a \"<code>+</code>\" to see the C code that Cython generated for it.\n", + "</p>\n", + "<div class=\"cython\"><pre class=\"cython line score-16\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">001</span>: <span class=\"k\">import</span> <span class=\"nn\">numpy</span> <span class=\"k\">as</span> <span class=\"nn\">np</span></pre>\n", + "<pre class='cython code score-16 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_Import</span>(__pyx_n_s_numpy, 0, 0);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) <span class='error_goto'>__PYX_ERR(0, 1, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + "/* … */\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyDict_NewPresized</span>(0);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) <span class='error_goto'>__PYX_ERR(0, 1, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">002</span>: <span class=\"k\">cimport</span> <span class=\"nn\">numpy</span> <span class=\"k\">as</span> <span class=\"nn\">np</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">003</span>: <span class=\"k\">from</span> <span class=\"nn\">libcpp.vector</span> <span class=\"k\">cimport</span> <span class=\"n\">vector</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">004</span>: <span class=\"c\">#from libcpp.list cimport list as cpplist</span></pre>\n", + "<pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">005</span>: <span class=\"k\">cdef</span> <span class=\"k\">class</span> <span class=\"nf\">HED</span><span class=\"p\">:</span></pre>\n", + "<pre class='cython code score-0 '>struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED {\n", + " PyObject_HEAD\n", + " struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_vtab;\n", + " int node_del;\n", + " int node_ins;\n", + " int edge_del;\n", + " int edge_ins;\n", + "};\n", + "\n", + "\n", + "\n", + "struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED {\n", + " float (*hed)(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *, PyObject *, PyObject *, int __pyx_skip_dispatch);\n", + " float (*sum_fuv)(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *, PyObject *, PyObject *);\n", + " float (*fuv)(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *, PyObject *, PyObject *, PyObject *, PyObject *);\n", + " float (*hed_edge)(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *, PyObject *, PyObject *, PyObject *, PyObject *);\n", + " PyObject *(*get_edge_multigraph)(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *, PyObject *, PyObject *);\n", + " float (*sum_gpq)(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *, PyObject *, PyObject *, PyObject *, PyObject *);\n", + " float (*gpq)(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *, PyObject *, PyObject *);\n", + "};\n", + "static struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_vtabptr_46_cython_magic_dda4cdebdc96d9140091621511971356_HED;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">006</span>: <span class=\"sd\">"""</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">007</span>: <span class=\"sd\"> Implementation of Hausdorff Edit Distance described in</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">008</span>: </pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">009</span>: <span class=\"sd\"> Improved quadratic time approximation of graph edit distance by Hausdorff matching and greedy assignement</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">010</span>: <span class=\"sd\"> Andreas Fischer, Kaspar Riesen, Horst Bunke</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">011</span>: <span class=\"sd\"> 2016</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">012</span>: <span class=\"sd\"> """</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">013</span>: </pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">014</span>: <span class=\"k\">cdef</span> <span class=\"kt\">int</span> <span class=\"nf\">node_del</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">015</span>: <span class=\"k\">cdef</span> <span class=\"kt\">int</span> <span class=\"nf\">node_ins</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">016</span>: <span class=\"k\">cdef</span> <span class=\"kt\">int</span> <span class=\"nf\">edge_del</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">017</span>: <span class=\"k\">cdef</span> <span class=\"kt\">int</span> <span class=\"nf\">edge_ins</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">018</span>: </pre>\n", + "<pre class=\"cython line score-10\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">019</span>: <span class=\"n\">__type__</span> <span class=\"o\">=</span> <span class=\"s\">"dist"</span></pre>\n", + "<pre class='cython code score-10 '> if (<span class='py_c_api'>PyDict_SetItem</span>((PyObject *)__pyx_ptype_46_cython_magic_dda4cdebdc96d9140091621511971356_HED->tp_dict, __pyx_n_s_type, __pyx_n_u_dist) < 0) <span class='error_goto'>__PYX_ERR(0, 19, __pyx_L1_error)</span>\n", + " <span class='py_c_api'>PyType_Modified</span>(__pyx_ptype_46_cython_magic_dda4cdebdc96d9140091621511971356_HED);\n", + "</pre><pre class=\"cython line score-14\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">020</span>: <span class=\"nd\">@staticmethod</span></pre>\n", + "<pre class='cython code score-14 '> __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_builtin_staticmethod, __pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " if (<span class='py_c_api'>PyDict_SetItem</span>((PyObject *)__pyx_ptype_46_cython_magic_dda4cdebdc96d9140091621511971356_HED->tp_dict, __pyx_n_s_compare, __pyx_t_2) < 0) <span class='error_goto'>__PYX_ERR(0, 21, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='py_c_api'>PyType_Modified</span>(__pyx_ptype_46_cython_magic_dda4cdebdc96d9140091621511971356_HED);\n", + "</pre><pre class=\"cython line score-93\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">021</span>: <span class=\"k\">def</span> <span class=\"nf\">compare</span><span class=\"p\">(</span><span class=\"nb\">list</span> <span class=\"n\">listgs</span><span class=\"p\">,</span> <span class=\"nb\">int</span> <span class=\"n\">c_del_node</span><span class=\"o\">=</span><span class=\"mf\">1</span><span class=\"p\">,</span> <span class=\"nb\">int</span> <span class=\"n\">c_del_edge</span><span class=\"o\">=</span><span class=\"mf\">1</span><span class=\"p\">,</span> <span class=\"nb\">int</span> <span class=\"n\">c_ins_node</span><span class=\"o\">=</span><span class=\"mf\">1</span><span class=\"p\">,</span> <span class=\"nb\">int</span> <span class=\"n\">c_ins_edge</span><span class=\"o\">=</span><span class=\"mf\">1</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-93 '>/* Python wrapper */\n", + "static PyObject *__pyx_pw_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_1compare(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/\n", + "static PyMethodDef __pyx_mdef_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_1compare = {\"compare\", (PyCFunction)__pyx_pw_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_1compare, METH_VARARGS|METH_KEYWORDS, 0};\n", + "static PyObject *__pyx_pw_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_1compare(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {\n", + " PyObject *__pyx_v_listgs = 0;\n", + " int __pyx_v_c_del_node;\n", + " int __pyx_v_c_del_edge;\n", + " int __pyx_v_c_ins_node;\n", + " int __pyx_v_c_ins_edge;\n", + " PyObject *__pyx_r = 0;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"compare (wrapper)\", 0);\n", + " {\n", + " static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_listgs,&__pyx_n_s_c_del_node,&__pyx_n_s_c_del_edge,&__pyx_n_s_c_ins_node,&__pyx_n_s_c_ins_edge,0};\n", + " PyObject* values[5] = {0,0,0,0,0};\n", + " if (unlikely(__pyx_kwds)) {\n", + " Py_ssize_t kw_args;\n", + " const Py_ssize_t pos_args = <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args);\n", + " switch (pos_args) {\n", + " case 5: values[4] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 4);\n", + " CYTHON_FALLTHROUGH;\n", + " case 4: values[3] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 3);\n", + " CYTHON_FALLTHROUGH;\n", + " case 3: values[2] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 2);\n", + " CYTHON_FALLTHROUGH;\n", + " case 2: values[1] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 1);\n", + " CYTHON_FALLTHROUGH;\n", + " case 1: values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0);\n", + " CYTHON_FALLTHROUGH;\n", + " case 0: break;\n", + " default: goto __pyx_L5_argtuple_error;\n", + " }\n", + " kw_args = <span class='py_c_api'>PyDict_Size</span>(__pyx_kwds);\n", + " switch (pos_args) {\n", + " case 0:\n", + " if (likely((values[0] = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_listgs)) != 0)) kw_args--;\n", + " else goto __pyx_L5_argtuple_error;\n", + " CYTHON_FALLTHROUGH;\n", + " case 1:\n", + " if (kw_args > 0) {\n", + " PyObject* value = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_c_del_node);\n", + " if (value) { values[1] = value; kw_args--; }\n", + " }\n", + " CYTHON_FALLTHROUGH;\n", + " case 2:\n", + " if (kw_args > 0) {\n", + " PyObject* value = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_c_del_edge);\n", + " if (value) { values[2] = value; kw_args--; }\n", + " }\n", + " CYTHON_FALLTHROUGH;\n", + " case 3:\n", + " if (kw_args > 0) {\n", + " PyObject* value = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_c_ins_node);\n", + " if (value) { values[3] = value; kw_args--; }\n", + " }\n", + " CYTHON_FALLTHROUGH;\n", + " case 4:\n", + " if (kw_args > 0) {\n", + " PyObject* value = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_c_ins_edge);\n", + " if (value) { values[4] = value; kw_args--; }\n", + " }\n", + " }\n", + " if (unlikely(kw_args > 0)) {\n", + " if (unlikely(<span class='pyx_c_api'>__Pyx_ParseOptionalKeywords</span>(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, \"compare\") < 0)) <span class='error_goto'>__PYX_ERR(0, 21, __pyx_L3_error)</span>\n", + " }\n", + " } else {\n", + " switch (<span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args)) {\n", + " case 5: values[4] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 4);\n", + " CYTHON_FALLTHROUGH;\n", + " case 4: values[3] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 3);\n", + " CYTHON_FALLTHROUGH;\n", + " case 3: values[2] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 2);\n", + " CYTHON_FALLTHROUGH;\n", + " case 2: values[1] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 1);\n", + " CYTHON_FALLTHROUGH;\n", + " case 1: values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0);\n", + " break;\n", + " default: goto __pyx_L5_argtuple_error;\n", + " }\n", + " }\n", + " __pyx_v_listgs = ((PyObject*)values[0]);\n", + " if (values[1]) {\n", + " __pyx_v_c_del_node = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(values[1]); if (unlikely((__pyx_v_c_del_node == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 21, __pyx_L3_error)</span>\n", + " } else {\n", + " __pyx_v_c_del_node = ((int)1);\n", + " }\n", + " if (values[2]) {\n", + " __pyx_v_c_del_edge = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(values[2]); if (unlikely((__pyx_v_c_del_edge == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 21, __pyx_L3_error)</span>\n", + " } else {\n", + " __pyx_v_c_del_edge = ((int)1);\n", + " }\n", + " if (values[3]) {\n", + " __pyx_v_c_ins_node = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(values[3]); if (unlikely((__pyx_v_c_ins_node == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 21, __pyx_L3_error)</span>\n", + " } else {\n", + " __pyx_v_c_ins_node = ((int)1);\n", + " }\n", + " if (values[4]) {\n", + " __pyx_v_c_ins_edge = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(values[4]); if (unlikely((__pyx_v_c_ins_edge == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 21, __pyx_L3_error)</span>\n", + " } else {\n", + " __pyx_v_c_ins_edge = ((int)1);\n", + " }\n", + " }\n", + " goto __pyx_L4_argument_unpacking_done;\n", + " __pyx_L5_argtuple_error:;\n", + " <span class='pyx_c_api'>__Pyx_RaiseArgtupleInvalid</span>(\"compare\", 0, 1, 5, <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args)); <span class='error_goto'>__PYX_ERR(0, 21, __pyx_L3_error)</span>\n", + " __pyx_L3_error:;\n", + " <span class='pyx_c_api'>__Pyx_AddTraceback</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.compare\", __pyx_clineno, __pyx_lineno, __pyx_filename);\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return NULL;\n", + " __pyx_L4_argument_unpacking_done:;\n", + " if (unlikely(!<span class='pyx_c_api'>__Pyx_ArgTypeTest</span>(((PyObject *)__pyx_v_listgs), (&PyList_Type), 1, \"listgs\", 1))) <span class='error_goto'>__PYX_ERR(0, 21, __pyx_L1_error)</span>\n", + " __pyx_r = __pyx_pf_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_compare(__pyx_v_listgs, __pyx_v_c_del_node, __pyx_v_c_del_edge, __pyx_v_c_ins_node, __pyx_v_c_ins_edge);\n", + "\n", + " /* function exit code */\n", + " goto __pyx_L0;\n", + " __pyx_L1_error:;\n", + " __pyx_r = NULL;\n", + " __pyx_L0:;\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "\n", + "static PyObject *__pyx_pf_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_compare(PyObject *__pyx_v_listgs, int __pyx_v_c_del_node, int __pyx_v_c_del_edge, int __pyx_v_c_ins_node, int __pyx_v_c_ins_edge) {\n", + " int __pyx_v_n;\n", + " struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_v_comparator = NULL;\n", + " PyArrayObject *__pyx_v_comparison_matrix = 0;\n", + " int __pyx_v_i;\n", + " int __pyx_v_j;\n", + " PyObject *__pyx_r = NULL;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"compare\", 0);\n", + "/* … */\n", + " /* function exit code */\n", + " __pyx_L1_error:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6);\n", + " <span class='pyx_c_api'>__Pyx_AddTraceback</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.compare\", __pyx_clineno, __pyx_lineno, __pyx_filename);\n", + " __pyx_r = NULL;\n", + " __pyx_L0:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>((PyObject *)__pyx_v_comparator);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>((PyObject *)__pyx_v_comparison_matrix);\n", + " <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r);\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "/* … */\n", + " __pyx_tuple__11 = <span class='py_c_api'>PyTuple_Pack</span>(10, __pyx_n_s_listgs, __pyx_n_s_c_del_node, __pyx_n_s_c_del_edge, __pyx_n_s_c_ins_node, __pyx_n_s_c_ins_edge, __pyx_n_s_n, __pyx_n_s_comparator, __pyx_n_s_comparison_matrix, __pyx_n_s_i, __pyx_n_s_j);<span class='error_goto'> if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 21, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_tuple__11);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_tuple__11);\n", + "/* … */\n", + " __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_1compare, NULL, __pyx_n_s_cython_magic_dda4cdebdc96d91400);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " if (<span class='py_c_api'>PyDict_SetItem</span>((PyObject *)__pyx_ptype_46_cython_magic_dda4cdebdc96d9140091621511971356_HED->tp_dict, __pyx_n_s_compare, __pyx_t_1) < 0) <span class='error_goto'>__PYX_ERR(0, 21, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " <span class='py_c_api'>PyType_Modified</span>(__pyx_ptype_46_cython_magic_dda4cdebdc96d9140091621511971356_HED);\n", + "/* … */\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetNameInClass</span>((PyObject *)__pyx_ptype_46_cython_magic_dda4cdebdc96d9140091621511971356_HED, __pyx_n_s_compare);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " __pyx_codeobj__12 = (PyObject*)<span class='pyx_c_api'>__Pyx_PyCode_New</span>(5, 0, 10, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_jacquesfize_ipython_cytho, __pyx_n_s_compare, 21, __pyx_empty_bytes);<span class='error_goto'> if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 21, __pyx_L1_error)</span>\n", + "</pre><pre class=\"cython line score-6\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">022</span>: <span class=\"k\">cdef</span> <span class=\"kt\">int</span> <span class=\"nf\">n</span> <span class=\"o\">=</span> <span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">listgs</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-6 '> if (unlikely(__pyx_v_listgs == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"object of type 'NoneType' has no len()\");\n", + " <span class='error_goto'>__PYX_ERR(0, 22, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_1 = <span class='py_macro_api'>PyList_GET_SIZE</span>(__pyx_v_listgs);<span class='error_goto'> if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 22, __pyx_L1_error)</span>\n", + " __pyx_v_n = __pyx_t_1;\n", + "</pre><pre class=\"cython line score-20\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">023</span>: <span class=\"n\">comparator</span> <span class=\"o\">=</span> <span class=\"n\">HED</span><span class=\"p\">(</span><span class=\"n\">c_del_node</span><span class=\"p\">,</span> <span class=\"n\">c_ins_node</span><span class=\"p\">,</span> <span class=\"n\">c_del_edge</span><span class=\"p\">,</span> <span class=\"n\">c_ins_edge</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-20 '> __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_c_del_node);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 23, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_c_ins_node);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 23, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_c_del_edge);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_c_ins_edge);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 23, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " __pyx_t_6 = <span class='py_c_api'>PyTuple_New</span>(4);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 23, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_2);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0, __pyx_t_2);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_3);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 1, __pyx_t_3);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_4);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 2, __pyx_t_4);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_5);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 3, __pyx_t_5);\n", + " __pyx_t_2 = 0;\n", + " __pyx_t_3 = 0;\n", + " __pyx_t_4 = 0;\n", + " __pyx_t_5 = 0;\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(((PyObject *)__pyx_ptype_46_cython_magic_dda4cdebdc96d9140091621511971356_HED), __pyx_t_6, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 23, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " __pyx_v_comparator = ((struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_t_5);\n", + " __pyx_t_5 = 0;\n", + "</pre><pre class=\"cython line score-57\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">024</span>: <span class=\"k\">cdef</span> <span class=\"kt\">np</span>.<span class=\"kt\">ndarray</span> <span class=\"nf\">comparison_matrix</span> <span class=\"o\">=</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">zeros</span><span class=\"p\">((</span><span class=\"n\">n</span><span class=\"p\">,</span> <span class=\"n\">n</span><span class=\"p\">))</span></pre>\n", + "<pre class='cython code score-57 '> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_np);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_6, __pyx_n_s_zeros);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " __pyx_t_6 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_n);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_n);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_2 = <span class='py_c_api'>PyTuple_New</span>(2);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_6);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0, __pyx_t_6);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_3);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 1, __pyx_t_3);\n", + " __pyx_t_6 = 0;\n", + " __pyx_t_3 = 0;\n", + " __pyx_t_3 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && unlikely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_4))) {\n", + " __pyx_t_3 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_4);\n", + " if (likely(__pyx_t_3)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_4, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_3) {\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_4, __pyx_t_2);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_4)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_2};\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_4, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_4)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_2};\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_4, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_6 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_3); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL;\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_2);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0+1, __pyx_t_2);\n", + " __pyx_t_2 = 0;\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_4, __pyx_t_6, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_4); __pyx_t_4 = 0;\n", + " if (!(likely(((__pyx_t_5) == Py_None) || likely(<span class='pyx_c_api'>__Pyx_TypeTest</span>(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) <span class='error_goto'>__PYX_ERR(0, 24, __pyx_L1_error)</span>\n", + " __pyx_v_comparison_matrix = ((PyArrayObject *)__pyx_t_5);\n", + " __pyx_t_5 = 0;\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">025</span>: <span class=\"k\">for</span> <span class=\"n\">i</span> <span class=\"ow\">in</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"n\">n</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_t_7 = __pyx_v_n;\n", + " __pyx_t_8 = __pyx_t_7;\n", + " for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {\n", + " __pyx_v_i = __pyx_t_9;\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">026</span>: <span class=\"k\">for</span> <span class=\"n\">j</span> <span class=\"ow\">in</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"n\">i</span><span class=\"p\">,</span> <span class=\"n\">n</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_t_10 = __pyx_v_n;\n", + " __pyx_t_11 = __pyx_t_10;\n", + " for (__pyx_t_12 = __pyx_v_i; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {\n", + " __pyx_v_j = __pyx_t_12;\n", + "</pre><pre class=\"cython line score-39\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">027</span>: <span class=\"n\">comparison_matrix</span><span class=\"p\">[</span><span class=\"n\">i</span><span class=\"p\">,</span> <span class=\"n\">j</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"n\">comparator</span><span class=\"o\">.</span><span class=\"n\">hed</span><span class=\"p\">(</span><span class=\"n\">listgs</span><span class=\"p\">[</span><span class=\"n\">i</span><span class=\"p\">],</span> <span class=\"n\">listgs</span><span class=\"p\">[</span><span class=\"n\">j</span><span class=\"p\">])</span></pre>\n", + "<pre class='cython code score-39 '> if (unlikely(__pyx_v_listgs == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"'NoneType' object is not subscriptable\");\n", + " <span class='error_goto'>__PYX_ERR(0, 27, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_GetItemInt_List</span>(__pyx_v_listgs, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 27, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " if (unlikely(__pyx_v_listgs == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"'NoneType' object is not subscriptable\");\n", + " <span class='error_goto'>__PYX_ERR(0, 27, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_GetItemInt_List</span>(__pyx_v_listgs, __pyx_v_j, int, 1, __Pyx_PyInt_From_int, 1, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 27, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " __pyx_t_6 = <span class='py_c_api'>PyFloat_FromDouble</span>(((struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_comparator->__pyx_vtab)->hed(__pyx_v_comparator, __pyx_t_5, __pyx_t_4, 0));<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 27, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_4); __pyx_t_4 = 0;\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_i);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 27, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_j);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 27, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " __pyx_t_2 = <span class='py_c_api'>PyTuple_New</span>(2);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_4);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0, __pyx_t_4);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_5);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 1, __pyx_t_5);\n", + " __pyx_t_4 = 0;\n", + " __pyx_t_5 = 0;\n", + " if (unlikely(<span class='py_c_api'>PyObject_SetItem</span>(((PyObject *)__pyx_v_comparison_matrix), __pyx_t_2, __pyx_t_6) < 0)) <span class='error_goto'>__PYX_ERR(0, 27, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + "</pre><pre class=\"cython line score-32\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">028</span>: <span class=\"n\">comparison_matrix</span><span class=\"p\">[</span><span class=\"n\">j</span><span class=\"p\">,</span> <span class=\"n\">i</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"n\">comparison_matrix</span><span class=\"p\">[</span><span class=\"n\">i</span><span class=\"p\">,</span> <span class=\"n\">j</span><span class=\"p\">]</span></pre>\n", + "<pre class='cython code score-32 '> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_i);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 28, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_j);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 28, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " __pyx_t_5 = <span class='py_c_api'>PyTuple_New</span>(2);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 28, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_6);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_5, 0, __pyx_t_6);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_2);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_5, 1, __pyx_t_2);\n", + " __pyx_t_6 = 0;\n", + " __pyx_t_2 = 0;\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_GetItem</span>(((PyObject *)__pyx_v_comparison_matrix), __pyx_t_5);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 28, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_j);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 28, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " __pyx_t_6 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_i);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 28, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " __pyx_t_4 = <span class='py_c_api'>PyTuple_New</span>(2);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 28, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_5);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_4, 0, __pyx_t_5);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_6);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_4, 1, __pyx_t_6);\n", + " __pyx_t_5 = 0;\n", + " __pyx_t_6 = 0;\n", + " if (unlikely(<span class='py_c_api'>PyObject_SetItem</span>(((PyObject *)__pyx_v_comparison_matrix), __pyx_t_4, __pyx_t_2) < 0)) <span class='error_goto'>__PYX_ERR(0, 28, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_4); __pyx_t_4 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " }\n", + " }\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">029</span>: </pre>\n", + "<pre class=\"cython line score-2\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">030</span>: <span class=\"k\">return</span> <span class=\"n\">comparison_matrix</span></pre>\n", + "<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(((PyObject *)__pyx_v_comparison_matrix));\n", + " __pyx_r = ((PyObject *)__pyx_v_comparison_matrix);\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">031</span>: </pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">032</span>: </pre>\n", + "<pre class=\"cython line score-58\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">033</span>: <span class=\"k\">def</span> <span class=\"nf\">__init__</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"nb\">int</span> <span class=\"n\">node_del</span><span class=\"o\">=</span><span class=\"mf\">1</span><span class=\"p\">,</span> <span class=\"nb\">int</span> <span class=\"n\">node_ins</span><span class=\"o\">=</span><span class=\"mf\">1</span><span class=\"p\">,</span> <span class=\"nb\">int</span> <span class=\"n\">edge_del</span><span class=\"o\">=</span><span class=\"mf\">1</span><span class=\"p\">,</span> <span class=\"nb\">int</span> <span class=\"n\">edge_ins</span><span class=\"o\">=</span><span class=\"mf\">1</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-58 '>/* Python wrapper */\n", + "static int __pyx_pw_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/\n", + "static char __pyx_doc_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_2__init__[] = \"Constructor for HED\";\n", + "#if CYTHON_COMPILING_IN_CPYTHON\n", + "struct wrapperbase __pyx_wrapperbase_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_2__init__;\n", + "#endif\n", + "static int __pyx_pw_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {\n", + " int __pyx_v_node_del;\n", + " int __pyx_v_node_ins;\n", + " int __pyx_v_edge_del;\n", + " int __pyx_v_edge_ins;\n", + " int __pyx_r;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"__init__ (wrapper)\", 0);\n", + " {\n", + " static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_node_del,&__pyx_n_s_node_ins,&__pyx_n_s_edge_del,&__pyx_n_s_edge_ins,0};\n", + " PyObject* values[4] = {0,0,0,0};\n", + " if (unlikely(__pyx_kwds)) {\n", + " Py_ssize_t kw_args;\n", + " const Py_ssize_t pos_args = <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args);\n", + " switch (pos_args) {\n", + " case 4: values[3] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 3);\n", + " CYTHON_FALLTHROUGH;\n", + " case 3: values[2] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 2);\n", + " CYTHON_FALLTHROUGH;\n", + " case 2: values[1] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 1);\n", + " CYTHON_FALLTHROUGH;\n", + " case 1: values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0);\n", + " CYTHON_FALLTHROUGH;\n", + " case 0: break;\n", + " default: goto __pyx_L5_argtuple_error;\n", + " }\n", + " kw_args = <span class='py_c_api'>PyDict_Size</span>(__pyx_kwds);\n", + " switch (pos_args) {\n", + " case 0:\n", + " if (kw_args > 0) {\n", + " PyObject* value = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_node_del);\n", + " if (value) { values[0] = value; kw_args--; }\n", + " }\n", + " CYTHON_FALLTHROUGH;\n", + " case 1:\n", + " if (kw_args > 0) {\n", + " PyObject* value = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_node_ins);\n", + " if (value) { values[1] = value; kw_args--; }\n", + " }\n", + " CYTHON_FALLTHROUGH;\n", + " case 2:\n", + " if (kw_args > 0) {\n", + " PyObject* value = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_edge_del);\n", + " if (value) { values[2] = value; kw_args--; }\n", + " }\n", + " CYTHON_FALLTHROUGH;\n", + " case 3:\n", + " if (kw_args > 0) {\n", + " PyObject* value = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_edge_ins);\n", + " if (value) { values[3] = value; kw_args--; }\n", + " }\n", + " }\n", + " if (unlikely(kw_args > 0)) {\n", + " if (unlikely(<span class='pyx_c_api'>__Pyx_ParseOptionalKeywords</span>(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, \"__init__\") < 0)) <span class='error_goto'>__PYX_ERR(0, 33, __pyx_L3_error)</span>\n", + " }\n", + " } else {\n", + " switch (<span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args)) {\n", + " case 4: values[3] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 3);\n", + " CYTHON_FALLTHROUGH;\n", + " case 3: values[2] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 2);\n", + " CYTHON_FALLTHROUGH;\n", + " case 2: values[1] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 1);\n", + " CYTHON_FALLTHROUGH;\n", + " case 1: values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0);\n", + " CYTHON_FALLTHROUGH;\n", + " case 0: break;\n", + " default: goto __pyx_L5_argtuple_error;\n", + " }\n", + " }\n", + " if (values[0]) {\n", + " __pyx_v_node_del = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(values[0]); if (unlikely((__pyx_v_node_del == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 33, __pyx_L3_error)</span>\n", + " } else {\n", + " __pyx_v_node_del = ((int)1);\n", + " }\n", + " if (values[1]) {\n", + " __pyx_v_node_ins = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(values[1]); if (unlikely((__pyx_v_node_ins == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 33, __pyx_L3_error)</span>\n", + " } else {\n", + " __pyx_v_node_ins = ((int)1);\n", + " }\n", + " if (values[2]) {\n", + " __pyx_v_edge_del = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(values[2]); if (unlikely((__pyx_v_edge_del == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 33, __pyx_L3_error)</span>\n", + " } else {\n", + " __pyx_v_edge_del = ((int)1);\n", + " }\n", + " if (values[3]) {\n", + " __pyx_v_edge_ins = <span class='pyx_c_api'>__Pyx_PyInt_As_int</span>(values[3]); if (unlikely((__pyx_v_edge_ins == (int)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 33, __pyx_L3_error)</span>\n", + " } else {\n", + " __pyx_v_edge_ins = ((int)1);\n", + " }\n", + " }\n", + " goto __pyx_L4_argument_unpacking_done;\n", + " __pyx_L5_argtuple_error:;\n", + " <span class='pyx_c_api'>__Pyx_RaiseArgtupleInvalid</span>(\"__init__\", 0, 0, 4, <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args)); <span class='error_goto'>__PYX_ERR(0, 33, __pyx_L3_error)</span>\n", + " __pyx_L3_error:;\n", + " <span class='pyx_c_api'>__Pyx_AddTraceback</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.__init__\", __pyx_clineno, __pyx_lineno, __pyx_filename);\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return -1;\n", + " __pyx_L4_argument_unpacking_done:;\n", + " __pyx_r = __pyx_pf_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_2__init__(((struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self), __pyx_v_node_del, __pyx_v_node_ins, __pyx_v_edge_del, __pyx_v_edge_ins);\n", + "\n", + " /* function exit code */\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "\n", + "static int __pyx_pf_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_2__init__(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_v_self, int __pyx_v_node_del, int __pyx_v_node_ins, int __pyx_v_edge_del, int __pyx_v_edge_ins) {\n", + " int __pyx_r;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"__init__\", 0);\n", + "/* … */\n", + " /* function exit code */\n", + " __pyx_r = 0;\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">034</span>: <span class=\"sd\">"""Constructor for HED"""</span></pre>\n", + "<pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">035</span>: <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">node_del</span> <span class=\"o\">=</span> <span class=\"n\">node_del</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_v_self->node_del = __pyx_v_node_del;\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">036</span>: <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">node_ins</span> <span class=\"o\">=</span> <span class=\"n\">node_ins</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_v_self->node_ins = __pyx_v_node_ins;\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">037</span>: <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">edge_del</span> <span class=\"o\">=</span> <span class=\"n\">edge_del</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_v_self->edge_del = __pyx_v_edge_del;\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">038</span>: <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">edge_ins</span> <span class=\"o\">=</span> <span class=\"n\">edge_ins</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_v_self->edge_ins = __pyx_v_edge_ins;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">039</span>: </pre>\n", + "<pre class=\"cython line score-93\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">040</span>: <span class=\"k\">cpdef</span> <span class=\"kt\">float</span> <span class=\"nf\">hed</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">g2</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-93 '>static PyObject *__pyx_pw_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_5hed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/\n", + "static float __pyx_f_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_hed(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_v_self, PyObject *__pyx_v_g1, PyObject *__pyx_v_g2, int __pyx_skip_dispatch) {\n", + " float __pyx_r;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"hed\", 0);\n", + " /* Check if called by wrapper */\n", + " if (unlikely(__pyx_skip_dispatch)) ;\n", + " /* Check if overridden in Python */\n", + " else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(((PyObject *)__pyx_v_self), __pyx_n_s_hed);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 40, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_5hed)) {\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_1);\n", + " __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;\n", + " __pyx_t_5 = 0;\n", + " if (CYTHON_UNPACK_METHODS && unlikely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_3))) {\n", + " __pyx_t_4 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_3);\n", + " if (likely(__pyx_t_4)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_3, function);\n", + " __pyx_t_5 = 1;\n", + " }\n", + " }\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_g1, __pyx_v_g2};\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_4); __pyx_t_4 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_g1, __pyx_v_g2};\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_4); __pyx_t_4 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_6 = <span class='py_c_api'>PyTuple_New</span>(2+__pyx_t_5);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 40, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " if (__pyx_t_4) {\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_4); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_g1);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_g1);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0+__pyx_t_5, __pyx_v_g1);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_g2);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_g2);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 1+__pyx_t_5, __pyx_v_g2);\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_3, __pyx_t_6, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " __pyx_t_7 = __pyx_<span class='py_c_api'>PyFloat_AsFloat</span>(__pyx_t_2); if (unlikely((__pyx_t_7 == (float)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 40, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " __pyx_r = __pyx_t_7;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " goto __pyx_L0;\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " }\n", + "/* … */\n", + " /* function exit code */\n", + " __pyx_L1_error:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6);\n", + " <span class='pyx_c_api'>__Pyx_WriteUnraisable</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.hed\", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);\n", + " __pyx_r = 0;\n", + " __pyx_L0:;\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "\n", + "/* Python wrapper */\n", + "static PyObject *__pyx_pw_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_5hed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/\n", + "static char __pyx_doc_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_4hed[] = \"\\n Compute de Hausdorff Edit Distance\\n :param g1: first graph\\n :param g2: second graph\\n :return:\\n \";\n", + "static PyObject *__pyx_pw_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_5hed(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {\n", + " PyObject *__pyx_v_g1 = 0;\n", + " PyObject *__pyx_v_g2 = 0;\n", + " PyObject *__pyx_r = 0;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"hed (wrapper)\", 0);\n", + " {\n", + " static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_g1,&__pyx_n_s_g2,0};\n", + " PyObject* values[2] = {0,0};\n", + " if (unlikely(__pyx_kwds)) {\n", + " Py_ssize_t kw_args;\n", + " const Py_ssize_t pos_args = <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args);\n", + " switch (pos_args) {\n", + " case 2: values[1] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 1);\n", + " CYTHON_FALLTHROUGH;\n", + " case 1: values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0);\n", + " CYTHON_FALLTHROUGH;\n", + " case 0: break;\n", + " default: goto __pyx_L5_argtuple_error;\n", + " }\n", + " kw_args = <span class='py_c_api'>PyDict_Size</span>(__pyx_kwds);\n", + " switch (pos_args) {\n", + " case 0:\n", + " if (likely((values[0] = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_g1)) != 0)) kw_args--;\n", + " else goto __pyx_L5_argtuple_error;\n", + " CYTHON_FALLTHROUGH;\n", + " case 1:\n", + " if (likely((values[1] = <span class='pyx_c_api'>__Pyx_PyDict_GetItemStr</span>(__pyx_kwds, __pyx_n_s_g2)) != 0)) kw_args--;\n", + " else {\n", + " <span class='pyx_c_api'>__Pyx_RaiseArgtupleInvalid</span>(\"hed\", 1, 2, 2, 1); <span class='error_goto'>__PYX_ERR(0, 40, __pyx_L3_error)</span>\n", + " }\n", + " }\n", + " if (unlikely(kw_args > 0)) {\n", + " if (unlikely(<span class='pyx_c_api'>__Pyx_ParseOptionalKeywords</span>(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, \"hed\") < 0)) <span class='error_goto'>__PYX_ERR(0, 40, __pyx_L3_error)</span>\n", + " }\n", + " } else if (<span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args) != 2) {\n", + " goto __pyx_L5_argtuple_error;\n", + " } else {\n", + " values[0] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 0);\n", + " values[1] = <span class='py_macro_api'>PyTuple_GET_ITEM</span>(__pyx_args, 1);\n", + " }\n", + " __pyx_v_g1 = values[0];\n", + " __pyx_v_g2 = values[1];\n", + " }\n", + " goto __pyx_L4_argument_unpacking_done;\n", + " __pyx_L5_argtuple_error:;\n", + " <span class='pyx_c_api'>__Pyx_RaiseArgtupleInvalid</span>(\"hed\", 1, 2, 2, <span class='py_macro_api'>PyTuple_GET_SIZE</span>(__pyx_args)); <span class='error_goto'>__PYX_ERR(0, 40, __pyx_L3_error)</span>\n", + " __pyx_L3_error:;\n", + " <span class='pyx_c_api'>__Pyx_AddTraceback</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.hed\", __pyx_clineno, __pyx_lineno, __pyx_filename);\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return NULL;\n", + " __pyx_L4_argument_unpacking_done:;\n", + " __pyx_r = __pyx_pf_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_4hed(((struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self), __pyx_v_g1, __pyx_v_g2);\n", + "\n", + " /* function exit code */\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "\n", + "static PyObject *__pyx_pf_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_4hed(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_v_self, PyObject *__pyx_v_g1, PyObject *__pyx_v_g2) {\n", + " PyObject *__pyx_r = NULL;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"hed\", 0);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r);\n", + " __pyx_t_1 = <span class='py_c_api'>PyFloat_FromDouble</span>(__pyx_f_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_hed(__pyx_v_self, __pyx_v_g1, __pyx_v_g2, 1));<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 40, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " __pyx_r = __pyx_t_1;\n", + " __pyx_t_1 = 0;\n", + " goto __pyx_L0;\n", + "\n", + " /* function exit code */\n", + " __pyx_L1_error:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);\n", + " <span class='pyx_c_api'>__Pyx_AddTraceback</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.hed\", __pyx_clineno, __pyx_lineno, __pyx_filename);\n", + " __pyx_r = NULL;\n", + " __pyx_L0:;\n", + " <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r);\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">041</span>: <span class=\"sd\">"""</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">042</span>: <span class=\"sd\"> Compute de Hausdorff Edit Distance</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">043</span>: <span class=\"sd\"> :param g1: first graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">044</span>: <span class=\"sd\"> :param g2: second graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">045</span>: <span class=\"sd\"> :return:</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">046</span>: <span class=\"sd\"> """</span></pre>\n", + "<pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">047</span>: <span class=\"k\">return</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">sum_fuv</span><span class=\"p\">(</span><span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">g2</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">sum_fuv</span><span class=\"p\">(</span><span class=\"n\">g2</span><span class=\"p\">,</span> <span class=\"n\">g1</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_r = (((struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self->__pyx_vtab)->sum_fuv(__pyx_v_self, __pyx_v_g1, __pyx_v_g2) + ((struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self->__pyx_vtab)->sum_fuv(__pyx_v_self, __pyx_v_g2, __pyx_v_g1));\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">048</span>: </pre>\n", + "<pre class=\"cython line score-11\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">049</span>: <span class=\"k\">cdef</span> <span class=\"kt\">float</span> <span class=\"nf\">sum_fuv</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">g2</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-11 '>static float __pyx_f_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_sum_fuv(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_v_self, PyObject *__pyx_v_g1, PyObject *__pyx_v_g2) {\n", + " PyArrayObject *__pyx_v_min_sum = 0;\n", + " PyObject *__pyx_v_nodes1 = NULL;\n", + " PyObject *__pyx_v_nodes2 = NULL;\n", + " PyArrayObject *__pyx_v_min_i = 0;\n", + " Py_ssize_t __pyx_v_i;\n", + " Py_ssize_t __pyx_v_j;\n", + " float __pyx_r;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"sum_fuv\", 0);\n", + "/* … */\n", + " /* function exit code */\n", + " __pyx_L1_error:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6);\n", + " <span class='pyx_c_api'>__Pyx_WriteUnraisable</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.sum_fuv\", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);\n", + " __pyx_r = 0;\n", + " __pyx_L0:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>((PyObject *)__pyx_v_min_sum);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_nodes1);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_nodes2);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>((PyObject *)__pyx_v_min_i);\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">050</span>: <span class=\"sd\">"""</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">051</span>: <span class=\"sd\"> Compute Nearest Neighbour Distance between G1 and G2</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">052</span>: <span class=\"sd\"> :param g1: First Graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">053</span>: <span class=\"sd\"> :param g2: Second Graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">054</span>: <span class=\"sd\"> :return:</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">055</span>: <span class=\"sd\"> """</span></pre>\n", + "<pre class=\"cython line score-56\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">056</span>: <span class=\"k\">cdef</span> <span class=\"kt\">np</span>.<span class=\"kt\">ndarray</span> <span class=\"nf\">min_sum</span> <span class=\"o\">=</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">zeros</span><span class=\"p\">(</span><span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">g1</span><span class=\"p\">))</span></pre>\n", + "<pre class='cython code score-56 '> __pyx_t_2 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_np);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 56, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_2, __pyx_n_s_zeros);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 56, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " __pyx_t_4 = <span class='py_c_api'>PyObject_Length</span>(__pyx_v_g1);<span class='error_goto'> if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 56, __pyx_L1_error)</span>\n", + " __pyx_t_2 = <span class='py_c_api'>PyInt_FromSsize_t</span>(__pyx_t_4);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 56, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " __pyx_t_5 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && unlikely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_3))) {\n", + " __pyx_t_5 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_3);\n", + " if (likely(__pyx_t_5)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_3, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_5) {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_3, __pyx_t_2);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_2};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_2};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_6 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 56, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_5); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_2);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0+1, __pyx_t_2);\n", + " __pyx_t_2 = 0;\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_3, __pyx_t_6, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " if (!(likely(((__pyx_t_1) == Py_None) || likely(<span class='pyx_c_api'>__Pyx_TypeTest</span>(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) <span class='error_goto'>__PYX_ERR(0, 56, __pyx_L1_error)</span>\n", + " __pyx_v_min_sum = ((PyArrayObject *)__pyx_t_1);\n", + " __pyx_t_1 = 0;\n", + "</pre><pre class=\"cython line score-18\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">057</span>: <span class=\"n\">nodes1</span> <span class=\"o\">=</span> <span class=\"n\">g1</span><span class=\"o\">.</span><span class=\"n\">nodes</span><span class=\"p\">()</span></pre>\n", + "<pre class='cython code score-18 '> __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_g1, __pyx_n_s_nodes);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 57, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_6 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && likely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_3))) {\n", + " __pyx_t_6 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_3);\n", + " if (likely(__pyx_t_6)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_6);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_3, function);\n", + " }\n", + " }\n", + " if (__pyx_t_6) {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_3, __pyx_t_6);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " } else {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallNoArg</span>(__pyx_t_3);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error)</span>\n", + " }\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " __pyx_v_nodes1 = __pyx_t_1;\n", + " __pyx_t_1 = 0;\n", + "</pre><pre class=\"cython line score-18\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">058</span>: <span class=\"n\">nodes2</span> <span class=\"o\">=</span> <span class=\"n\">g2</span><span class=\"o\">.</span><span class=\"n\">nodes</span><span class=\"p\">()</span></pre>\n", + "<pre class='cython code score-18 '> __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_g2, __pyx_n_s_nodes);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 58, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_6 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && likely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_3))) {\n", + " __pyx_t_6 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_3);\n", + " if (likely(__pyx_t_6)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_6);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_3, function);\n", + " }\n", + " }\n", + " if (__pyx_t_6) {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_3, __pyx_t_6);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " } else {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallNoArg</span>(__pyx_t_3);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error)</span>\n", + " }\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " __pyx_v_nodes2 = __pyx_t_1;\n", + " __pyx_t_1 = 0;\n", + "</pre><pre class=\"cython line score-49\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">059</span>: <span class=\"n\">nodes2</span><span class=\"o\">.</span><span class=\"n\">extend</span><span class=\"p\">([</span><span class=\"bp\">None</span><span class=\"p\">])</span></pre>\n", + "<pre class='cython code score-49 '> __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_nodes2, __pyx_n_s_extend);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 59, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_6 = <span class='py_c_api'>PyList_New</span>(1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 59, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(Py_None);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(Py_None);\n", + " <span class='py_macro_api'>PyList_SET_ITEM</span>(__pyx_t_6, 0, Py_None);\n", + " __pyx_t_2 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && likely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_3))) {\n", + " __pyx_t_2 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_3);\n", + " if (likely(__pyx_t_2)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_3, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_2) {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_3, __pyx_t_6);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_6};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_6};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_5 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 59, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_2); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_6);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_5, 0+1, __pyx_t_6);\n", + " __pyx_t_6 = 0;\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_3, __pyx_t_5, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">060</span>: <span class=\"k\">cdef</span> <span class=\"kt\">np</span>.<span class=\"kt\">ndarray</span> <span class=\"nf\">min_i</span></pre>\n", + "<pre class=\"cython line score-5\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">061</span>: <span class=\"k\">for</span> <span class=\"n\">i</span> <span class=\"ow\">in</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">nodes1</span><span class=\"p\">)):</span></pre>\n", + "<pre class='cython code score-5 '> __pyx_t_4 = <span class='py_c_api'>PyObject_Length</span>(__pyx_v_nodes1);<span class='error_goto'> if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 61, __pyx_L1_error)</span>\n", + " __pyx_t_7 = __pyx_t_4;\n", + " for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {\n", + " __pyx_v_i = __pyx_t_8;\n", + "</pre><pre class=\"cython line score-57\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">062</span>: <span class=\"n\">min_i</span> <span class=\"o\">=</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">zeros</span><span class=\"p\">(</span><span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">nodes2</span><span class=\"p\">))</span></pre>\n", + "<pre class='cython code score-57 '> __pyx_t_3 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_np);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 62, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_3, __pyx_n_s_zeros);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 62, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " __pyx_t_9 = <span class='py_c_api'>PyObject_Length</span>(__pyx_v_nodes2);<span class='error_goto'> if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 62, __pyx_L1_error)</span>\n", + " __pyx_t_3 = <span class='py_c_api'>PyInt_FromSsize_t</span>(__pyx_t_9);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 62, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_6 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && unlikely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_5))) {\n", + " __pyx_t_6 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_5);\n", + " if (likely(__pyx_t_6)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_6);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_5, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_6) {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_5, __pyx_t_3);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_5)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_3};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_5, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_5)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_3};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_5, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_2 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 62, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_6); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0, __pyx_t_6); __pyx_t_6 = NULL;\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_3);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0+1, __pyx_t_3);\n", + " __pyx_t_3 = 0;\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_5, __pyx_t_2, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " if (!(likely(((__pyx_t_1) == Py_None) || likely(<span class='pyx_c_api'>__Pyx_TypeTest</span>(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) <span class='error_goto'>__PYX_ERR(0, 62, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF_SET</span>(__pyx_v_min_i, ((PyArrayObject *)__pyx_t_1));\n", + " __pyx_t_1 = 0;\n", + "</pre><pre class=\"cython line score-5\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">063</span>: <span class=\"k\">for</span> <span class=\"n\">j</span> <span class=\"ow\">in</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">nodes2</span><span class=\"p\">)):</span></pre>\n", + "<pre class='cython code score-5 '> __pyx_t_9 = <span class='py_c_api'>PyObject_Length</span>(__pyx_v_nodes2);<span class='error_goto'> if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 63, __pyx_L1_error)</span>\n", + " __pyx_t_10 = __pyx_t_9;\n", + " for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {\n", + " __pyx_v_j = __pyx_t_11;\n", + "</pre><pre class=\"cython line score-14\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">064</span>: <span class=\"n\">min_i</span><span class=\"p\">[</span><span class=\"n\">j</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">fuv</span><span class=\"p\">(</span><span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">g2</span><span class=\"p\">,</span> <span class=\"n\">nodes1</span><span class=\"p\">[</span><span class=\"n\">i</span><span class=\"p\">],</span> <span class=\"n\">nodes2</span><span class=\"p\">[</span><span class=\"n\">j</span><span class=\"p\">])</span></pre>\n", + "<pre class='cython code score-14 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_nodes1, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_nodes2, __pyx_v_j, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 64, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " __pyx_t_2 = <span class='py_c_api'>PyFloat_FromDouble</span>(((struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self->__pyx_vtab)->fuv(__pyx_v_self, __pyx_v_g1, __pyx_v_g2, __pyx_t_1, __pyx_t_5));<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 64, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " if (unlikely(<span class='pyx_c_api'>__Pyx_SetItemInt</span>(((PyObject *)__pyx_v_min_i), __pyx_v_j, __pyx_t_2, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1) < 0)) <span class='error_goto'>__PYX_ERR(0, 64, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " }\n", + "</pre><pre class=\"cython line score-45\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">065</span>: <span class=\"n\">min_sum</span><span class=\"p\">[</span><span class=\"n\">i</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">min</span><span class=\"p\">(</span><span class=\"n\">min_i</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-45 '> __pyx_t_5 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_np);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 65, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_5, __pyx_n_s_min);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " __pyx_t_5 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && unlikely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_1))) {\n", + " __pyx_t_5 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_1);\n", + " if (likely(__pyx_t_5)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_1, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_5) {\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_1, ((PyObject *)__pyx_v_min_i));<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 65, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_1)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_5, ((PyObject *)__pyx_v_min_i)};\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_1, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 65, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_1)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_5, ((PyObject *)__pyx_v_min_i)};\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_1, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 65, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_3 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 65, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_5); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL;\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(((PyObject *)__pyx_v_min_i));\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(((PyObject *)__pyx_v_min_i));\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_3, 0+1, ((PyObject *)__pyx_v_min_i));\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_1, __pyx_t_3, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 65, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " if (unlikely(<span class='pyx_c_api'>__Pyx_SetItemInt</span>(((PyObject *)__pyx_v_min_sum), __pyx_v_i, __pyx_t_2, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1) < 0)) <span class='error_goto'>__PYX_ERR(0, 65, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " }\n", + "</pre><pre class=\"cython line score-53\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">066</span>: <span class=\"k\">return</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">sum</span><span class=\"p\">(</span><span class=\"n\">min_sum</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-53 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_np);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_1, __pyx_n_s_sum);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 66, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " __pyx_t_1 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && unlikely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_3))) {\n", + " __pyx_t_1 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_3);\n", + " if (likely(__pyx_t_1)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_3, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_1) {\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_3, ((PyObject *)__pyx_v_min_sum));<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_1, ((PyObject *)__pyx_v_min_sum)};\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_1, ((PyObject *)__pyx_v_min_sum)};\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_5 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 66, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_5, 0, __pyx_t_1); __pyx_t_1 = NULL;\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(((PyObject *)__pyx_v_min_sum));\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(((PyObject *)__pyx_v_min_sum));\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_min_sum));\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_3, __pyx_t_5, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " __pyx_t_12 = __pyx_<span class='py_c_api'>PyFloat_AsFloat</span>(__pyx_t_2); if (unlikely((__pyx_t_12 == (float)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 66, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " __pyx_r = __pyx_t_12;\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">067</span>: </pre>\n", + "<pre class=\"cython line score-8\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">068</span>: <span class=\"k\">cdef</span> <span class=\"kt\">float</span> <span class=\"nf\">fuv</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">g2</span><span class=\"p\">,</span> <span class=\"n\">n1</span><span class=\"p\">,</span> <span class=\"n\">n2</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-8 '>static float __pyx_f_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_fuv(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_v_self, PyObject *__pyx_v_g1, PyObject *__pyx_v_g2, PyObject *__pyx_v_n1, PyObject *__pyx_v_n2) {\n", + " float __pyx_r;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"fuv\", 0);\n", + "/* … */\n", + " /* function exit code */\n", + " __pyx_L1_error:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_7);\n", + " <span class='pyx_c_api'>__Pyx_WriteUnraisable</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.fuv\", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);\n", + " __pyx_r = 0;\n", + " __pyx_L0:;\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">069</span>: <span class=\"sd\">"""</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">070</span>: <span class=\"sd\"> Compute the Node Distance function</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">071</span>: <span class=\"sd\"> :param g1: first graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">072</span>: <span class=\"sd\"> :param g2: second graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">073</span>: <span class=\"sd\"> :param n1: node of the first graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">074</span>: <span class=\"sd\"> :param n2: node of the second graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">075</span>: <span class=\"sd\"> :return:</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">076</span>: <span class=\"sd\"> """</span></pre>\n", + "<pre class=\"cython line score-8\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">077</span>: <span class=\"k\">if</span> <span class=\"n\">n2</span> <span class=\"o\">==</span> <span class=\"bp\">None</span><span class=\"p\">:</span> <span class=\"c\"># Del</span></pre>\n", + "<pre class='cython code score-8 '> __pyx_t_1 = <span class='py_c_api'>PyObject_RichCompare</span>(__pyx_v_n2, Py_None, Py_EQ); <span class='refnanny'>__Pyx_XGOTREF</span>(__pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error)</span>\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_IsTrue</span>(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) <span class='error_goto'>__PYX_ERR(0, 77, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " if (__pyx_t_2) {\n", + "/* … */\n", + " }\n", + "</pre><pre class=\"cython line score-71\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">078</span>: <span class=\"k\">return</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">node_del</span> <span class=\"o\">+</span> <span class=\"p\">((</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">edge_del</span> <span class=\"o\">/</span> <span class=\"mf\">2</span><span class=\"p\">)</span> <span class=\"o\">*</span> <span class=\"n\">g1</span><span class=\"o\">.</span><span class=\"n\">degree</span><span class=\"p\">(</span><span class=\"n\">n1</span><span class=\"p\">))</span></pre>\n", + "<pre class='cython code score-71 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_self->node_del);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " __pyx_t_3 = <span class='py_c_api'>PyFloat_FromDouble</span>((((double)__pyx_v_self->edge_del) / 2.0));<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_g1, __pyx_n_s_degree);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " __pyx_t_6 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && likely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_5))) {\n", + " __pyx_t_6 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_5);\n", + " if (likely(__pyx_t_6)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_6);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_5, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_6) {\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_5, __pyx_v_n1);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_5)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_n1};\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_5, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_5)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_n1};\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_5, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_7 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_7);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_6); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_n1);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_n1);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_7, 0+1, __pyx_v_n1);\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_5, __pyx_t_7, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_7); __pyx_t_7 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " __pyx_t_5 = <span class='py_c_api'>PyNumber_Multiply</span>(__pyx_t_3, __pyx_t_4);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_4); __pyx_t_4 = 0;\n", + " __pyx_t_4 = <span class='py_c_api'>PyNumber_Add</span>(__pyx_t_1, __pyx_t_5);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " __pyx_t_8 = __pyx_<span class='py_c_api'>PyFloat_AsFloat</span>(__pyx_t_4); if (unlikely((__pyx_t_8 == (float)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 78, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_4); __pyx_t_4 = 0;\n", + " __pyx_r = __pyx_t_8;\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-8\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">079</span>: <span class=\"k\">if</span> <span class=\"n\">n1</span> <span class=\"o\">==</span> <span class=\"bp\">None</span><span class=\"p\">:</span> <span class=\"c\"># Insert</span></pre>\n", + "<pre class='cython code score-8 '> __pyx_t_4 = <span class='py_c_api'>PyObject_RichCompare</span>(__pyx_v_n1, Py_None, Py_EQ); <span class='refnanny'>__Pyx_XGOTREF</span>(__pyx_t_4);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 79, __pyx_L1_error)</span>\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_IsTrue</span>(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) <span class='error_goto'>__PYX_ERR(0, 79, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_4); __pyx_t_4 = 0;\n", + " if (__pyx_t_2) {\n", + "/* … */\n", + " }\n", + "</pre><pre class=\"cython line score-71\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">080</span>: <span class=\"k\">return</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">node_ins</span> <span class=\"o\">+</span> <span class=\"p\">((</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">edge_ins</span> <span class=\"o\">/</span> <span class=\"mf\">2</span><span class=\"p\">)</span> <span class=\"o\">*</span> <span class=\"n\">g2</span><span class=\"o\">.</span><span class=\"n\">degree</span><span class=\"p\">(</span><span class=\"n\">n2</span><span class=\"p\">))</span></pre>\n", + "<pre class='cython code score-71 '> __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyInt_From_int</span>(__pyx_v_self->node_ins);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " __pyx_t_5 = <span class='py_c_api'>PyFloat_FromDouble</span>((((double)__pyx_v_self->edge_ins) / 2.0));<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_g2, __pyx_n_s_degree);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_7 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && likely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_3))) {\n", + " __pyx_t_7 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_3);\n", + " if (likely(__pyx_t_7)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_7);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_3, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_7) {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_3, __pyx_v_n2);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_n2};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_7); __pyx_t_7 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_v_n2};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_7); __pyx_t_7 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_6 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_7); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL;\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_n2);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_n2);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0+1, __pyx_v_n2);\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_3, __pyx_t_6, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " __pyx_t_3 = <span class='py_c_api'>PyNumber_Multiply</span>(__pyx_t_5, __pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " __pyx_t_1 = <span class='py_c_api'>PyNumber_Add</span>(__pyx_t_4, __pyx_t_3);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_4); __pyx_t_4 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " __pyx_t_8 = __pyx_<span class='py_c_api'>PyFloat_AsFloat</span>(__pyx_t_1); if (unlikely((__pyx_t_8 == (float)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 80, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " __pyx_r = __pyx_t_8;\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">081</span>: <span class=\"k\">else</span><span class=\"p\">:</span></pre>\n", + "<pre class=\"cython line score-8\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">082</span>: <span class=\"k\">if</span> <span class=\"n\">n1</span> <span class=\"o\">==</span> <span class=\"n\">n2</span><span class=\"p\">:</span></pre>\n", + "<pre class='cython code score-8 '> /*else*/ {\n", + " __pyx_t_1 = <span class='py_c_api'>PyObject_RichCompare</span>(__pyx_v_n1, __pyx_v_n2, Py_EQ); <span class='refnanny'>__Pyx_XGOTREF</span>(__pyx_t_1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error)</span>\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_PyObject_IsTrue</span>(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) <span class='error_goto'>__PYX_ERR(0, 82, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " if (__pyx_t_2) {\n", + "/* … */\n", + " }\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">083</span>: <span class=\"k\">return</span> <span class=\"mf\">0</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_r = 0.0;\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">084</span>: <span class=\"k\">return</span> <span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">node_del</span> <span class=\"o\">+</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">node_ins</span> <span class=\"o\">+</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">hed_edge</span><span class=\"p\">(</span><span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">g2</span><span class=\"p\">,</span> <span class=\"n\">n1</span><span class=\"p\">,</span> <span class=\"n\">n2</span><span class=\"p\">))</span> <span class=\"o\">/</span> <span class=\"mf\">2</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_r = (((__pyx_v_self->node_del + __pyx_v_self->node_ins) + ((struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self->__pyx_vtab)->hed_edge(__pyx_v_self, __pyx_v_g1, __pyx_v_g2, __pyx_v_n1, __pyx_v_n2)) / 2.0);\n", + " goto __pyx_L0;\n", + " }\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">085</span>: </pre>\n", + "<pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">086</span>: <span class=\"k\">cdef</span> <span class=\"kt\">float</span> <span class=\"nf\">hed_edge</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">g2</span><span class=\"p\">,</span> <span class=\"n\">n1</span><span class=\"p\">,</span> <span class=\"n\">n2</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-0 '>static float __pyx_f_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_hed_edge(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_v_self, PyObject *__pyx_v_g1, PyObject *__pyx_v_g2, PyObject *__pyx_v_n1, PyObject *__pyx_v_n2) {\n", + " float __pyx_r;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"hed_edge\", 0);\n", + "/* … */\n", + " /* function exit code */\n", + " __pyx_L0:;\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">087</span>: <span class=\"sd\">"""</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">088</span>: <span class=\"sd\"> Compute HEDistance between edges of n1 and n2, respectively in g1 and g2</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">089</span>: <span class=\"sd\"> :param g1: first graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">090</span>: <span class=\"sd\"> :param g2: second graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">091</span>: <span class=\"sd\"> :param n1: node of the first graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">092</span>: <span class=\"sd\"> :param n2: node of the second graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">093</span>: <span class=\"sd\"> :return:</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">094</span>: <span class=\"sd\"> """</span></pre>\n", + "<pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">095</span>: <span class=\"k\">return</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">sum_gpq</span><span class=\"p\">(</span><span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">n1</span><span class=\"p\">,</span> <span class=\"n\">g2</span><span class=\"p\">,</span> <span class=\"n\">n2</span><span class=\"p\">)</span> <span class=\"o\">+</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">sum_gpq</span><span class=\"p\">(</span><span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">n1</span><span class=\"p\">,</span> <span class=\"n\">g2</span><span class=\"p\">,</span> <span class=\"n\">n2</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_r = (((struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self->__pyx_vtab)->sum_gpq(__pyx_v_self, __pyx_v_g1, __pyx_v_n1, __pyx_v_g2, __pyx_v_n2) + ((struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self->__pyx_vtab)->sum_gpq(__pyx_v_self, __pyx_v_g1, __pyx_v_n1, __pyx_v_g2, __pyx_v_n2));\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">096</span>: </pre>\n", + "<pre class=\"cython line score-11\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">097</span>: <span class=\"k\">cdef</span> <span class=\"kt\">list</span> <span class=\"nf\">get_edge_multigraph</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">g</span><span class=\"p\">,</span> <span class=\"n\">node</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-11 '>static PyObject *__pyx_f_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_get_edge_multigraph(CYTHON_UNUSED struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_v_self, PyObject *__pyx_v_g, PyObject *__pyx_v_node) {\n", + " PyObject *__pyx_v_originals_ = 0;\n", + " int __pyx_v_n;\n", + " PyObject *__pyx_v_edges = 0;\n", + " int __pyx_v_i;\n", + " PyObject *__pyx_v_edge = NULL;\n", + " PyObject *__pyx_r = NULL;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"get_edge_multigraph\", 0);\n", + "/* … */\n", + " /* function exit code */\n", + " __pyx_L1_error:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_10);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_12);\n", + " <span class='pyx_c_api'>__Pyx_AddTraceback</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.get_edge_multigraph\", __pyx_clineno, __pyx_lineno, __pyx_filename);\n", + " __pyx_r = 0;\n", + " __pyx_L0:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_originals_);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_edges);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_edge);\n", + " <span class='refnanny'>__Pyx_XGIVEREF</span>(__pyx_r);\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">098</span>: <span class=\"sd\">"""</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">099</span>: <span class=\"sd\"> Get list of edge around a node in a Multigraph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">100</span>: <span class=\"sd\"> :param g: multigraph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">101</span>: <span class=\"sd\"> :param node: node in the multigraph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">102</span>: <span class=\"sd\"> :return:</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">103</span>: <span class=\"sd\"> """</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">104</span>: </pre>\n", + "<pre class=\"cython line score-31\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">105</span>: <span class=\"k\">cdef</span> <span class=\"kt\">list</span> <span class=\"nf\">originals_</span> <span class=\"o\">=</span> <span class=\"n\">g</span><span class=\"o\">.</span><span class=\"n\">edges</span><span class=\"p\">(</span><span class=\"n\">node</span><span class=\"p\">,</span> <span class=\"n\">data</span><span class=\"o\">=</span><span class=\"bp\">True</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-31 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_v_g, __pyx_n_s_edges);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " __pyx_t_2 = <span class='py_c_api'>PyTuple_New</span>(1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 105, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_node);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_v_node);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_2, 0, __pyx_v_node);\n", + " __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyDict_NewPresized</span>(1);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 105, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " if (<span class='py_c_api'>PyDict_SetItem</span>(__pyx_t_3, __pyx_n_s_data, Py_True) < 0) <span class='error_goto'>__PYX_ERR(0, 105, __pyx_L1_error)</span>\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_1, __pyx_t_2, __pyx_t_3);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 105, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " if (!(likely(<span class='py_c_api'>PyList_CheckExact</span>(__pyx_t_4))||((__pyx_t_4) == Py_None)||(<span class='py_c_api'>PyErr_Format</span>(PyExc_TypeError, \"Expected %.16s, got %.200s\", \"list\", Py_TYPE(__pyx_t_4)->tp_name), 0))) <span class='error_goto'>__PYX_ERR(0, 105, __pyx_L1_error)</span>\n", + " __pyx_v_originals_ = ((PyObject*)__pyx_t_4);\n", + " __pyx_t_4 = 0;\n", + "</pre><pre class=\"cython line score-6\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">106</span>: <span class=\"k\">cdef</span> <span class=\"kt\">int</span> <span class=\"nf\">n</span><span class=\"o\">=</span> <span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">originals_</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-6 '> if (unlikely(__pyx_v_originals_ == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"object of type 'NoneType' has no len()\");\n", + " <span class='error_goto'>__PYX_ERR(0, 106, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_5 = <span class='py_macro_api'>PyList_GET_SIZE</span>(__pyx_v_originals_);<span class='error_goto'> if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 106, __pyx_L1_error)</span>\n", + " __pyx_v_n = __pyx_t_5;\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">107</span>: <span class=\"k\">if</span> <span class=\"n\">n</span> <span class=\"o\">==</span> <span class=\"mf\">0</span><span class=\"p\">:</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_t_6 = ((__pyx_v_n == 0) != 0);\n", + " if (__pyx_t_6) {\n", + "/* … */\n", + " }\n", + "</pre><pre class=\"cython line score-6\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">108</span>: <span class=\"k\">return</span> <span class=\"p\">[]</span></pre>\n", + "<pre class='cython code score-6 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r);\n", + " __pyx_t_4 = <span class='py_c_api'>PyList_New</span>(0);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 108, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " __pyx_r = ((PyObject*)__pyx_t_4);\n", + " __pyx_t_4 = 0;\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">109</span>: </pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">110</span>: </pre>\n", + "<pre class=\"cython line score-7\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">111</span>: <span class=\"k\">cdef</span> <span class=\"kt\">list</span> <span class=\"nf\">edges</span> <span class=\"o\">=</span> <span class=\"p\">[</span><span class=\"s\">""</span><span class=\"p\">]</span><span class=\"o\">*</span><span class=\"n\">n</span></pre>\n", + "<pre class='cython code score-7 '> __pyx_t_4 = <span class='py_c_api'>PyList_New</span>(1 * ((__pyx_v_n<0) ? 0:__pyx_v_n));<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 111, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " { Py_ssize_t __pyx_temp;\n", + " for (__pyx_temp=0; __pyx_temp < __pyx_v_n; __pyx_temp++) {\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_kp_u_);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_kp_u_);\n", + " <span class='py_macro_api'>PyList_SET_ITEM</span>(__pyx_t_4, __pyx_temp, __pyx_kp_u_);\n", + " }\n", + " }\n", + " __pyx_v_edges = ((PyObject*)__pyx_t_4);\n", + " __pyx_t_4 = 0;\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">112</span>: <span class=\"k\">for</span> <span class=\"n\">i</span> <span class=\"ow\">in</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"n\">n</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_t_7 = __pyx_v_n;\n", + " __pyx_t_8 = __pyx_t_7;\n", + " for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {\n", + " __pyx_v_i = __pyx_t_9;\n", + "</pre><pre class=\"cython line score-8\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">113</span>: <span class=\"n\">edge</span><span class=\"o\">=</span><span class=\"n\">originals_</span><span class=\"p\">[</span><span class=\"n\">i</span><span class=\"p\">]</span></pre>\n", + "<pre class='cython code score-8 '> if (unlikely(__pyx_v_originals_ == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"'NoneType' object is not subscriptable\");\n", + " <span class='error_goto'>__PYX_ERR(0, 113, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_GetItemInt_List</span>(__pyx_v_originals_, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 113, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF_SET</span>(__pyx_v_edge, __pyx_t_4);\n", + " __pyx_t_4 = 0;\n", + "</pre><pre class=\"cython line score-48\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">114</span>: <span class=\"n\">edges</span><span class=\"p\">[</span><span class=\"n\">i</span><span class=\"p\">]</span><span class=\"o\">=</span><span class=\"p\">(</span><span class=\"s\">"{0}-{1}"</span><span class=\"o\">.</span><span class=\"n\">format</span><span class=\"p\">(</span><span class=\"n\">edge</span><span class=\"p\">[</span><span class=\"mf\">0</span><span class=\"p\">],</span><span class=\"n\">edge</span><span class=\"p\">[</span><span class=\"mf\">1</span><span class=\"p\">]))</span></pre>\n", + "<pre class='cython code score-48 '> __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_kp_u_0_1, __pyx_n_s_format);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 114, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_2 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_edge, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 114, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt</span>(__pyx_v_edge, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " __pyx_t_10 = NULL;\n", + " __pyx_t_11 = 0;\n", + " if (CYTHON_UNPACK_METHODS && likely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_3))) {\n", + " __pyx_t_10 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_3);\n", + " if (likely(__pyx_t_10)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_10);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_3, function);\n", + " __pyx_t_11 = 1;\n", + " }\n", + " }\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_2, __pyx_t_1};\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 114, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_10); __pyx_t_10 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_2, __pyx_t_1};\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 2+__pyx_t_11);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 114, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_10); __pyx_t_10 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_12 = <span class='py_c_api'>PyTuple_New</span>(2+__pyx_t_11);<span class='error_goto'> if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 114, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_12);\n", + " if (__pyx_t_10) {\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_10); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_12, 0, __pyx_t_10); __pyx_t_10 = NULL;\n", + " }\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_2);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_12, 0+__pyx_t_11, __pyx_t_2);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_12, 1+__pyx_t_11, __pyx_t_1);\n", + " __pyx_t_2 = 0;\n", + " __pyx_t_1 = 0;\n", + " __pyx_t_4 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_3, __pyx_t_12, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 114, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_4);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_12); __pyx_t_12 = 0;\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " if (unlikely(<span class='pyx_c_api'>__Pyx_SetItemInt</span>(__pyx_v_edges, __pyx_v_i, __pyx_t_4, int, 1, __Pyx_PyInt_From_int, 1, 1, 1) < 0)) <span class='error_goto'>__PYX_ERR(0, 114, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_4); __pyx_t_4 = 0;\n", + " }\n", + "</pre><pre class=\"cython line score-2\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">115</span>: <span class=\"k\">return</span> <span class=\"n\">edges</span></pre>\n", + "<pre class='cython code score-2 '> <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_r);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_v_edges);\n", + " __pyx_r = __pyx_v_edges;\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">116</span>: </pre>\n", + "<pre class=\"cython line score-11\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">117</span>: <span class=\"k\">cdef</span> <span class=\"kt\">float</span> <span class=\"nf\">sum_gpq</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">n1</span><span class=\"p\">,</span> <span class=\"n\">g2</span><span class=\"p\">,</span> <span class=\"n\">n2</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-11 '>static float __pyx_f_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_sum_gpq(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_v_self, PyObject *__pyx_v_g1, PyObject *__pyx_v_n1, PyObject *__pyx_v_g2, PyObject *__pyx_v_n2) {\n", + " PyObject *__pyx_v_edges1 = 0;\n", + " PyObject *__pyx_v_edges2 = 0;\n", + " PyArrayObject *__pyx_v_min_sum = 0;\n", + " PyArrayObject *__pyx_v_min_i = 0;\n", + " Py_ssize_t __pyx_v_i;\n", + " Py_ssize_t __pyx_v_j;\n", + " float __pyx_r;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"sum_gpq\", 0);\n", + "/* … */\n", + " /* function exit code */\n", + " __pyx_L1_error:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6);\n", + " <span class='pyx_c_api'>__Pyx_WriteUnraisable</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.sum_gpq\", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);\n", + " __pyx_r = 0;\n", + " __pyx_L0:;\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_edges1);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_v_edges2);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>((PyObject *)__pyx_v_min_sum);\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>((PyObject *)__pyx_v_min_i);\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">118</span>: <span class=\"sd\">"""</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">119</span>: <span class=\"sd\"> Compute Nearest Neighbour Distance between edges around n1 in G1 and edges around n2 in G2</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">120</span>: <span class=\"sd\"> :param g1: first graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">121</span>: <span class=\"sd\"> :param n1: node in the first graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">122</span>: <span class=\"sd\"> :param g2: second graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">123</span>: <span class=\"sd\"> :param n2: node in the second graph</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">124</span>: <span class=\"sd\"> :return:</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">125</span>: <span class=\"sd\"> """</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">126</span>: </pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">127</span>: <span class=\"c\">#if isinstance(g1, nx.MultiDiGraph):</span></pre>\n", + "<pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">128</span>: <span class=\"k\">cdef</span> <span class=\"kt\">list</span> <span class=\"nf\">edges1</span> <span class=\"o\">=</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">get_edge_multigraph</span><span class=\"p\">(</span><span class=\"n\">g1</span><span class=\"p\">,</span> <span class=\"n\">n1</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_t_1 = ((struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self->__pyx_vtab)->get_edge_multigraph(__pyx_v_self, __pyx_v_g1, __pyx_v_n1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 128, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " __pyx_v_edges1 = ((PyObject*)__pyx_t_1);\n", + " __pyx_t_1 = 0;\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">129</span>: <span class=\"k\">cdef</span> <span class=\"kt\">list</span> <span class=\"nf\">edges2</span> <span class=\"o\">=</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">get_edge_multigraph</span><span class=\"p\">(</span><span class=\"n\">g2</span><span class=\"p\">,</span> <span class=\"n\">n2</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_t_1 = ((struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self->__pyx_vtab)->get_edge_multigraph(__pyx_v_self, __pyx_v_g2, __pyx_v_n2);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " __pyx_v_edges2 = ((PyObject*)__pyx_t_1);\n", + " __pyx_t_1 = 0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">130</span>: </pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">131</span>: <span class=\"c\">#else:</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">132</span>: <span class=\"c\">#edges1 = [str(n1 + "-" + ef) for ef in list(g1.edge[n1].keys())]</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">133</span>: <span class=\"c\">#edges2 = [str(n2 + "-" + ef) for ef in list(g2.edge[n2].keys())]</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">134</span>: </pre>\n", + "<pre class=\"cython line score-57\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">135</span>: <span class=\"k\">cdef</span> <span class=\"kt\">np</span>.<span class=\"kt\">ndarray</span> <span class=\"nf\">min_sum</span> <span class=\"o\">=</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">zeros</span><span class=\"p\">(</span><span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">edges1</span><span class=\"p\">))</span></pre>\n", + "<pre class='cython code score-57 '> __pyx_t_2 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_np);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_2, __pyx_n_s_zeros);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " if (unlikely(__pyx_v_edges1 == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"object of type 'NoneType' has no len()\");\n", + " <span class='error_goto'>__PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_4 = <span class='py_macro_api'>PyList_GET_SIZE</span>(__pyx_v_edges1);<span class='error_goto'> if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " __pyx_t_2 = <span class='py_c_api'>PyInt_FromSsize_t</span>(__pyx_t_4);<span class='error_goto'> if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_2);\n", + " __pyx_t_5 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && unlikely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_3))) {\n", + " __pyx_t_5 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_3);\n", + " if (likely(__pyx_t_5)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_3, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_5) {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_3, __pyx_t_2);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_2};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_2};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_6 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_5); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_2);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0+1, __pyx_t_2);\n", + " __pyx_t_2 = 0;\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_3, __pyx_t_6, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " if (!(likely(((__pyx_t_1) == Py_None) || likely(<span class='pyx_c_api'>__Pyx_TypeTest</span>(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) <span class='error_goto'>__PYX_ERR(0, 135, __pyx_L1_error)</span>\n", + " __pyx_v_min_sum = ((PyArrayObject *)__pyx_t_1);\n", + " __pyx_t_1 = 0;\n", + "</pre><pre class=\"cython line score-7\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">136</span>: <span class=\"n\">edges2</span><span class=\"o\">.</span><span class=\"n\">extend</span><span class=\"p\">([</span><span class=\"bp\">None</span><span class=\"p\">])</span></pre>\n", + "<pre class='cython code score-7 '> if (unlikely(__pyx_v_edges2 == Py_None)) {\n", + " <span class='py_c_api'>PyErr_Format</span>(PyExc_AttributeError, \"'NoneType' object has no attribute '%.30s'\", \"extend\");\n", + " <span class='error_goto'>__PYX_ERR(0, 136, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_7 = <span class='pyx_c_api'>__Pyx_PyList_Append</span>(__pyx_v_edges2, Py_None);<span class='error_goto'> if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 136, __pyx_L1_error)</span>\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">137</span>: <span class=\"k\">cdef</span> <span class=\"kt\">np</span>.<span class=\"kt\">ndarray</span> <span class=\"nf\">min_i</span></pre>\n", + "<pre class=\"cython line score-6\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">138</span>: <span class=\"k\">for</span> <span class=\"n\">i</span> <span class=\"ow\">in</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">edges1</span><span class=\"p\">)):</span></pre>\n", + "<pre class='cython code score-6 '> if (unlikely(__pyx_v_edges1 == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"object of type 'NoneType' has no len()\");\n", + " <span class='error_goto'>__PYX_ERR(0, 138, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_4 = <span class='py_macro_api'>PyList_GET_SIZE</span>(__pyx_v_edges1);<span class='error_goto'> if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 138, __pyx_L1_error)</span>\n", + " __pyx_t_8 = __pyx_t_4;\n", + " for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {\n", + " __pyx_v_i = __pyx_t_9;\n", + "</pre><pre class=\"cython line score-58\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">139</span>: <span class=\"n\">min_i</span> <span class=\"o\">=</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">zeros</span><span class=\"p\">(</span><span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">edges2</span><span class=\"p\">))</span></pre>\n", + "<pre class='cython code score-58 '> __pyx_t_3 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_np);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_6 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_3, __pyx_n_s_zeros);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " if (unlikely(__pyx_v_edges2 == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"object of type 'NoneType' has no len()\");\n", + " <span class='error_goto'>__PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_10 = <span class='py_macro_api'>PyList_GET_SIZE</span>(__pyx_v_edges2);<span class='error_goto'> if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " __pyx_t_3 = <span class='py_c_api'>PyInt_FromSsize_t</span>(__pyx_t_10);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " __pyx_t_2 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && unlikely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_6))) {\n", + " __pyx_t_2 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_6);\n", + " if (likely(__pyx_t_2)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_6);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_2);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_6, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_2) {\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_6, __pyx_t_3);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_6)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_3};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_6, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_6)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_t_3};\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_6, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_2); __pyx_t_2 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_5 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_2); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_3);\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_5, 0+1, __pyx_t_3);\n", + " __pyx_t_3 = 0;\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_6, __pyx_t_5, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " if (!(likely(((__pyx_t_1) == Py_None) || likely(<span class='pyx_c_api'>__Pyx_TypeTest</span>(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) <span class='error_goto'>__PYX_ERR(0, 139, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF_SET</span>(__pyx_v_min_i, ((PyArrayObject *)__pyx_t_1));\n", + " __pyx_t_1 = 0;\n", + "</pre><pre class=\"cython line score-6\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">140</span>: <span class=\"k\">for</span> <span class=\"n\">j</span> <span class=\"ow\">in</span> <span class=\"nb\">range</span><span class=\"p\">(</span><span class=\"nb\">len</span><span class=\"p\">(</span><span class=\"n\">edges2</span><span class=\"p\">)):</span></pre>\n", + "<pre class='cython code score-6 '> if (unlikely(__pyx_v_edges2 == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"object of type 'NoneType' has no len()\");\n", + " <span class='error_goto'>__PYX_ERR(0, 140, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_10 = <span class='py_macro_api'>PyList_GET_SIZE</span>(__pyx_v_edges2);<span class='error_goto'> if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(0, 140, __pyx_L1_error)</span>\n", + " __pyx_t_11 = __pyx_t_10;\n", + " for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {\n", + " __pyx_v_j = __pyx_t_12;\n", + "</pre><pre class=\"cython line score-44\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">141</span>: <span class=\"n\">min_i</span><span class=\"p\">[</span><span class=\"n\">j</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">gpq</span><span class=\"p\">(</span><span class=\"n\">edges1</span><span class=\"p\">[</span><span class=\"n\">i</span><span class=\"p\">],</span> <span class=\"n\">edges2</span><span class=\"p\">[</span><span class=\"n\">j</span><span class=\"p\">])</span></pre>\n", + "<pre class='cython code score-44 '> if (unlikely(__pyx_v_edges1 == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"'NoneType' object is not subscriptable\");\n", + " <span class='error_goto'>__PYX_ERR(0, 141, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetItemInt_List</span>(__pyx_v_edges1, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " if (!(likely(<span class='py_c_api'>PyUnicode_CheckExact</span>(__pyx_t_1))||((__pyx_t_1) == Py_None)||(<span class='py_c_api'>PyErr_Format</span>(PyExc_TypeError, \"Expected %.16s, got %.200s\", \"unicode\", Py_TYPE(__pyx_t_1)->tp_name), 0))) <span class='error_goto'>__PYX_ERR(0, 141, __pyx_L1_error)</span>\n", + " if (unlikely(__pyx_v_edges2 == Py_None)) {\n", + " <span class='py_c_api'>PyErr_SetString</span>(PyExc_TypeError, \"'NoneType' object is not subscriptable\");\n", + " <span class='error_goto'>__PYX_ERR(0, 141, __pyx_L1_error)</span>\n", + " }\n", + " __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetItemInt_List</span>(__pyx_v_edges2, __pyx_v_j, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 141, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " if (!(likely(<span class='py_c_api'>PyUnicode_CheckExact</span>(__pyx_t_6))||((__pyx_t_6) == Py_None)||(<span class='py_c_api'>PyErr_Format</span>(PyExc_TypeError, \"Expected %.16s, got %.200s\", \"unicode\", Py_TYPE(__pyx_t_6)->tp_name), 0))) <span class='error_goto'>__PYX_ERR(0, 141, __pyx_L1_error)</span>\n", + " __pyx_t_5 = <span class='py_c_api'>PyFloat_FromDouble</span>(((struct __pyx_vtabstruct_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *)__pyx_v_self->__pyx_vtab)->gpq(__pyx_v_self, ((PyObject*)__pyx_t_1), ((PyObject*)__pyx_t_6)));<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 141, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " if (unlikely(<span class='pyx_c_api'>__Pyx_SetItemInt</span>(((PyObject *)__pyx_v_min_i), __pyx_v_j, __pyx_t_5, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1) < 0)) <span class='error_goto'>__PYX_ERR(0, 141, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " }\n", + "</pre><pre class=\"cython line score-45\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">142</span>: <span class=\"n\">min_sum</span><span class=\"p\">[</span><span class=\"n\">i</span><span class=\"p\">]</span> <span class=\"o\">=</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">min</span><span class=\"p\">(</span><span class=\"n\">min_i</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-45 '> __pyx_t_6 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_np);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 142, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " __pyx_t_1 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_6, __pyx_n_s_min);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 142, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " __pyx_t_6 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && unlikely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_1))) {\n", + " __pyx_t_6 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_1);\n", + " if (likely(__pyx_t_6)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_6);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_1, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_6) {\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_1, ((PyObject *)__pyx_v_min_i));<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 142, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_1)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_6, ((PyObject *)__pyx_v_min_i)};\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_1, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 142, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_1)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_6, ((PyObject *)__pyx_v_min_i)};\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_1, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 142, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_3 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 142, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_6); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_3, 0, __pyx_t_6); __pyx_t_6 = NULL;\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(((PyObject *)__pyx_v_min_i));\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(((PyObject *)__pyx_v_min_i));\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_3, 0+1, ((PyObject *)__pyx_v_min_i));\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_1, __pyx_t_3, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 142, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " if (unlikely(<span class='pyx_c_api'>__Pyx_SetItemInt</span>(((PyObject *)__pyx_v_min_sum), __pyx_v_i, __pyx_t_5, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1) < 0)) <span class='error_goto'>__PYX_ERR(0, 142, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " }\n", + "</pre><pre class=\"cython line score-53\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">143</span>: <span class=\"k\">return</span> <span class=\"n\">np</span><span class=\"o\">.</span><span class=\"n\">sum</span><span class=\"p\">(</span><span class=\"n\">min_sum</span><span class=\"p\">)</span></pre>\n", + "<pre class='cython code score-53 '> __pyx_t_1 = <span class='pyx_c_api'>__Pyx_GetModuleGlobalName</span>(__pyx_n_s_np);<span class='error_goto'> if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_1);\n", + " __pyx_t_3 = <span class='pyx_c_api'>__Pyx_PyObject_GetAttrStr</span>(__pyx_t_1, __pyx_n_s_sum);<span class='error_goto'> if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 143, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " __pyx_t_1 = NULL;\n", + " if (CYTHON_UNPACK_METHODS && unlikely(<span class='py_c_api'>PyMethod_Check</span>(__pyx_t_3))) {\n", + " __pyx_t_1 = <span class='py_macro_api'>PyMethod_GET_SELF</span>(__pyx_t_3);\n", + " if (likely(__pyx_t_1)) {\n", + " PyObject* function = <span class='py_macro_api'>PyMethod_GET_FUNCTION</span>(__pyx_t_3);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(__pyx_t_1);\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(function);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF_SET</span>(__pyx_t_3, function);\n", + " }\n", + " }\n", + " if (!__pyx_t_1) {\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_CallOneArg</span>(__pyx_t_3, ((PyObject *)__pyx_v_min_sum));<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 143, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " } else {\n", + " #if CYTHON_FAST_PYCALL\n", + " if (<span class='py_c_api'>PyFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_1, ((PyObject *)__pyx_v_min_sum)};\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 143, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " } else\n", + " #endif\n", + " #if CYTHON_FAST_PYCCALL\n", + " if (<span class='pyx_c_api'>__Pyx_PyFastCFunction_Check</span>(__pyx_t_3)) {\n", + " PyObject *__pyx_temp[2] = {__pyx_t_1, ((PyObject *)__pyx_v_min_sum)};\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyCFunction_FastCall</span>(__pyx_t_3, __pyx_temp+1-1, 1+1);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 143, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_XDECREF</span>(__pyx_t_1); __pyx_t_1 = 0;\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " } else\n", + " #endif\n", + " {\n", + " __pyx_t_6 = <span class='py_c_api'>PyTuple_New</span>(1+1);<span class='error_goto'> if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 143, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_6);\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(__pyx_t_1); <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;\n", + " <span class='pyx_macro_api'>__Pyx_INCREF</span>(((PyObject *)__pyx_v_min_sum));\n", + " <span class='refnanny'>__Pyx_GIVEREF</span>(((PyObject *)__pyx_v_min_sum));\n", + " <span class='py_macro_api'>PyTuple_SET_ITEM</span>(__pyx_t_6, 0+1, ((PyObject *)__pyx_v_min_sum));\n", + " __pyx_t_5 = <span class='pyx_c_api'>__Pyx_PyObject_Call</span>(__pyx_t_3, __pyx_t_6, NULL);<span class='error_goto'> if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 143, __pyx_L1_error)</span>\n", + " <span class='refnanny'>__Pyx_GOTREF</span>(__pyx_t_5);\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_6); __pyx_t_6 = 0;\n", + " }\n", + " }\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_3); __pyx_t_3 = 0;\n", + " __pyx_t_13 = __pyx_<span class='py_c_api'>PyFloat_AsFloat</span>(__pyx_t_5); if (unlikely((__pyx_t_13 == (float)-1) && <span class='py_c_api'>PyErr_Occurred</span>())) <span class='error_goto'>__PYX_ERR(0, 143, __pyx_L1_error)</span>\n", + " <span class='pyx_macro_api'>__Pyx_DECREF</span>(__pyx_t_5); __pyx_t_5 = 0;\n", + " __pyx_r = __pyx_t_13;\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">144</span>: </pre>\n", + "<pre class=\"cython line score-2\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">145</span>: <span class=\"k\">cdef</span> <span class=\"kt\">float</span> <span class=\"nf\">gpq</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"nb\">str</span> <span class=\"n\">e1</span><span class=\"p\">,</span> <span class=\"nb\">str</span> <span class=\"n\">e2</span><span class=\"p\">):</span></pre>\n", + "<pre class='cython code score-2 '>static float __pyx_f_46_cython_magic_dda4cdebdc96d9140091621511971356_3HED_gpq(struct __pyx_obj_46_cython_magic_dda4cdebdc96d9140091621511971356_HED *__pyx_v_self, PyObject *__pyx_v_e1, PyObject *__pyx_v_e2) {\n", + " float __pyx_r;\n", + " <span class='refnanny'>__Pyx_RefNannyDeclarations</span>\n", + " <span class='refnanny'>__Pyx_RefNannySetupContext</span>(\"gpq\", 0);\n", + "/* … */\n", + " /* function exit code */\n", + " __pyx_L1_error:;\n", + " <span class='pyx_c_api'>__Pyx_WriteUnraisable</span>(\"_cython_magic_dda4cdebdc96d9140091621511971356.HED.gpq\", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);\n", + " __pyx_r = 0;\n", + " __pyx_L0:;\n", + " <span class='refnanny'>__Pyx_RefNannyFinishContext</span>();\n", + " return __pyx_r;\n", + "}\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">146</span>: <span class=\"sd\">"""</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">147</span>: <span class=\"sd\"> Compute the edge distance function</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">148</span>: <span class=\"sd\"> :param e1: edge1</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">149</span>: <span class=\"sd\"> :param e2: edge2</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">150</span>: <span class=\"sd\"> :return:</span></pre>\n", + "<pre class=\"cython line score-0\"> <span class=\"\">151</span>: <span class=\"sd\"> """</span></pre>\n", + "<pre class=\"cython line score-2\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">152</span>: <span class=\"k\">if</span> <span class=\"n\">e2</span> <span class=\"o\">==</span> <span class=\"bp\">None</span><span class=\"p\">:</span> <span class=\"c\"># Del</span></pre>\n", + "<pre class='cython code score-2 '> __pyx_t_1 = (<span class='pyx_c_api'>__Pyx_PyUnicode_Equals</span>(__pyx_v_e2, Py_None, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) <span class='error_goto'>__PYX_ERR(0, 152, __pyx_L1_error)</span>\n", + " if (__pyx_t_1) {\n", + "/* … */\n", + " }\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">153</span>: <span class=\"k\">return</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">edge_del</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_r = __pyx_v_self->edge_del;\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-2\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">154</span>: <span class=\"k\">if</span> <span class=\"n\">e1</span> <span class=\"o\">==</span> <span class=\"bp\">None</span><span class=\"p\">:</span> <span class=\"c\"># Insert</span></pre>\n", + "<pre class='cython code score-2 '> __pyx_t_1 = (<span class='pyx_c_api'>__Pyx_PyUnicode_Equals</span>(__pyx_v_e1, Py_None, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) <span class='error_goto'>__PYX_ERR(0, 154, __pyx_L1_error)</span>\n", + " if (__pyx_t_1) {\n", + "/* … */\n", + " }\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">155</span>: <span class=\"k\">return</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">edge_ins</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_r = __pyx_v_self->edge_ins;\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\"> <span class=\"\">156</span>: <span class=\"k\">else</span><span class=\"p\">:</span></pre>\n", + "<pre class=\"cython line score-2\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">157</span>: <span class=\"k\">if</span> <span class=\"n\">e1</span> <span class=\"o\">==</span> <span class=\"n\">e2</span><span class=\"p\">:</span></pre>\n", + "<pre class='cython code score-2 '> /*else*/ {\n", + " __pyx_t_1 = (<span class='pyx_c_api'>__Pyx_PyUnicode_Equals</span>(__pyx_v_e1, __pyx_v_e2, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) <span class='error_goto'>__PYX_ERR(0, 157, __pyx_L1_error)</span>\n", + " __pyx_t_2 = (__pyx_t_1 != 0);\n", + " if (__pyx_t_2) {\n", + "/* … */\n", + " }\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">158</span>: <span class=\"k\">return</span> <span class=\"mf\">0</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_r = 0.0;\n", + " goto __pyx_L0;\n", + "</pre><pre class=\"cython line score-0\" onclick=\"(function(s){s.display=s.display==='block'?'none':'block'})(this.nextElementSibling.style)\">+<span class=\"\">159</span>: <span class=\"k\">return</span> <span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">edge_del</span> <span class=\"o\">+</span> <span class=\"bp\">self</span><span class=\"o\">.</span><span class=\"n\">edge_ins</span><span class=\"p\">)</span> <span class=\"o\">/</span> <span class=\"mf\">2</span></pre>\n", + "<pre class='cython code score-0 '> __pyx_r = (((double)(__pyx_v_self->edge_del + __pyx_v_self->edge_ins)) / 2.0);\n", + " goto __pyx_L0;\n", + " }\n", + "</pre></div></body></html>" + ], "text/plain": [ - "2.43290200817664e+18" + "<IPython.core.display.HTML object>" ] }, - "execution_count": 12, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "%timeit cyfac_double_fast(20.0)\n", - "cyfac_double_fast(20.0)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-20T07:03:37.332486Z", - "start_time": "2018-04-20T07:03:37.328492Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/Users/jacquesfize/nas_cloud/Code/str-python\n" - ] - } - ], - "source": [ - "cd .." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-20T07:03:37.421880Z", - "start_time": "2018-04-20T07:03:37.334723Z" - } - }, - "outputs": [], - "source": [ - "import numpy as np\n", - "class PureHED():\n", - " \"\"\"\n", - " Implementation of Hausdorff Edit Distance described in\n", - "\n", - " Improved quadratic time approximation of graph edit distance by Hausdorff matching and greedy assignement\n", - " Andreas Fischer, Kaspar Riesen, Horst Bunke\n", - " 2016\n", - " \"\"\"\n", - " __type__ = \"dist\"\n", - " @staticmethod\n", - " def compare(listgs, c_del_node=1, c_del_edge=1, c_ins_node=1, c_ins_edge=1):\n", - " n = len(listgs)\n", - " comparator = PureHED(c_del_node, c_ins_node, c_del_edge, c_ins_edge)\n", - " comparison_matrix = np.zeros((n, n))\n", - " for i in range(n):\n", - " for j in range(i, n):\n", - " comparison_matrix[i, j] = comparator.hed(listgs[i], listgs[j])\n", - " comparison_matrix[j, i] = comparison_matrix[i, j]\n", - "\n", - " return comparison_matrix\n", - "\n", - "\n", - " def __init__(self, node_del=1, node_ins=1, edge_del=1, edge_ins=1):\n", - " \"\"\"Constructor for HED\"\"\"\n", - " self.node_del = node_del\n", - " self.node_ins = node_ins\n", - " self.edge_del = edge_del\n", - " self.edge_ins = edge_ins\n", - "\n", - " def hed(self, g1, g2):\n", - " \"\"\"\n", - " Compute de Hausdorff Edit Distance\n", - " :param g1: first graph\n", - " :param g2: second graph\n", - " :return:\n", - " \"\"\"\n", - " return self.sum_fuv(g1, g2) + self.sum_fuv(g2, g1)\n", - "\n", - " def sum_fuv(self, g1, g2):\n", - " \"\"\"\n", - " Compute Nearest Neighbour Distance between G1 and G2\n", - " :param g1: First Graph\n", - " :param g2: Second Graph\n", - " :return:\n", - " \"\"\"\n", - " min_sum = np.zeros(len(g1))\n", - " nodes1 = g1.nodes()\n", - " nodes2 = g2.nodes()\n", - " nodes2.extend([None])\n", - " for i in range(len(nodes1)):\n", - " min_i = np.zeros(len(nodes2))\n", - " for j in range(len(nodes2)):\n", - " min_i[j] = self.fuv(g1, g2, nodes1[i], nodes2[j])\n", - " min_sum[i] = np.min(min_i)\n", - " return np.sum(min_sum)\n", - "\n", - " def fuv(self, g1, g2, n1, n2):\n", - " \"\"\"\n", - " Compute the Node Distance function\n", - " :param g1: first graph\n", - " :param g2: second graph\n", - " :param n1: node of the first graph\n", - " :param n2: node of the second graph\n", - " :return:\n", - " \"\"\"\n", - " if n2 == None: # Del\n", - " return self.node_del + ((self.edge_del / 2) * g1.degree(n1))\n", - " if n1 == None: # Insert\n", - " return self.node_ins + ((self.edge_ins / 2) * g2.degree(n2))\n", - " else:\n", - " if n1 == n2:\n", - " return 0.\n", - " return (self.node_del + self.node_ins + self.hed_edge(g1, g2, n1, n2)) / 2\n", - "\n", - " def hed_edge(self, g1, g2, n1, n2):\n", - " \"\"\"\n", - " Compute HEDistance between edges of n1 and n2, respectively in g1 and g2\n", - " :param g1: first graph\n", - " :param g2: second graph\n", - " :param n1: node of the first graph\n", - " :param n2: node of the second graph\n", - " :return:\n", - " \"\"\"\n", - " return self.sum_gpq(g1, n1, g2, n2) + self.sum_gpq(g1, n1, g2, n2)\n", - "\n", - " def get_edge_multigraph(self, g, node):\n", - " \"\"\"\n", - " Get list of edge around a node in a Multigraph\n", - " :param g: multigraph\n", - " :param node: node in the multigraph\n", - " :return:\n", - " \"\"\"\n", - " edges = []\n", - " for edge in g.edges(data=True):\n", - " if node == edge[0] or node == edge[1]:\n", - " edges.append(\"{0}-{1}\".format(edge[0],edge[1]))\n", - " return edges\n", - "\n", - " def sum_gpq(self, g1, n1, g2, n2):\n", - " \"\"\"\n", - " Compute Nearest Neighbour Distance between edges around n1 in G1 and edges around n2 in G2\n", - " :param g1: first graph\n", - " :param n1: node in the first graph\n", - " :param g2: second graph\n", - " :param n2: node in the second graph\n", - " :return:\n", - " \"\"\"\n", - "\n", - " #if isinstance(g1, nx.MultiDiGraph):\n", - " edges1 = self.get_edge_multigraph(g1, n1)\n", - " edges2 = self.get_edge_multigraph(g2, n2)\n", - "\n", - " #else:\n", - " #edges1 = [str(n1 + \"-\" + ef) for ef in list(g1.edge[n1].keys())]\n", - " #edges2 = [str(n2 + \"-\" + ef) for ef in list(g2.edge[n2].keys())]\n", - "\n", - " min_sum = np.zeros(len(edges1))\n", - " edges2.extend([None])\n", - " for i in range(len(edges1)):\n", - " min_i = np.zeros(len(edges2))\n", - " for j in range(len(edges2)):\n", - " min_i[j] = self.gpq(edges1[i], edges2[j])\n", - " min_sum[i] = np.min(min_i)\n", - " return np.sum(min_sum)\n", - "\n", - " def gpq(self, e1, e2):\n", - " \"\"\"\n", - " Compute the edge distance function\n", - " :param e1: edge1\n", - " :param e2: edge2\n", - " :return:\n", - " \"\"\"\n", - " if e2 == None: # Del\n", - " return self.edge_del\n", - " if e1 == None: # Insert\n", - " return self.edge_ins\n", - " else:\n", - " if e1 == e2:\n", - " return 0\n", - " return (self.edge_del + self.edge_ins) / 2\n" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-20T07:03:37.430098Z", - "start_time": "2018-04-20T07:03:37.424291Z" - } - }, - "outputs": [], - "source": [ - "%%cython \n", + "%%cython --annotate --cplus\n", "import numpy as np\n", "cimport numpy as np\n", + "#from libcpp.list cimport list as cpplist\n", "cdef class HED:\n", " \"\"\"\n", " Implementation of Hausdorff Edit Distance described in\n", @@ -1001,7 +2680,7 @@ " \"\"\"\n", " return self.sum_fuv(g1, g2) + self.sum_fuv(g2, g1)\n", "\n", - " cpdef float sum_fuv(self, g1, g2):\n", + " cdef float sum_fuv(self, g1, g2):\n", " \"\"\"\n", " Compute Nearest Neighbour Distance between G1 and G2\n", " :param g1: First Graph\n", @@ -1020,7 +2699,7 @@ " min_sum[i] = np.min(min_i)\n", " return np.sum(min_sum)\n", "\n", - " cpdef float fuv(self, g1, g2, n1, n2):\n", + " cdef float fuv(self, g1, g2, n1, n2):\n", " \"\"\"\n", " Compute the Node Distance function\n", " :param g1: first graph\n", @@ -1038,7 +2717,7 @@ " return 0\n", " return (self.node_del + self.node_ins + self.hed_edge(g1, g2, n1, n2)) / 2\n", "\n", - " cpdef float hed_edge(self, g1, g2, n1, n2):\n", + " cdef float hed_edge(self, g1, g2, n1, n2):\n", " \"\"\"\n", " Compute HEDistance between edges of n1 and n2, respectively in g1 and g2\n", " :param g1: first graph\n", @@ -1049,20 +2728,27 @@ " \"\"\"\n", " return self.sum_gpq(g1, n1, g2, n2) + self.sum_gpq(g1, n1, g2, n2)\n", "\n", - " cpdef list get_edge_multigraph(self, g, node):\n", + " cdef list get_edge_multigraph(self, g, node):\n", " \"\"\"\n", " Get list of edge around a node in a Multigraph\n", " :param g: multigraph\n", " :param node: node in the multigraph\n", " :return:\n", " \"\"\"\n", - " cdef list edges = []\n", - " for edge in g.edges(data=True):\n", - " if node == edge[0] or node == edge[1]:\n", - " edges.append(\"{0}-{1}\".format(edge[0],edge[1]))\n", + " \n", + " cdef list originals_ = g.edges(node, data=True)\n", + " cdef int n= len(originals_)\n", + " if n == 0:\n", + " return []\n", + " \n", + " \n", + " cdef list edges = [\"\"]*n\n", + " for i in range(n):\n", + " edge=originals_[i]\n", + " edges[i]=(\"{0}-{1}\".format(edge[0],edge[1]))\n", " return edges\n", "\n", - " cpdef float sum_gpq(self, g1, n1, g2, n2):\n", + " cdef float sum_gpq(self, g1, n1, g2, n2):\n", " \"\"\"\n", " Compute Nearest Neighbour Distance between edges around n1 in G1 and edges around n2 in G2\n", " :param g1: first graph\n", @@ -1090,7 +2776,7 @@ " min_sum[i] = np.min(min_i)\n", " return np.sum(min_sum)\n", "\n", - " cpdef float gpq(self, str e1, str e2):\n", + " cdef float gpq(self, str e1, str e2):\n", " \"\"\"\n", " Compute the edge distance function\n", " :param e1: edge1\n", @@ -1109,11 +2795,11 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": { "ExecuteTime": { - "end_time": "2018-04-20T07:03:37.434790Z", - "start_time": "2018-04-20T07:03:37.432514Z" + "end_time": "2018-05-22T11:38:55.525187Z", + "start_time": "2018-05-22T11:38:55.522495Z" } }, "outputs": [], @@ -1123,11 +2809,11 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 5, "metadata": { "ExecuteTime": { - "end_time": "2018-04-20T07:03:37.736648Z", - "start_time": "2018-04-20T07:03:37.437089Z" + "end_time": "2018-05-22T11:40:27.535455Z", + "start_time": "2018-05-22T11:40:27.319835Z" } }, "outputs": [], @@ -1137,11 +2823,11 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 9, "metadata": { "ExecuteTime": { - "end_time": "2018-04-20T07:03:37.750336Z", - "start_time": "2018-04-20T07:03:37.738699Z" + "end_time": "2018-05-22T11:44:30.940189Z", + "start_time": "2018-05-22T11:44:30.930315Z" } }, "outputs": [], @@ -1152,11 +2838,39 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2018-05-22T11:38:58.738614Z", + "start_time": "2018-05-22T11:38:58.729483Z" + } + }, + "outputs": [], + "source": [ + "g2.edges()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "ExecuteTime": { + "end_time": "2018-05-22T11:38:58.894169Z", + "start_time": "2018-05-22T11:38:58.890234Z" + } + }, + "outputs": [], + "source": [ + "g2.edges(\"GD1874760\",data=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, "metadata": { "ExecuteTime": { - "end_time": "2018-04-20T07:03:37.763916Z", - "start_time": "2018-04-20T07:03:37.753086Z" + "end_time": "2018-05-22T11:40:30.176015Z", + "start_time": "2018-05-22T11:40:30.166741Z" } }, "outputs": [], @@ -1167,11 +2881,11 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 10, "metadata": { "ExecuteTime": { - "end_time": "2018-04-20T07:04:01.654836Z", - "start_time": "2018-04-20T07:03:37.766300Z" + "end_time": "2018-05-22T11:45:12.039535Z", + "start_time": "2018-05-22T11:44:33.072785Z" } }, "outputs": [ @@ -1179,18 +2893,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 23.8 s, sys: 191 ms, total: 24 s\n", - "Wall time: 23.9 s\n" + "CPU times: user 38.9 s, sys: 133 ms, total: 39 s\n", + "Wall time: 39 s\n" ] }, { "data": { "text/plain": [ - "array([[0., 0.],\n", - " [0., 0.]])" + "array([[ 0. , 387.5],\n", + " [387.5, 0. ]])" ] }, - "execution_count": 20, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -1201,11 +2915,11 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 11, "metadata": { "ExecuteTime": { - "end_time": "2018-04-20T07:04:14.050637Z", - "start_time": "2018-04-20T07:04:01.657104Z" + "end_time": "2018-05-22T11:45:15.452038Z", + "start_time": "2018-05-22T11:45:12.080332Z" } }, "outputs": [ @@ -1213,18 +2927,18 @@ "name": "stdout", "output_type": "stream", "text": [ - "CPU times: user 12.4 s, sys: 41.7 ms, total: 12.4 s\n", - "Wall time: 12.4 s\n" + "CPU times: user 3.35 s, sys: 57.5 ms, total: 3.41 s\n", + "Wall time: 3.37 s\n" ] }, { "data": { "text/plain": [ - "array([[0., 0.],\n", - " [0., 0.]])" + "array([[ 0., 315.],\n", + " [315., 0.]])" ] }, - "execution_count": 21, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } diff --git a/notebooks/Eval_mada_light_30_mars.ipynb b/notebooks/Eval_mada_light_30_mars.ipynb index 1e75630..2362e7f 100644 --- a/notebooks/Eval_mada_light_30_mars.ipynb +++ b/notebooks/Eval_mada_light_30_mars.ipynb @@ -17,22 +17,6 @@ "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.3.0) doesn't match a supported version!\n", " RequestsDependencyWarning)\n" ] - }, - { - "data": { - "text/html": [ - "<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>" - ] - }, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/Users/jacquesfize/nas_cloud/Code/str-python\n" - ] } ], "source": [ @@ -64,6496 +48,6 @@ " return intersection_cardinality/float(union_cardinality)\n", "%cd .." ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:03.630062Z", - "start_time": "2018-04-06T12:39:03.579773Z" - } - }, - "outputs": [], - "source": [ - "df=pd.read_csv(\"data/graph_exp_mar_30/first_result.tsv\",delimiter=\"\\t\",index_col=0)\n", - "new_df=pd.DataFrame(columns=df.columns)\n", - "\n", - "types=df.type.unique()\n", - "graph_size={}\n", - "graphs_={}\n", - "\n", - "files_glob= glob.glob(\"data/graph_exp_mar_30/normal/*.gexf\")\n", - "for fn in files_glob:\n", - " id_ = int(re.findall(\"\\d+\", fn)[-1])\n", - " graphs_[id_]=nx.read_gexf(fn)\n", - " graph_size[id_]=len(graphs_[id_])\n", - "nb_of_g_w_es_com={}\n", - "for g in graphs_:\n", - " if not g in nb_of_g_w_es_com:\n", - " nb_of_g_w_es_com[g]=0\n", - " for g2 in graphs_:\n", - " if not g2 == g:\n", - " if set(graphs_[g].nodes()).intersection(set(graphs_[g2].nodes())):\n", - " nb_of_g_w_es_com[g]+=1 \n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:03.655426Z", - "start_time": "2018-04-06T12:39:03.632192Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>id_g1</th>\n", - " <th>id_g2</th>\n", - " <th>mesure</th>\n", - " <th>type</th>\n", - " <th>id_user</th>\n", - " <th>c1_val</th>\n", - " <th>c2_val</th>\n", - " <th>c3_val</th>\n", - " <th>c4_val</th>\n", - " </tr>\n", - " <tr>\n", - " <th>id</th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>5</td>\n", - " <td>27</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>1</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>5</td>\n", - " <td>7</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>5</td>\n", - " <td>24</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>5</td>\n", - " <td>4</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>5</th>\n", - " <td>5</td>\n", - " <td>21</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>6</th>\n", - " <td>6</td>\n", - " <td>14</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>7</th>\n", - " <td>6</td>\n", - " <td>4</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>8</th>\n", - " <td>6</td>\n", - " <td>2</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>9</th>\n", - " <td>6</td>\n", - " <td>28</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>10</th>\n", - " <td>6</td>\n", - " <td>7</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>11</th>\n", - " <td>7</td>\n", - " <td>22</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " </tr>\n", - " <tr>\n", - " <th>12</th>\n", - " <td>7</td>\n", - " <td>28</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>13</th>\n", - " <td>7</td>\n", - " <td>4</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " </tr>\n", - " <tr>\n", - " <th>14</th>\n", - " <td>7</td>\n", - " <td>25</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>15</th>\n", - " <td>7</td>\n", - " <td>21</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " </tr>\n", - " <tr>\n", - " <th>16</th>\n", - " <td>9</td>\n", - " <td>12</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>17</th>\n", - " <td>9</td>\n", - " <td>30</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>18</th>\n", - " <td>9</td>\n", - " <td>14</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>19</th>\n", - " <td>9</td>\n", - " <td>7</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " <tr>\n", - " <th>20</th>\n", - " <td>9</td>\n", - " <td>21</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "</div>" - ], - "text/plain": [ - " id_g1 id_g2 mesure type id_user c1_val c2_val c3_val c4_val\n", - "id \n", - "1 5 27 1 normal 3 1 1 0 1\n", - "2 5 7 1 normal 3 1 1 1 0\n", - "3 5 24 1 normal 3 1 1 1 0\n", - "4 5 4 1 normal 3 1 1 1 0\n", - "5 5 21 1 normal 3 1 1 1 0\n", - "6 6 14 1 normal 3 1 1 1 0\n", - "7 6 4 1 normal 3 1 1 1 0\n", - "8 6 2 1 normal 3 1 1 0 0\n", - "9 6 28 1 normal 3 1 1 1 0\n", - "10 6 7 1 normal 3 1 1 1 0\n", - "11 7 22 1 normal 3 1 1 1 1\n", - "12 7 28 1 normal 3 1 1 1 0\n", - "13 7 4 1 normal 3 1 1 1 1\n", - "14 7 25 1 normal 3 1 1 1 0\n", - "15 7 21 1 normal 3 1 1 1 1\n", - "16 9 12 1 normal 3 1 1 1 0\n", - "17 9 30 1 normal 3 1 1 0 0\n", - "18 9 14 1 normal 3 1 1 0 0\n", - "19 9 7 1 normal 3 1 1 1 0\n", - "20 9 21 1 normal 3 1 1 1 0" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.head(20)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:03.667434Z", - "start_time": "2018-04-06T12:39:03.658006Z" - } - }, - "outputs": [], - "source": [ - "df_mesure=pd.read_csv(\"resources/mesures.tsv\",delimiter=\"\\t\")\n", - "\n", - "type2int={}\n", - "int2type={}\n", - "i=0\n", - "for t in df.type.unique():\n", - " type2int[t]=i\n", - " int2type[i]=t\n", - " i+=1" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:05.434699Z", - "start_time": "2018-04-06T12:39:03.669949Z" - } - }, - "outputs": [], - "source": [ - "df[\"mesureL\"]=df[\"mesure\"].apply(lambda x:df_mesure[df_mesure.id==x].values[0][-1])" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:05.469186Z", - "start_time": "2018-04-06T12:39:05.436220Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>id_g1</th>\n", - " <th>id_g2</th>\n", - " <th>mesure</th>\n", - " <th>type</th>\n", - " <th>id_user</th>\n", - " <th>c1_val</th>\n", - " <th>c2_val</th>\n", - " <th>c3_val</th>\n", - " <th>c4_val</th>\n", - " <th>mesureL</th>\n", - " </tr>\n", - " <tr>\n", - " <th>id</th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " <th></th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>5</td>\n", - " <td>27</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>1</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>5</td>\n", - " <td>7</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>5</td>\n", - " <td>24</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>5</td>\n", - " <td>4</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>5</th>\n", - " <td>5</td>\n", - " <td>21</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>6</th>\n", - " <td>6</td>\n", - " <td>14</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>7</th>\n", - " <td>6</td>\n", - " <td>4</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>8</th>\n", - " <td>6</td>\n", - " <td>2</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>9</th>\n", - " <td>6</td>\n", - " <td>28</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>10</th>\n", - " <td>6</td>\n", - " <td>7</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>11</th>\n", - " <td>7</td>\n", - " <td>22</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>12</th>\n", - " <td>7</td>\n", - " <td>28</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>13</th>\n", - " <td>7</td>\n", - " <td>4</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>14</th>\n", - " <td>7</td>\n", - " <td>25</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>15</th>\n", - " <td>7</td>\n", - " <td>21</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>16</th>\n", - " <td>9</td>\n", - " <td>12</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>17</th>\n", - " <td>9</td>\n", - " <td>30</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>18</th>\n", - " <td>9</td>\n", - " <td>14</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>19</th>\n", - " <td>9</td>\n", - " <td>7</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>20</th>\n", - " <td>9</td>\n", - " <td>21</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>21</th>\n", - " <td>10</td>\n", - " <td>28</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>22</th>\n", - " <td>10</td>\n", - " <td>22</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>23</th>\n", - " <td>10</td>\n", - " <td>25</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>24</th>\n", - " <td>11</td>\n", - " <td>0</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>0</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>25</th>\n", - " <td>11</td>\n", - " <td>28</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>0</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>26</th>\n", - " <td>11</td>\n", - " <td>27</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>0</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>27</th>\n", - " <td>11</td>\n", - " <td>25</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>0</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>28</th>\n", - " <td>11</td>\n", - " <td>24</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>0</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>29</th>\n", - " <td>12</td>\n", - " <td>9</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>30</th>\n", - " <td>12</td>\n", - " <td>19</td>\n", - " <td>1</td>\n", - " <td>normal</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>...</th>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3488</th>\n", - " <td>25</td>\n", - " <td>28</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3489</th>\n", - " <td>25</td>\n", - " <td>14</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3490</th>\n", - " <td>25</td>\n", - " <td>27</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3491</th>\n", - " <td>25</td>\n", - " <td>15</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3492</th>\n", - " <td>25</td>\n", - " <td>7</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3493</th>\n", - " <td>25</td>\n", - " <td>24</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3494</th>\n", - " <td>25</td>\n", - " <td>21</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3495</th>\n", - " <td>27</td>\n", - " <td>25</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3496</th>\n", - " <td>27</td>\n", - " <td>14</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3497</th>\n", - " <td>27</td>\n", - " <td>20</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3498</th>\n", - " <td>27</td>\n", - " <td>24</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3499</th>\n", - " <td>27</td>\n", - " <td>5</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3500</th>\n", - " <td>27</td>\n", - " <td>21</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3501</th>\n", - " <td>27</td>\n", - " <td>7</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3502</th>\n", - " <td>28</td>\n", - " <td>25</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3503</th>\n", - " <td>28</td>\n", - " <td>10</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3504</th>\n", - " <td>28</td>\n", - " <td>7</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3505</th>\n", - " <td>28</td>\n", - " <td>6</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3506</th>\n", - " <td>28</td>\n", - " <td>4</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3507</th>\n", - " <td>28</td>\n", - " <td>14</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3508</th>\n", - " <td>28</td>\n", - " <td>21</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3509</th>\n", - " <td>28</td>\n", - " <td>15</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3510</th>\n", - " <td>30</td>\n", - " <td>14</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3511</th>\n", - " <td>30</td>\n", - " <td>10</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3512</th>\n", - " <td>30</td>\n", - " <td>7</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3513</th>\n", - " <td>30</td>\n", - " <td>24</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3514</th>\n", - " <td>30</td>\n", - " <td>21</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3515</th>\n", - " <td>30</td>\n", - " <td>25</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3516</th>\n", - " <td>30</td>\n", - " <td>6</td>\n", - " <td>9</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3517</th>\n", - " <td>0</td>\n", - " <td>2</td>\n", - " <td>1</td>\n", - " <td>extension_2</td>\n", - " <td>3</td>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "<p>3517 rows × 10 columns</p>\n", - "</div>" - ], - "text/plain": [ - " id_g1 id_g2 mesure type id_user c1_val c2_val c3_val \\\n", - "id \n", - "1 5 27 1 normal 3 1 1 0 \n", - "2 5 7 1 normal 3 1 1 1 \n", - "3 5 24 1 normal 3 1 1 1 \n", - "4 5 4 1 normal 3 1 1 1 \n", - "5 5 21 1 normal 3 1 1 1 \n", - "6 6 14 1 normal 3 1 1 1 \n", - "7 6 4 1 normal 3 1 1 1 \n", - "8 6 2 1 normal 3 1 1 0 \n", - "9 6 28 1 normal 3 1 1 1 \n", - "10 6 7 1 normal 3 1 1 1 \n", - "11 7 22 1 normal 3 1 1 1 \n", - "12 7 28 1 normal 3 1 1 1 \n", - "13 7 4 1 normal 3 1 1 1 \n", - "14 7 25 1 normal 3 1 1 1 \n", - "15 7 21 1 normal 3 1 1 1 \n", - "16 9 12 1 normal 3 1 1 1 \n", - "17 9 30 1 normal 3 1 1 0 \n", - "18 9 14 1 normal 3 1 1 0 \n", - "19 9 7 1 normal 3 1 1 1 \n", - "20 9 21 1 normal 3 1 1 1 \n", - "21 10 28 1 normal 3 1 1 1 \n", - "22 10 22 1 normal 3 1 1 1 \n", - "23 10 25 1 normal 3 1 1 1 \n", - "24 11 0 1 normal 3 0 1 0 \n", - "25 11 28 1 normal 3 0 1 0 \n", - "26 11 27 1 normal 3 0 1 0 \n", - "27 11 25 1 normal 3 0 1 0 \n", - "28 11 24 1 normal 3 0 1 0 \n", - "29 12 9 1 normal 3 1 1 1 \n", - "30 12 19 1 normal 3 1 1 1 \n", - "... ... ... ... ... ... ... ... ... \n", - "3488 25 28 9 extension_2 3 1 1 1 \n", - "3489 25 14 9 extension_2 3 1 1 1 \n", - "3490 25 27 9 extension_2 3 1 1 1 \n", - "3491 25 15 9 extension_2 3 1 1 1 \n", - "3492 25 7 9 extension_2 3 1 1 1 \n", - "3493 25 24 9 extension_2 3 1 1 1 \n", - "3494 25 21 9 extension_2 3 1 1 1 \n", - "3495 27 25 9 extension_2 3 1 1 1 \n", - "3496 27 14 9 extension_2 3 1 1 1 \n", - "3497 27 20 9 extension_2 3 1 1 1 \n", - "3498 27 24 9 extension_2 3 1 1 1 \n", - "3499 27 5 9 extension_2 3 1 1 1 \n", - "3500 27 21 9 extension_2 3 1 1 1 \n", - "3501 27 7 9 extension_2 3 1 1 1 \n", - "3502 28 25 9 extension_2 3 1 1 1 \n", - "3503 28 10 9 extension_2 3 1 1 1 \n", - "3504 28 7 9 extension_2 3 1 1 1 \n", - "3505 28 6 9 extension_2 3 1 1 1 \n", - "3506 28 4 9 extension_2 3 1 1 1 \n", - "3507 28 14 9 extension_2 3 1 1 1 \n", - "3508 28 21 9 extension_2 3 1 1 1 \n", - "3509 28 15 9 extension_2 3 1 1 1 \n", - "3510 30 14 9 extension_2 3 1 1 1 \n", - "3511 30 10 9 extension_2 3 1 1 0 \n", - "3512 30 7 9 extension_2 3 1 1 1 \n", - "3513 30 24 9 extension_2 3 1 1 1 \n", - "3514 30 21 9 extension_2 3 1 1 1 \n", - "3515 30 25 9 extension_2 3 1 1 0 \n", - "3516 30 6 9 extension_2 3 1 1 0 \n", - "3517 0 2 1 extension_2 3 1 1 0 \n", - "\n", - " c4_val mesureL \n", - "id \n", - "1 1 MCS \n", - "2 0 MCS \n", - "3 0 MCS \n", - "4 0 MCS \n", - "5 0 MCS \n", - "6 0 MCS \n", - "7 0 MCS \n", - "8 0 MCS \n", - "9 0 MCS \n", - "10 0 MCS \n", - "11 1 MCS \n", - "12 0 MCS \n", - "13 1 MCS \n", - "14 0 MCS \n", - "15 1 MCS \n", - "16 0 MCS \n", - "17 0 MCS \n", - "18 0 MCS \n", - "19 0 MCS \n", - "20 0 MCS \n", - "21 0 MCS \n", - "22 0 MCS \n", - "23 0 MCS \n", - "24 0 MCS \n", - "25 0 MCS \n", - "26 0 MCS \n", - "27 0 MCS \n", - "28 0 MCS \n", - "29 1 MCS \n", - "30 0 MCS \n", - "... ... ... \n", - "3488 0 BOC \n", - "3489 0 BOC \n", - "3490 1 BOC \n", - "3491 1 BOC \n", - "3492 0 BOC \n", - "3493 1 BOC \n", - "3494 0 BOC \n", - "3495 0 BOC \n", - "3496 0 BOC \n", - "3497 0 BOC \n", - "3498 1 BOC \n", - "3499 1 BOC \n", - "3500 0 BOC \n", - "3501 0 BOC \n", - "3502 0 BOC \n", - "3503 0 BOC \n", - "3504 0 BOC \n", - "3505 0 BOC \n", - "3506 1 BOC \n", - "3507 0 BOC \n", - "3508 0 BOC \n", - "3509 0 BOC \n", - "3510 0 BOC \n", - "3511 0 BOC \n", - "3512 1 BOC \n", - "3513 0 BOC \n", - "3514 1 BOC \n", - "3515 0 BOC \n", - "3516 0 BOC \n", - "3517 0 MCS \n", - "\n", - "[3517 rows x 10 columns]" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:05.480001Z", - "start_time": "2018-04-06T12:39:05.471331Z" - } - }, - "outputs": [], - "source": [ - "rank_data=json.load(open(\"data/graph_exp_mar_30/rank.json\"))" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:12.868622Z", - "start_time": "2018-04-06T12:39:05.481555Z" - } - }, - "outputs": [], - "source": [ - "new_df=pd.DataFrame(data=None,columns=df.columns)\n", - "for id,row in df.iterrows():\n", - " ranks=set(rank_data[row.type][row.mesureL][str(row.id_g1)][:5])\n", - " if row.id_g2 in ranks:\n", - " new_df=new_df.append(row)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:12.873132Z", - "start_time": "2018-04-06T12:39:12.870379Z" - }, - "scrolled": false - }, - "outputs": [], - "source": [ - "df=new_df" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:12.916295Z", - "start_time": "2018-04-06T12:39:12.875271Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>id_g1</th>\n", - " <th>id_g2</th>\n", - " <th>mesure</th>\n", - " <th>type</th>\n", - " <th>id_user</th>\n", - " <th>c1_val</th>\n", - " <th>c2_val</th>\n", - " <th>c3_val</th>\n", - " <th>c4_val</th>\n", - " <th>mesureL</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>5.0</td>\n", - " <td>27.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>1.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>5.0</td>\n", - " <td>7.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>5.0</td>\n", - " <td>24.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>5.0</td>\n", - " <td>4.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>5</th>\n", - " <td>5.0</td>\n", - " <td>21.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>6</th>\n", - " <td>6.0</td>\n", - " <td>14.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>7</th>\n", - " <td>6.0</td>\n", - " <td>4.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>8</th>\n", - " <td>6.0</td>\n", - " <td>2.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>9</th>\n", - " <td>6.0</td>\n", - " <td>28.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>10</th>\n", - " <td>6.0</td>\n", - " <td>7.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>11</th>\n", - " <td>7.0</td>\n", - " <td>22.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>12</th>\n", - " <td>7.0</td>\n", - " <td>28.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>13</th>\n", - " <td>7.0</td>\n", - " <td>4.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>14</th>\n", - " <td>7.0</td>\n", - " <td>25.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>15</th>\n", - " <td>7.0</td>\n", - " <td>21.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>16</th>\n", - " <td>9.0</td>\n", - " <td>12.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>17</th>\n", - " <td>9.0</td>\n", - " <td>30.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>18</th>\n", - " <td>9.0</td>\n", - " <td>14.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>19</th>\n", - " <td>9.0</td>\n", - " <td>7.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>20</th>\n", - " <td>9.0</td>\n", - " <td>21.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>21</th>\n", - " <td>10.0</td>\n", - " <td>28.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>22</th>\n", - " <td>10.0</td>\n", - " <td>22.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>23</th>\n", - " <td>10.0</td>\n", - " <td>25.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>24</th>\n", - " <td>11.0</td>\n", - " <td>0.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>0.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>25</th>\n", - " <td>11.0</td>\n", - " <td>28.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>0.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>26</th>\n", - " <td>11.0</td>\n", - " <td>27.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>0.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>27</th>\n", - " <td>11.0</td>\n", - " <td>25.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>0.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>29</th>\n", - " <td>12.0</td>\n", - " <td>9.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>30</th>\n", - " <td>12.0</td>\n", - " <td>19.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>31</th>\n", - " <td>12.0</td>\n", - " <td>15.0</td>\n", - " <td>1.0</td>\n", - " <td>normal</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " <tr>\n", - " <th>...</th>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " <td>...</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3473</th>\n", - " <td>23.0</td>\n", - " <td>6.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3474</th>\n", - " <td>23.0</td>\n", - " <td>14.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3475</th>\n", - " <td>23.0</td>\n", - " <td>20.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>0.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3476</th>\n", - " <td>23.0</td>\n", - " <td>28.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3477</th>\n", - " <td>23.0</td>\n", - " <td>27.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3481</th>\n", - " <td>24.0</td>\n", - " <td>27.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3482</th>\n", - " <td>24.0</td>\n", - " <td>14.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3483</th>\n", - " <td>24.0</td>\n", - " <td>25.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3484</th>\n", - " <td>24.0</td>\n", - " <td>28.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3485</th>\n", - " <td>24.0</td>\n", - " <td>30.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3488</th>\n", - " <td>25.0</td>\n", - " <td>28.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3489</th>\n", - " <td>25.0</td>\n", - " <td>14.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3490</th>\n", - " <td>25.0</td>\n", - " <td>27.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3491</th>\n", - " <td>25.0</td>\n", - " <td>15.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3492</th>\n", - " <td>25.0</td>\n", - " <td>7.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3495</th>\n", - " <td>27.0</td>\n", - " <td>25.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3496</th>\n", - " <td>27.0</td>\n", - " <td>14.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3497</th>\n", - " <td>27.0</td>\n", - " <td>20.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3498</th>\n", - " <td>27.0</td>\n", - " <td>24.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3499</th>\n", - " <td>27.0</td>\n", - " <td>5.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3502</th>\n", - " <td>28.0</td>\n", - " <td>25.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3503</th>\n", - " <td>28.0</td>\n", - " <td>10.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3504</th>\n", - " <td>28.0</td>\n", - " <td>7.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3505</th>\n", - " <td>28.0</td>\n", - " <td>6.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3506</th>\n", - " <td>28.0</td>\n", - " <td>4.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3510</th>\n", - " <td>30.0</td>\n", - " <td>14.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3511</th>\n", - " <td>30.0</td>\n", - " <td>10.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3512</th>\n", - " <td>30.0</td>\n", - " <td>7.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3513</th>\n", - " <td>30.0</td>\n", - " <td>24.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3516</th>\n", - " <td>30.0</td>\n", - " <td>6.0</td>\n", - " <td>9.0</td>\n", - " <td>extension_2</td>\n", - " <td>3.0</td>\n", - " <td>1.0</td>\n", - " <td>1.0</td>\n", - " <td>0.0</td>\n", - " <td>0.0</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "<p>2348 rows × 10 columns</p>\n", - "</div>" - ], - "text/plain": [ - " id_g1 id_g2 mesure type id_user c1_val c2_val c3_val \\\n", - "1 5.0 27.0 1.0 normal 3.0 1.0 1.0 0.0 \n", - "2 5.0 7.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "3 5.0 24.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "4 5.0 4.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "5 5.0 21.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "6 6.0 14.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "7 6.0 4.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "8 6.0 2.0 1.0 normal 3.0 1.0 1.0 0.0 \n", - "9 6.0 28.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "10 6.0 7.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "11 7.0 22.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "12 7.0 28.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "13 7.0 4.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "14 7.0 25.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "15 7.0 21.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "16 9.0 12.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "17 9.0 30.0 1.0 normal 3.0 1.0 1.0 0.0 \n", - "18 9.0 14.0 1.0 normal 3.0 1.0 1.0 0.0 \n", - "19 9.0 7.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "20 9.0 21.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "21 10.0 28.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "22 10.0 22.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "23 10.0 25.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "24 11.0 0.0 1.0 normal 3.0 0.0 1.0 0.0 \n", - "25 11.0 28.0 1.0 normal 3.0 0.0 1.0 0.0 \n", - "26 11.0 27.0 1.0 normal 3.0 0.0 1.0 0.0 \n", - "27 11.0 25.0 1.0 normal 3.0 0.0 1.0 0.0 \n", - "29 12.0 9.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "30 12.0 19.0 1.0 normal 3.0 1.0 1.0 1.0 \n", - "31 12.0 15.0 1.0 normal 3.0 1.0 1.0 0.0 \n", - "... ... ... ... ... ... ... ... ... \n", - "3473 23.0 6.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3474 23.0 14.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3475 23.0 20.0 9.0 extension_2 3.0 0.0 1.0 1.0 \n", - "3476 23.0 28.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3477 23.0 27.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3481 24.0 27.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3482 24.0 14.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3483 24.0 25.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3484 24.0 28.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3485 24.0 30.0 9.0 extension_2 3.0 1.0 1.0 0.0 \n", - "3488 25.0 28.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3489 25.0 14.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3490 25.0 27.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3491 25.0 15.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3492 25.0 7.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3495 27.0 25.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3496 27.0 14.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3497 27.0 20.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3498 27.0 24.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3499 27.0 5.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3502 28.0 25.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3503 28.0 10.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3504 28.0 7.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3505 28.0 6.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3506 28.0 4.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3510 30.0 14.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3511 30.0 10.0 9.0 extension_2 3.0 1.0 1.0 0.0 \n", - "3512 30.0 7.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3513 30.0 24.0 9.0 extension_2 3.0 1.0 1.0 1.0 \n", - "3516 30.0 6.0 9.0 extension_2 3.0 1.0 1.0 0.0 \n", - "\n", - " c4_val mesureL \n", - "1 1.0 MCS \n", - "2 0.0 MCS \n", - "3 0.0 MCS \n", - "4 0.0 MCS \n", - "5 0.0 MCS \n", - "6 0.0 MCS \n", - "7 0.0 MCS \n", - "8 0.0 MCS \n", - "9 0.0 MCS \n", - "10 0.0 MCS \n", - "11 1.0 MCS \n", - "12 0.0 MCS \n", - "13 1.0 MCS \n", - "14 0.0 MCS \n", - "15 1.0 MCS \n", - "16 0.0 MCS \n", - "17 0.0 MCS \n", - "18 0.0 MCS \n", - "19 0.0 MCS \n", - "20 0.0 MCS \n", - "21 0.0 MCS \n", - "22 0.0 MCS \n", - "23 0.0 MCS \n", - "24 0.0 MCS \n", - "25 0.0 MCS \n", - "26 0.0 MCS \n", - "27 0.0 MCS \n", - "29 1.0 MCS \n", - "30 0.0 MCS \n", - "31 0.0 MCS \n", - "... ... ... \n", - "3473 0.0 BOC \n", - "3474 0.0 BOC \n", - "3475 0.0 BOC \n", - "3476 1.0 BOC \n", - "3477 1.0 BOC \n", - "3481 1.0 BOC \n", - "3482 0.0 BOC \n", - "3483 1.0 BOC \n", - "3484 0.0 BOC \n", - "3485 0.0 BOC \n", - "3488 0.0 BOC \n", - "3489 0.0 BOC \n", - "3490 1.0 BOC \n", - "3491 1.0 BOC \n", - "3492 0.0 BOC \n", - "3495 0.0 BOC \n", - "3496 0.0 BOC \n", - "3497 0.0 BOC \n", - "3498 1.0 BOC \n", - "3499 1.0 BOC \n", - "3502 0.0 BOC \n", - "3503 0.0 BOC \n", - "3504 0.0 BOC \n", - "3505 0.0 BOC \n", - "3506 1.0 BOC \n", - "3510 0.0 BOC \n", - "3511 0.0 BOC \n", - "3512 1.0 BOC \n", - "3513 0.0 BOC \n", - "3516 0.0 BOC \n", - "\n", - "[2348 rows x 10 columns]" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.205430Z", - "start_time": "2018-04-06T12:39:12.918098Z" - } - }, - "outputs": [], - "source": [ - "df[\"g1_size\"]=df[\"id_g1\"].apply(lambda x:graph_size[int(x)])\n", - "df[\"g2_size\"]=df[\"id_g2\"].apply(lambda x:graph_size[int(x)])\n", - "df[\"mesureL\"]=df[\"mesure\"].apply(lambda x:df_mesure[df_mesure.id==x].values[0][-1])\n", - "df[\"mesure\"]=df[\"mesure\"].apply(lambda x:int(x))\n", - "df[\"typeI\"]=df[\"type\"].apply(lambda x:type2int[x])\n", - "df['c1*c2']=df.c1_val*df.c2_val\n", - "df['c1+c2']=(df.c1_val+df.c2_val).apply(lambda x:x if x<2 else 1)\n", - "df['c1*c2*c3']=df.c1_val*df.c2_val*df.c3_val\n", - "df['c1*c3']=df.c1_val*df.c3_val\n", - "df['c1+c3']=(df.c1_val+df.c3_val).apply(lambda x:x if x<2 else 1)\n", - "df['c2*c3']=df.c2_val*df.c3_val\n", - "df[\"for_c\"]=df[\"id_g2\"].apply(lambda x:1)\n", - "df[\"es_in_common\"]=df[\"id_g1\"].apply(lambda x:nb_of_g_w_es_com[x])\n", - "normal=df[df.type == \"normal\"]\n", - "gen_country=df[df.type == \"gen_country\"]\n", - "gen_region=df[df.type == \"gen_region\"]\n", - "extension_1=df[df.type == \"extension_1\"]" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.210201Z", - "start_time": "2018-04-06T12:39:14.207234Z" - } - }, - "outputs": [], - "source": [ - " colorized_subset=['c1_val', 'c2_val', 'c3_val',\n", - " 'c4_val', 'c1*c2', 'c1+c2', 'c1*c2*c3', 'c1*c3', 'c1+c3', 'c2*c3']" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.221369Z", - "start_time": "2018-04-06T12:39:14.212126Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>" - ] - }, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from eval.pareto import is_pareto_front\n", - "from eval.visualize import *" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.230073Z", - "start_time": "2018-04-06T12:39:14.223019Z" - } - }, - "outputs": [], - "source": [ - "def get_pareto_graph_ids(df,criteria):\n", - " set_=set([])\n", - " for c in criteria:\n", - " df_is_pareto = df.apply(lambda row: is_pareto_front(df,row, [x_label, c]), axis=1)\n", - " df_pareto = df.ix[df_is_pareto]\n", - " for i,row in df_pareto.iterrows():\n", - " set_.add(int(row.id_g1))\n", - " return list(set_)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.235035Z", - "start_time": "2018-04-06T12:39:14.232011Z" - } - }, - "outputs": [], - "source": [ - "keys_alone=['c1_val', 'c2_val', 'c3_val', 'c4_val']\n", - "keys_combined=['c1*c2', 'c1*c2*c3', 'c1*c3', 'c2*c3']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Quelle mesure maximise les 4 critères ?\n", - "\n", - "Procédure de test:\n", - "\n", - " * On récupére la valeur de précision pour chaque mesure et critère.\n", - " * On calcule le front de Pareto sur les 4 critères de validation\n", - " \n", - "Résultat :\n", - " MCS et VEO maximise les différents critères selon la valeur de précision moyenne sur l'ensemble des couples de graphes.\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.294422Z", - "start_time": "2018-04-06T12:39:14.236778Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>mesure</th>\n", - " <th>c1_val</th>\n", - " <th>c2_val</th>\n", - " <th>c3_val</th>\n", - " <th>c4_val</th>\n", - " <th>mesureL</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>9</td>\n", - " <td>0.926298</td>\n", - " <td>0.944724</td>\n", - " <td>0.685092</td>\n", - " <td>0.324958</td>\n", - " <td>BOC</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>2</td>\n", - " <td>0.950000</td>\n", - " <td>0.970690</td>\n", - " <td>0.679310</td>\n", - " <td>0.317241</td>\n", - " <td>VEO</td>\n", - " </tr>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>1</td>\n", - " <td>0.954545</td>\n", - " <td>0.979021</td>\n", - " <td>0.690559</td>\n", - " <td>0.302448</td>\n", - " <td>MCS</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "</div>" - ], - "text/plain": [ - " mesure c1_val c2_val c3_val c4_val mesureL\n", - "3 9 0.926298 0.944724 0.685092 0.324958 BOC\n", - "1 2 0.950000 0.970690 0.679310 0.317241 VEO\n", - "0 1 0.954545 0.979021 0.690559 0.302448 MCS" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "d_pc=df.groupby(['mesure'],as_index=False).mean()[['mesure','c1_val','c2_val','c3_val','c4_val']]\n", - "df_is_pareto = d_pc.apply(lambda row: is_pareto_front(d_pc,row, ['c1_val','c2_val','c3_val','c4_val']), axis=1)\n", - "df_pareto = d_pc.ix[df_is_pareto].sort_values(by=['c1_val','c2_val','c3_val','c4_val'])\n", - "df_pareto[\"mesureL\"]=df_pareto[\"mesure\"].apply(lambda x:df_mesure[df_mesure.id==x].values[0][-1])\n", - "%matplotlib inline\n", - "df_pareto" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:49:03.928978Z", - "start_time": "2018-04-06T12:49:03.914662Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>mesure</th>\n", - " <th>c1_val</th>\n", - " <th>c2_val</th>\n", - " <th>c3_val</th>\n", - " <th>c4_val</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>1</td>\n", - " <td>0.954545</td>\n", - " <td>0.979021</td>\n", - " <td>0.690559</td>\n", - " <td>0.302448</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>2</td>\n", - " <td>0.950000</td>\n", - " <td>0.970690</td>\n", - " <td>0.679310</td>\n", - " <td>0.317241</td>\n", - " </tr>\n", - " <tr>\n", - " <th>2</th>\n", - " <td>8</td>\n", - " <td>0.944908</td>\n", - " <td>0.918197</td>\n", - " <td>0.622705</td>\n", - " <td>0.295492</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>9</td>\n", - " <td>0.926298</td>\n", - " <td>0.944724</td>\n", - " <td>0.685092</td>\n", - " <td>0.324958</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "</div>" - ], - "text/plain": [ - " mesure c1_val c2_val c3_val c4_val\n", - "0 1 0.954545 0.979021 0.690559 0.302448\n", - "1 2 0.950000 0.970690 0.679310 0.317241\n", - "2 8 0.944908 0.918197 0.622705 0.295492\n", - "3 9 0.926298 0.944724 0.685092 0.324958" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.groupby(['mesure'],as_index=False).mean()[['mesure','c1_val','c2_val','c3_val','c4_val']]" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.305968Z", - "start_time": "2018-04-06T12:39:14.296269Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\\begin{tabular}{rrrrr}\n", - "\\toprule\n", - " mesure & c1\\_val & c2\\_val & c3\\_val & c4\\_val \\\\\n", - "\\midrule\n", - " 1 & 0.954545 & 0.979021 & 0.690559 & 0.302448 \\\\\n", - " 2 & 0.950000 & 0.970690 & 0.679310 & 0.317241 \\\\\n", - " 8 & 0.944908 & 0.918197 & 0.622705 & 0.295492 \\\\\n", - " 9 & 0.926298 & 0.944724 & 0.685092 & 0.324958 \\\\\n", - "\\bottomrule\n", - "\\end{tabular}\n", - "\n" - ] - } - ], - "source": [ - "print(d_pc.to_latex(index=False))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Quelles couple \"Mesure-TypeSTR\" maximise la validation des 4 critères ?\n", - "\n", - "Procèdure :\n", - " * On récupére la valeur de précision moyenne pour chaque critère, en fonction de la mesure et du type.\n", - " * On récupére les tuples appartenant au front de pareto sur les 4 critères.\n", - " \n", - "Résultat:\n", - " Comme dans les résultats précédents, les mesures MCS, VEO obtiennent les meilleurs scores. Enfin, les types de STR associées, donnant les meilleurs scores sont : gen_region, extension1, puis normal. On peut déjà conclure que la généralisation --**bornée Pays**-- déforme trop l'information contenue dans les graphes, on perd trop en finesse. " - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.445951Z", - "start_time": "2018-04-06T12:39:14.308985Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "<div>\n", - "<table border=\"1\" class=\"dataframe\">\n", - " <thead>\n", - " <tr style=\"text-align: right;\">\n", - " <th></th>\n", - " <th>mesure</th>\n", - " <th>typeI</th>\n", - " <th>c1_val</th>\n", - " <th>c2_val</th>\n", - " <th>c3_val</th>\n", - " <th>c4_val</th>\n", - " <th>mesureL</th>\n", - " <th>typeL</th>\n", - " </tr>\n", - " </thead>\n", - " <tbody>\n", - " <tr>\n", - " <th>18</th>\n", - " <td>9</td>\n", - " <td>3</td>\n", - " <td>0.940678</td>\n", - " <td>0.957627</td>\n", - " <td>0.737288</td>\n", - " <td>0.296610</td>\n", - " <td>BOC</td>\n", - " <td>extension_1</td>\n", - " </tr>\n", - " <tr>\n", - " <th>15</th>\n", - " <td>9</td>\n", - " <td>0</td>\n", - " <td>0.949580</td>\n", - " <td>0.949580</td>\n", - " <td>0.714286</td>\n", - " <td>0.352941</td>\n", - " <td>BOC</td>\n", - " <td>normal</td>\n", - " </tr>\n", - " <tr>\n", - " <th>8</th>\n", - " <td>2</td>\n", - " <td>3</td>\n", - " <td>0.956897</td>\n", - " <td>0.982759</td>\n", - " <td>0.689655</td>\n", - " <td>0.310345</td>\n", - " <td>VEO</td>\n", - " <td>extension_1</td>\n", - " </tr>\n", - " <tr>\n", - " <th>9</th>\n", - " <td>2</td>\n", - " <td>4</td>\n", - " <td>0.957265</td>\n", - " <td>0.982906</td>\n", - " <td>0.700855</td>\n", - " <td>0.299145</td>\n", - " <td>VEO</td>\n", - " <td>extension_2</td>\n", - " </tr>\n", - " <tr>\n", - " <th>4</th>\n", - " <td>1</td>\n", - " <td>4</td>\n", - " <td>0.957627</td>\n", - " <td>0.991525</td>\n", - " <td>0.720339</td>\n", - " <td>0.296610</td>\n", - " <td>MCS</td>\n", - " <td>extension_2</td>\n", - " </tr>\n", - " <tr>\n", - " <th>3</th>\n", - " <td>1</td>\n", - " <td>3</td>\n", - " <td>0.957983</td>\n", - " <td>0.991597</td>\n", - " <td>0.697479</td>\n", - " <td>0.285714</td>\n", - " <td>MCS</td>\n", - " <td>extension_1</td>\n", - " </tr>\n", - " <tr>\n", - " <th>0</th>\n", - " <td>1</td>\n", - " <td>0</td>\n", - " <td>0.958763</td>\n", - " <td>0.979381</td>\n", - " <td>0.711340</td>\n", - " <td>0.278351</td>\n", - " <td>MCS</td>\n", - " <td>normal</td>\n", - " </tr>\n", - " <tr>\n", - " <th>5</th>\n", - " <td>2</td>\n", - " <td>0</td>\n", - " <td>0.963636</td>\n", - " <td>0.972727</td>\n", - " <td>0.700000</td>\n", - " <td>0.345455</td>\n", - " <td>VEO</td>\n", - " <td>normal</td>\n", - " </tr>\n", - " <tr>\n", - " <th>1</th>\n", - " <td>1</td>\n", - " <td>1</td>\n", - " <td>0.966387</td>\n", - " <td>0.974790</td>\n", - " <td>0.680672</td>\n", - " <td>0.327731</td>\n", - " <td>MCS</td>\n", - " <td>gen_region</td>\n", - " </tr>\n", - " <tr>\n", - " <th>6</th>\n", - " <td>2</td>\n", - " <td>1</td>\n", - " <td>0.966387</td>\n", - " <td>0.974790</td>\n", - " <td>0.705882</td>\n", - " <td>0.310924</td>\n", - " <td>VEO</td>\n", - " <td>gen_region</td>\n", - " </tr>\n", - " </tbody>\n", - "</table>\n", - "</div>" - ], - "text/plain": [ - " mesure typeI c1_val c2_val c3_val c4_val mesureL typeL\n", - "18 9 3 0.940678 0.957627 0.737288 0.296610 BOC extension_1\n", - "15 9 0 0.949580 0.949580 0.714286 0.352941 BOC normal\n", - "8 2 3 0.956897 0.982759 0.689655 0.310345 VEO extension_1\n", - "9 2 4 0.957265 0.982906 0.700855 0.299145 VEO extension_2\n", - "4 1 4 0.957627 0.991525 0.720339 0.296610 MCS extension_2\n", - "3 1 3 0.957983 0.991597 0.697479 0.285714 MCS extension_1\n", - "0 1 0 0.958763 0.979381 0.711340 0.278351 MCS normal\n", - "5 2 0 0.963636 0.972727 0.700000 0.345455 VEO normal\n", - "1 1 1 0.966387 0.974790 0.680672 0.327731 MCS gen_region\n", - "6 2 1 0.966387 0.974790 0.705882 0.310924 VEO gen_region" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# On regroupe les données selon la mesure et le type de STR utilisé --> Pour chaque critère, on aura la valeur moyenne\n", - "# retourné par le critère sur l'ensemble des couples de graphes de la mesure.\n", - "d_pc=df.groupby(['mesure','typeI'],as_index=False).mean()[['mesure','typeI','c1_val','c2_val','c3_val','c4_val']]\n", - "df_is_pareto = d_pc.apply(lambda row: is_pareto_front(d_pc,row, ['c1_val','c2_val','c3_val','c4_val']), axis=1)\n", - "df_pareto = d_pc.ix[df_is_pareto].sort_values(by=['c1_val','c2_val','c3_val','c4_val'])\n", - "df_pareto[\"mesureL\"]=df_pareto[\"mesure\"].apply(lambda x:df_mesure[df_mesure.id==x].values[0][-1])\n", - "df_pareto[\"typeL\"]=df_pareto[\"typeI\"].apply(lambda x:int2type[x])\n", - "#df_pareto[\"type\"]=df_pareto[\"type\"].apply(lambda x:type2int.index(x))\n", - "%matplotlib inline\n", - "df_pareto" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.628489Z", - "start_time": "2018-04-06T12:39:14.448239Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " <style type=\"text/css\" >\n", - " \n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow0_col7 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow0_col8 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow0_col13 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow0_col14 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow0_col15 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow0_col17 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow1_col5 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow1_col6 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow1_col7 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow1_col12 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow1_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow1_col14 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow1_col15 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow1_col16 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow1_col17 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow2_col5 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow2_col6 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow2_col8 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow2_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow2_col16 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow3_col5 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow3_col12 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow3_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_839da77a_3997_11e8_aa59_4c327598678brow3_col16 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " </style>\n", - "\n", - " <table id=\"T_839da77a_3997_11e8_aa59_4c327598678b\" None>\n", - " \n", - "\n", - " <thead>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th class=\"blank level0\" >\n", - " \n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col0\" colspan=1>\n", - " mesureL\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col1\" colspan=1>\n", - " id_g1\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col2\" colspan=1>\n", - " id_g2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col3\" colspan=1>\n", - " mesure\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col4\" colspan=1>\n", - " id_user\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col5\" colspan=1>\n", - " c1_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col6\" colspan=1>\n", - " c2_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col7\" colspan=1>\n", - " c3_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col8\" colspan=1>\n", - " c4_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col9\" colspan=1>\n", - " g1_size\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col10\" colspan=1>\n", - " g2_size\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col11\" colspan=1>\n", - " typeI\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col12\" colspan=1>\n", - " c1*c2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col13\" colspan=1>\n", - " c1+c2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col14\" colspan=1>\n", - " c1*c2*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col15\" colspan=1>\n", - " c1*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col16\" colspan=1>\n", - " c1+c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col17\" colspan=1>\n", - " c2*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col18\" colspan=1>\n", - " for_c\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col19\" colspan=1>\n", - " es_in_common\n", - " \n", - " \n", - " </tr>\n", - " \n", - " </thead>\n", - " <tbody>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_839da77a_3997_11e8_aa59_4c327598678b\"\n", - " class=\"row_heading level0 row0\" rowspan=1>\n", - " 0\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col0\"\n", - " class=\"data row0 col0\" >\n", - " BOC\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col1\"\n", - " class=\"data row0 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col2\"\n", - " class=\"data row0 col2\" >\n", - " 15.1708\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col3\"\n", - " class=\"data row0 col3\" >\n", - " 9\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col4\"\n", - " class=\"data row0 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col5\"\n", - " class=\"data row0 col5\" >\n", - " 0.95\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col6\"\n", - " class=\"data row0 col6\" >\n", - " 0.95\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col7\"\n", - " class=\"data row0 col7\" >\n", - " 0.716667\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col8\"\n", - " class=\"data row0 col8\" >\n", - " 0.352083\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col9\"\n", - " class=\"data row0 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col10\"\n", - " class=\"data row0 col10\" >\n", - " 13.1708\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col11\"\n", - " class=\"data row0 col11\" >\n", - " 0\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col12\"\n", - " class=\"data row0 col12\" >\n", - " 0.908333\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col13\"\n", - " class=\"data row0 col13\" >\n", - " 0.991667\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col14\"\n", - " class=\"data row0 col14\" >\n", - " 0.716667\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col15\"\n", - " class=\"data row0 col15\" >\n", - " 0.716667\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col16\"\n", - " class=\"data row0 col16\" >\n", - " 0.95\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col17\"\n", - " class=\"data row0 col17\" >\n", - " 0.716667\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col18\"\n", - " class=\"data row0 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow0_col19\"\n", - " class=\"data row0 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_839da77a_3997_11e8_aa59_4c327598678b\"\n", - " class=\"row_heading level0 row1\" rowspan=1>\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col0\"\n", - " class=\"data row1 col0\" >\n", - " BOWSE\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col1\"\n", - " class=\"data row1 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col2\"\n", - " class=\"data row1 col2\" >\n", - " 14.8333\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col3\"\n", - " class=\"data row1 col3\" >\n", - " 8\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col4\"\n", - " class=\"data row1 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col5\"\n", - " class=\"data row1 col5\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col6\"\n", - " class=\"data row1 col6\" >\n", - " 0.916667\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col7\"\n", - " class=\"data row1 col7\" >\n", - " 0.616667\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col8\"\n", - " class=\"data row1 col8\" >\n", - " 0.3\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col9\"\n", - " class=\"data row1 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col10\"\n", - " class=\"data row1 col10\" >\n", - " 10.3\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col11\"\n", - " class=\"data row1 col11\" >\n", - " 0\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col12\"\n", - " class=\"data row1 col12\" >\n", - " 0.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col13\"\n", - " class=\"data row1 col13\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col14\"\n", - " class=\"data row1 col14\" >\n", - " 0.616667\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col15\"\n", - " class=\"data row1 col15\" >\n", - " 0.616667\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col16\"\n", - " class=\"data row1 col16\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col17\"\n", - " class=\"data row1 col17\" >\n", - " 0.616667\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col18\"\n", - " class=\"data row1 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow1_col19\"\n", - " class=\"data row1 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_839da77a_3997_11e8_aa59_4c327598678b\"\n", - " class=\"row_heading level0 row2\" rowspan=1>\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col0\"\n", - " class=\"data row2 col0\" >\n", - " MCS\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col1\"\n", - " class=\"data row2 col1\" >\n", - " 17.25\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col2\"\n", - " class=\"data row2 col2\" >\n", - " 17.53\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col3\"\n", - " class=\"data row2 col3\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col4\"\n", - " class=\"data row2 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col5\"\n", - " class=\"data row2 col5\" >\n", - " 0.95\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col6\"\n", - " class=\"data row2 col6\" >\n", - " 0.98\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col7\"\n", - " class=\"data row2 col7\" >\n", - " 0.71\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col8\"\n", - " class=\"data row2 col8\" >\n", - " 0.27\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col9\"\n", - " class=\"data row2 col9\" >\n", - " 14.3\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col10\"\n", - " class=\"data row2 col10\" >\n", - " 12.6975\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col11\"\n", - " class=\"data row2 col11\" >\n", - " 0\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col12\"\n", - " class=\"data row2 col12\" >\n", - " 0.93\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col13\"\n", - " class=\"data row2 col13\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col14\"\n", - " class=\"data row2 col14\" >\n", - " 0.71\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col15\"\n", - " class=\"data row2 col15\" >\n", - " 0.71\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col16\"\n", - " class=\"data row2 col16\" >\n", - " 0.95\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col17\"\n", - " class=\"data row2 col17\" >\n", - " 0.71\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col18\"\n", - " class=\"data row2 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow2_col19\"\n", - " class=\"data row2 col19\" >\n", - " 19.4\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_839da77a_3997_11e8_aa59_4c327598678b\"\n", - " class=\"row_heading level0 row3\" rowspan=1>\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col0\"\n", - " class=\"data row3 col0\" >\n", - " VEO\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col1\"\n", - " class=\"data row3 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col2\"\n", - " class=\"data row3 col2\" >\n", - " 16.9931\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col3\"\n", - " class=\"data row3 col3\" >\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col4\"\n", - " class=\"data row3 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col5\"\n", - " class=\"data row3 col5\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col6\"\n", - " class=\"data row3 col6\" >\n", - " 0.972917\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col7\"\n", - " class=\"data row3 col7\" >\n", - " 0.69375\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col8\"\n", - " class=\"data row3 col8\" >\n", - " 0.342361\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col9\"\n", - " class=\"data row3 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col10\"\n", - " class=\"data row3 col10\" >\n", - " 11.9535\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col11\"\n", - " class=\"data row3 col11\" >\n", - " 0\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col12\"\n", - " class=\"data row3 col12\" >\n", - " 0.93125\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col13\"\n", - " class=\"data row3 col13\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col14\"\n", - " class=\"data row3 col14\" >\n", - " 0.69375\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col15\"\n", - " class=\"data row3 col15\" >\n", - " 0.69375\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col16\"\n", - " class=\"data row3 col16\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col17\"\n", - " class=\"data row3 col17\" >\n", - " 0.69375\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col18\"\n", - " class=\"data row3 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_839da77a_3997_11e8_aa59_4c327598678brow3_col19\"\n", - " class=\"data row3 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " </tbody>\n", - " </table>\n", - " " - ], - "text/plain": [ - "<pandas.formats.style.Styler at 0x10dfe4710>" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "score_per_mesure=normal.groupby([\"id_g1\",\"mesureL\"], as_index=False).mean()\n", - "score_normal=score_per_mesure.groupby([\"mesureL\"],as_index=False).mean()\n", - "def highlight_max(s):\n", - " '''\n", - " highlight the maximum in a Series yellow.\n", - " '''\n", - " is_max = s == s.max()\n", - " return ['background-color: yellow' if v else '' for v in is_max]\n", - "def highlight_min(s):\n", - " '''\n", - " highlight the maximum in a Series yellow.\n", - " '''\n", - " is_max = s == s.min()\n", - " return ['background-color: red;color:white;' if v else '' for v in is_max]\n", - "score_normal.style.apply(highlight_max,subset=colorized_subset).apply(highlight_min,subset=colorized_subset)" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.707540Z", - "start_time": "2018-04-06T12:39:14.631275Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " <style type=\"text/css\" >\n", - " \n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col5 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col7 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col8 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col12 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col13 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col14 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col15 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col16 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col17 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col6 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col8 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col5 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col6 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col7 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col12 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col13 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col14 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col15 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col16 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col17 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " </style>\n", - "\n", - " <table id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678b\" None>\n", - " \n", - "\n", - " <thead>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th class=\"blank level0\" >\n", - " \n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col0\" colspan=1>\n", - " mesureL\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col1\" colspan=1>\n", - " id_g1\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col2\" colspan=1>\n", - " id_g2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col3\" colspan=1>\n", - " mesure\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col4\" colspan=1>\n", - " id_user\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col5\" colspan=1>\n", - " c1_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col6\" colspan=1>\n", - " c2_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col7\" colspan=1>\n", - " c3_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col8\" colspan=1>\n", - " c4_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col9\" colspan=1>\n", - " g1_size\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col10\" colspan=1>\n", - " g2_size\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col11\" colspan=1>\n", - " typeI\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col12\" colspan=1>\n", - " c1*c2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col13\" colspan=1>\n", - " c1+c2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col14\" colspan=1>\n", - " c1*c2*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col15\" colspan=1>\n", - " c1*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col16\" colspan=1>\n", - " c1+c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col17\" colspan=1>\n", - " c2*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col18\" colspan=1>\n", - " for_c\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col19\" colspan=1>\n", - " es_in_common\n", - " \n", - " \n", - " </tr>\n", - " \n", - " </thead>\n", - " <tbody>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678b\"\n", - " class=\"row_heading level0 row0\" rowspan=1>\n", - " 0\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col0\"\n", - " class=\"data row0 col0\" >\n", - " BOC\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col1\"\n", - " class=\"data row0 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col2\"\n", - " class=\"data row0 col2\" >\n", - " 13.8083\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col3\"\n", - " class=\"data row0 col3\" >\n", - " 9\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col4\"\n", - " class=\"data row0 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col5\"\n", - " class=\"data row0 col5\" >\n", - " 0.866667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col6\"\n", - " class=\"data row0 col6\" >\n", - " 0.925\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col7\"\n", - " class=\"data row0 col7\" >\n", - " 0.55\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col8\"\n", - " class=\"data row0 col8\" >\n", - " 0.341667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col9\"\n", - " class=\"data row0 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col10\"\n", - " class=\"data row0 col10\" >\n", - " 11.3583\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col11\"\n", - " class=\"data row0 col11\" >\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col12\"\n", - " class=\"data row0 col12\" >\n", - " 0.808333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col13\"\n", - " class=\"data row0 col13\" >\n", - " 0.983333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col14\"\n", - " class=\"data row0 col14\" >\n", - " 0.541667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col15\"\n", - " class=\"data row0 col15\" >\n", - " 0.541667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col16\"\n", - " class=\"data row0 col16\" >\n", - " 0.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col17\"\n", - " class=\"data row0 col17\" >\n", - " 0.55\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col18\"\n", - " class=\"data row0 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow0_col19\"\n", - " class=\"data row0 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678b\"\n", - " class=\"row_heading level0 row1\" rowspan=1>\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col0\"\n", - " class=\"data row1 col0\" >\n", - " BOWSE\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col1\"\n", - " class=\"data row1 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col2\"\n", - " class=\"data row1 col2\" >\n", - " 13.6167\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col3\"\n", - " class=\"data row1 col3\" >\n", - " 8\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col4\"\n", - " class=\"data row1 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col5\"\n", - " class=\"data row1 col5\" >\n", - " 0.908333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col6\"\n", - " class=\"data row1 col6\" >\n", - " 0.916667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col7\"\n", - " class=\"data row1 col7\" >\n", - " 0.591667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col8\"\n", - " class=\"data row1 col8\" >\n", - " 0.316667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col9\"\n", - " class=\"data row1 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col10\"\n", - " class=\"data row1 col10\" >\n", - " 10.5917\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col11\"\n", - " class=\"data row1 col11\" >\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col12\"\n", - " class=\"data row1 col12\" >\n", - " 0.833333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col13\"\n", - " class=\"data row1 col13\" >\n", - " 0.991667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col14\"\n", - " class=\"data row1 col14\" >\n", - " 0.583333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col15\"\n", - " class=\"data row1 col15\" >\n", - " 0.583333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col16\"\n", - " class=\"data row1 col16\" >\n", - " 0.916667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col17\"\n", - " class=\"data row1 col17\" >\n", - " 0.591667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col18\"\n", - " class=\"data row1 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow1_col19\"\n", - " class=\"data row1 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678b\"\n", - " class=\"row_heading level0 row2\" rowspan=1>\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col0\"\n", - " class=\"data row2 col0\" >\n", - " MCS\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col1\"\n", - " class=\"data row2 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col2\"\n", - " class=\"data row2 col2\" >\n", - " 14.4333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col3\"\n", - " class=\"data row2 col3\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col4\"\n", - " class=\"data row2 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col5\"\n", - " class=\"data row2 col5\" >\n", - " 0.93125\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col6\"\n", - " class=\"data row2 col6\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col7\"\n", - " class=\"data row2 col7\" >\n", - " 0.645833\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col8\"\n", - " class=\"data row2 col8\" >\n", - " 0.320833\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col9\"\n", - " class=\"data row2 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col10\"\n", - " class=\"data row2 col10\" >\n", - " 11.4771\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col11\"\n", - " class=\"data row2 col11\" >\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col12\"\n", - " class=\"data row2 col12\" >\n", - " 0.90625\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col13\"\n", - " class=\"data row2 col13\" >\n", - " 0.983333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col14\"\n", - " class=\"data row2 col14\" >\n", - " 0.645833\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col15\"\n", - " class=\"data row2 col15\" >\n", - " 0.645833\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col16\"\n", - " class=\"data row2 col16\" >\n", - " 0.93125\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col17\"\n", - " class=\"data row2 col17\" >\n", - " 0.645833\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col18\"\n", - " class=\"data row2 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow2_col19\"\n", - " class=\"data row2 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678b\"\n", - " class=\"row_heading level0 row3\" rowspan=1>\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col0\"\n", - " class=\"data row3 col0\" >\n", - " VEO\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col1\"\n", - " class=\"data row3 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col2\"\n", - " class=\"data row3 col2\" >\n", - " 14.6167\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col3\"\n", - " class=\"data row3 col3\" >\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col4\"\n", - " class=\"data row3 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col5\"\n", - " class=\"data row3 col5\" >\n", - " 0.90625\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col6\"\n", - " class=\"data row3 col6\" >\n", - " 0.941667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col7\"\n", - " class=\"data row3 col7\" >\n", - " 0.602083\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col8\"\n", - " class=\"data row3 col8\" >\n", - " 0.320833\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col9\"\n", - " class=\"data row3 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col10\"\n", - " class=\"data row3 col10\" >\n", - " 10.7729\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col11\"\n", - " class=\"data row3 col11\" >\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col12\"\n", - " class=\"data row3 col12\" >\n", - " 0.85625\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col13\"\n", - " class=\"data row3 col13\" >\n", - " 0.991667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col14\"\n", - " class=\"data row3 col14\" >\n", - " 0.59375\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col15\"\n", - " class=\"data row3 col15\" >\n", - " 0.59375\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col16\"\n", - " class=\"data row3 col16\" >\n", - " 0.914583\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col17\"\n", - " class=\"data row3 col17\" >\n", - " 0.602083\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col18\"\n", - " class=\"data row3 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83ad6f0c_3997_11e8_a82e_4c327598678brow3_col19\"\n", - " class=\"data row3 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " </tbody>\n", - " </table>\n", - " " - ], - "text/plain": [ - "<pandas.formats.style.Styler at 0x10a361278>" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "score_per_mesure=gen_country.groupby([\"id_g1\",\"mesureL\"], as_index=False).mean()\n", - "score_gen_country=score_per_mesure.groupby([\"mesureL\"],as_index=False).mean()\n", - "score_gen_country.style.apply(highlight_max,subset=colorized_subset).apply(highlight_min,subset=colorized_subset)" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.781212Z", - "start_time": "2018-04-06T12:39:14.710046Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " <style type=\"text/css\" >\n", - " \n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow0_col5 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow0_col7 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow0_col8 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow0_col13 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow0_col14 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow0_col15 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow0_col16 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow0_col17 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow1_col5 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow1_col6 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow1_col7 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow1_col12 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow1_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow1_col14 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow1_col15 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow1_col16 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow1_col17 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow2_col5 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow2_col6 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow2_col12 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow2_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow2_col16 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow3_col5 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow3_col6 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow3_col8 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow3_col12 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow3_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83b8bf46_3997_11e8_9993_4c327598678brow3_col16 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " </style>\n", - "\n", - " <table id=\"T_83b8bf46_3997_11e8_9993_4c327598678b\" None>\n", - " \n", - "\n", - " <thead>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th class=\"blank level0\" >\n", - " \n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col0\" colspan=1>\n", - " mesureL\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col1\" colspan=1>\n", - " id_g1\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col2\" colspan=1>\n", - " id_g2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col3\" colspan=1>\n", - " mesure\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col4\" colspan=1>\n", - " id_user\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col5\" colspan=1>\n", - " c1_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col6\" colspan=1>\n", - " c2_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col7\" colspan=1>\n", - " c3_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col8\" colspan=1>\n", - " c4_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col9\" colspan=1>\n", - " g1_size\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col10\" colspan=1>\n", - " g2_size\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col11\" colspan=1>\n", - " typeI\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col12\" colspan=1>\n", - " c1*c2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col13\" colspan=1>\n", - " c1+c2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col14\" colspan=1>\n", - " c1*c2*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col15\" colspan=1>\n", - " c1*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col16\" colspan=1>\n", - " c1+c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col17\" colspan=1>\n", - " c2*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col18\" colspan=1>\n", - " for_c\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col19\" colspan=1>\n", - " es_in_common\n", - " \n", - " \n", - " </tr>\n", - " \n", - " </thead>\n", - " <tbody>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83b8bf46_3997_11e8_9993_4c327598678b\"\n", - " class=\"row_heading level0 row0\" rowspan=1>\n", - " 0\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col0\"\n", - " class=\"data row0 col0\" >\n", - " BOC\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col1\"\n", - " class=\"data row0 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col2\"\n", - " class=\"data row0 col2\" >\n", - " 15.1833\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col3\"\n", - " class=\"data row0 col3\" >\n", - " 9\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col4\"\n", - " class=\"data row0 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col5\"\n", - " class=\"data row0 col5\" >\n", - " 0.933333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col6\"\n", - " class=\"data row0 col6\" >\n", - " 0.933333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col7\"\n", - " class=\"data row0 col7\" >\n", - " 0.708333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col8\"\n", - " class=\"data row0 col8\" >\n", - " 0.341667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col9\"\n", - " class=\"data row0 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col10\"\n", - " class=\"data row0 col10\" >\n", - " 13.025\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col11\"\n", - " class=\"data row0 col11\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col12\"\n", - " class=\"data row0 col12\" >\n", - " 0.891667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col13\"\n", - " class=\"data row0 col13\" >\n", - " 0.975\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col14\"\n", - " class=\"data row0 col14\" >\n", - " 0.708333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col15\"\n", - " class=\"data row0 col15\" >\n", - " 0.708333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col16\"\n", - " class=\"data row0 col16\" >\n", - " 0.933333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col17\"\n", - " class=\"data row0 col17\" >\n", - " 0.708333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col18\"\n", - " class=\"data row0 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow0_col19\"\n", - " class=\"data row0 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83b8bf46_3997_11e8_9993_4c327598678b\"\n", - " class=\"row_heading level0 row1\" rowspan=1>\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col0\"\n", - " class=\"data row1 col0\" >\n", - " BOWSE\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col1\"\n", - " class=\"data row1 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col2\"\n", - " class=\"data row1 col2\" >\n", - " 14.3167\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col3\"\n", - " class=\"data row1 col3\" >\n", - " 8\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col4\"\n", - " class=\"data row1 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col5\"\n", - " class=\"data row1 col5\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col6\"\n", - " class=\"data row1 col6\" >\n", - " 0.916667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col7\"\n", - " class=\"data row1 col7\" >\n", - " 0.633333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col8\"\n", - " class=\"data row1 col8\" >\n", - " 0.316667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col9\"\n", - " class=\"data row1 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col10\"\n", - " class=\"data row1 col10\" >\n", - " 10.8833\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col11\"\n", - " class=\"data row1 col11\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col12\"\n", - " class=\"data row1 col12\" >\n", - " 0.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col13\"\n", - " class=\"data row1 col13\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col14\"\n", - " class=\"data row1 col14\" >\n", - " 0.633333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col15\"\n", - " class=\"data row1 col15\" >\n", - " 0.633333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col16\"\n", - " class=\"data row1 col16\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col17\"\n", - " class=\"data row1 col17\" >\n", - " 0.633333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col18\"\n", - " class=\"data row1 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow1_col19\"\n", - " class=\"data row1 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83b8bf46_3997_11e8_9993_4c327598678b\"\n", - " class=\"row_heading level0 row2\" rowspan=1>\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col0\"\n", - " class=\"data row2 col0\" >\n", - " MCS\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col1\"\n", - " class=\"data row2 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col2\"\n", - " class=\"data row2 col2\" >\n", - " 16.6583\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col3\"\n", - " class=\"data row2 col3\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col4\"\n", - " class=\"data row2 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col5\"\n", - " class=\"data row2 col5\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col6\"\n", - " class=\"data row2 col6\" >\n", - " 0.975\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col7\"\n", - " class=\"data row2 col7\" >\n", - " 0.675\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col8\"\n", - " class=\"data row2 col8\" >\n", - " 0.325\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col9\"\n", - " class=\"data row2 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col10\"\n", - " class=\"data row2 col10\" >\n", - " 11.9562\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col11\"\n", - " class=\"data row2 col11\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col12\"\n", - " class=\"data row2 col12\" >\n", - " 0.933333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col13\"\n", - " class=\"data row2 col13\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col14\"\n", - " class=\"data row2 col14\" >\n", - " 0.675\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col15\"\n", - " class=\"data row2 col15\" >\n", - " 0.675\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col16\"\n", - " class=\"data row2 col16\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col17\"\n", - " class=\"data row2 col17\" >\n", - " 0.675\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col18\"\n", - " class=\"data row2 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow2_col19\"\n", - " class=\"data row2 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83b8bf46_3997_11e8_9993_4c327598678b\"\n", - " class=\"row_heading level0 row3\" rowspan=1>\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col0\"\n", - " class=\"data row3 col0\" >\n", - " VEO\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col1\"\n", - " class=\"data row3 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col2\"\n", - " class=\"data row3 col2\" >\n", - " 16.3667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col3\"\n", - " class=\"data row3 col3\" >\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col4\"\n", - " class=\"data row3 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col5\"\n", - " class=\"data row3 col5\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col6\"\n", - " class=\"data row3 col6\" >\n", - " 0.975\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col7\"\n", - " class=\"data row3 col7\" >\n", - " 0.7\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col8\"\n", - " class=\"data row3 col8\" >\n", - " 0.308333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col9\"\n", - " class=\"data row3 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col10\"\n", - " class=\"data row3 col10\" >\n", - " 11.8812\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col11\"\n", - " class=\"data row3 col11\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col12\"\n", - " class=\"data row3 col12\" >\n", - " 0.933333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col13\"\n", - " class=\"data row3 col13\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col14\"\n", - " class=\"data row3 col14\" >\n", - " 0.7\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col15\"\n", - " class=\"data row3 col15\" >\n", - " 0.7\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col16\"\n", - " class=\"data row3 col16\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col17\"\n", - " class=\"data row3 col17\" >\n", - " 0.7\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col18\"\n", - " class=\"data row3 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83b8bf46_3997_11e8_9993_4c327598678brow3_col19\"\n", - " class=\"data row3 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " </tbody>\n", - " </table>\n", - " " - ], - "text/plain": [ - "<pandas.formats.style.Styler at 0x10df78eb8>" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "score_per_mesure=gen_region.groupby([\"id_g1\",\"mesureL\"], as_index=False).mean()\n", - "score_gen_region=score_per_mesure.groupby([\"mesureL\"],as_index=False).mean()\n", - "score_gen_region.style.apply(highlight_max,subset=colorized_subset).apply(highlight_min,subset=colorized_subset)" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": { - "ExecuteTime": { - "end_time": "2018-04-06T12:39:14.852503Z", - "start_time": "2018-04-06T12:39:14.782871Z" - } - }, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " <style type=\"text/css\" >\n", - " \n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col5 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col7 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col13 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col14 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col15 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col16 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col17 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col5 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col6 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col7 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col12 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col14 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col15 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col16 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col17 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col5 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col6 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col8 {\n", - " \n", - " : ;\n", - " \n", - " background-color: red;\n", - " \n", - " color: white;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col12 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col16 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col5 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col8 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col13 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " #T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col16 {\n", - " \n", - " background-color: yellow;\n", - " \n", - " : ;\n", - " \n", - " }\n", - " \n", - " </style>\n", - "\n", - " <table id=\"T_83c3c93e_3997_11e8_a7df_4c327598678b\" None>\n", - " \n", - "\n", - " <thead>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th class=\"blank level0\" >\n", - " \n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col0\" colspan=1>\n", - " mesureL\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col1\" colspan=1>\n", - " id_g1\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col2\" colspan=1>\n", - " id_g2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col3\" colspan=1>\n", - " mesure\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col4\" colspan=1>\n", - " id_user\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col5\" colspan=1>\n", - " c1_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col6\" colspan=1>\n", - " c2_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col7\" colspan=1>\n", - " c3_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col8\" colspan=1>\n", - " c4_val\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col9\" colspan=1>\n", - " g1_size\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col10\" colspan=1>\n", - " g2_size\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col11\" colspan=1>\n", - " typeI\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col12\" colspan=1>\n", - " c1*c2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col13\" colspan=1>\n", - " c1+c2\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col14\" colspan=1>\n", - " c1*c2*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col15\" colspan=1>\n", - " c1*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col16\" colspan=1>\n", - " c1+c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col17\" colspan=1>\n", - " c2*c3\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col18\" colspan=1>\n", - " for_c\n", - " \n", - " \n", - " \n", - " <th class=\"col_heading level0 col19\" colspan=1>\n", - " es_in_common\n", - " \n", - " \n", - " </tr>\n", - " \n", - " </thead>\n", - " <tbody>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83c3c93e_3997_11e8_a7df_4c327598678b\"\n", - " class=\"row_heading level0 row0\" rowspan=1>\n", - " 0\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col0\"\n", - " class=\"data row0 col0\" >\n", - " BOC\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col1\"\n", - " class=\"data row0 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col2\"\n", - " class=\"data row0 col2\" >\n", - " 15.9167\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col3\"\n", - " class=\"data row0 col3\" >\n", - " 9\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col4\"\n", - " class=\"data row0 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col5\"\n", - " class=\"data row0 col5\" >\n", - " 0.941667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col6\"\n", - " class=\"data row0 col6\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col7\"\n", - " class=\"data row0 col7\" >\n", - " 0.736111\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col8\"\n", - " class=\"data row0 col8\" >\n", - " 0.291667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col9\"\n", - " class=\"data row0 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col10\"\n", - " class=\"data row0 col10\" >\n", - " 12.5389\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col11\"\n", - " class=\"data row0 col11\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col12\"\n", - " class=\"data row0 col12\" >\n", - " 0.908333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col13\"\n", - " class=\"data row0 col13\" >\n", - " 0.991667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col14\"\n", - " class=\"data row0 col14\" >\n", - " 0.727778\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col15\"\n", - " class=\"data row0 col15\" >\n", - " 0.727778\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col16\"\n", - " class=\"data row0 col16\" >\n", - " 0.95\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col17\"\n", - " class=\"data row0 col17\" >\n", - " 0.736111\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col18\"\n", - " class=\"data row0 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow0_col19\"\n", - " class=\"data row0 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83c3c93e_3997_11e8_a7df_4c327598678b\"\n", - " class=\"row_heading level0 row1\" rowspan=1>\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col0\"\n", - " class=\"data row1 col0\" >\n", - " BOWSE\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col1\"\n", - " class=\"data row1 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col2\"\n", - " class=\"data row1 col2\" >\n", - " 15.8812\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col3\"\n", - " class=\"data row1 col3\" >\n", - " 8\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col4\"\n", - " class=\"data row1 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col5\"\n", - " class=\"data row1 col5\" >\n", - " 0.95\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col6\"\n", - " class=\"data row1 col6\" >\n", - " 0.916667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col7\"\n", - " class=\"data row1 col7\" >\n", - " 0.63125\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col8\"\n", - " class=\"data row1 col8\" >\n", - " 0.289583\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col9\"\n", - " class=\"data row1 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col10\"\n", - " class=\"data row1 col10\" >\n", - " 10.6479\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col11\"\n", - " class=\"data row1 col11\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col12\"\n", - " class=\"data row1 col12\" >\n", - " 0.866667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col13\"\n", - " class=\"data row1 col13\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col14\"\n", - " class=\"data row1 col14\" >\n", - " 0.622917\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col15\"\n", - " class=\"data row1 col15\" >\n", - " 0.622917\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col16\"\n", - " class=\"data row1 col16\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col17\"\n", - " class=\"data row1 col17\" >\n", - " 0.63125\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col18\"\n", - " class=\"data row1 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow1_col19\"\n", - " class=\"data row1 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83c3c93e_3997_11e8_a7df_4c327598678b\"\n", - " class=\"row_heading level0 row2\" rowspan=1>\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col0\"\n", - " class=\"data row2 col0\" >\n", - " MCS\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col1\"\n", - " class=\"data row2 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col2\"\n", - " class=\"data row2 col2\" >\n", - " 17.5917\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col3\"\n", - " class=\"data row2 col3\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col4\"\n", - " class=\"data row2 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col5\"\n", - " class=\"data row2 col5\" >\n", - " 0.95\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col6\"\n", - " class=\"data row2 col6\" >\n", - " 0.991667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col7\"\n", - " class=\"data row2 col7\" >\n", - " 0.691667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col8\"\n", - " class=\"data row2 col8\" >\n", - " 0.283333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col9\"\n", - " class=\"data row2 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col10\"\n", - " class=\"data row2 col10\" >\n", - " 12.1729\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col11\"\n", - " class=\"data row2 col11\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col12\"\n", - " class=\"data row2 col12\" >\n", - " 0.941667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col13\"\n", - " class=\"data row2 col13\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col14\"\n", - " class=\"data row2 col14\" >\n", - " 0.683333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col15\"\n", - " class=\"data row2 col15\" >\n", - " 0.683333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col16\"\n", - " class=\"data row2 col16\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col17\"\n", - " class=\"data row2 col17\" >\n", - " 0.691667\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col18\"\n", - " class=\"data row2 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow2_col19\"\n", - " class=\"data row2 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " <tr>\n", - " \n", - " \n", - " <th id=\"T_83c3c93e_3997_11e8_a7df_4c327598678b\"\n", - " class=\"row_heading level0 row3\" rowspan=1>\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col0\"\n", - " class=\"data row3 col0\" >\n", - " VEO\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col1\"\n", - " class=\"data row3 col1\" >\n", - " 14.75\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col2\"\n", - " class=\"data row3 col2\" >\n", - " 18.2187\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col3\"\n", - " class=\"data row3 col3\" >\n", - " 2\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col4\"\n", - " class=\"data row3 col4\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col5\"\n", - " class=\"data row3 col5\" >\n", - " 0.95\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col6\"\n", - " class=\"data row3 col6\" >\n", - " 0.983333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col7\"\n", - " class=\"data row3 col7\" >\n", - " 0.6875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col8\"\n", - " class=\"data row3 col8\" >\n", - " 0.310417\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col9\"\n", - " class=\"data row3 col9\" >\n", - " 12.875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col10\"\n", - " class=\"data row3 col10\" >\n", - " 11.4729\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col11\"\n", - " class=\"data row3 col11\" >\n", - " 3\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col12\"\n", - " class=\"data row3 col12\" >\n", - " 0.933333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col13\"\n", - " class=\"data row3 col13\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col14\"\n", - " class=\"data row3 col14\" >\n", - " 0.679167\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col15\"\n", - " class=\"data row3 col15\" >\n", - " 0.679167\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col16\"\n", - " class=\"data row3 col16\" >\n", - " 0.958333\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col17\"\n", - " class=\"data row3 col17\" >\n", - " 0.6875\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col18\"\n", - " class=\"data row3 col18\" >\n", - " 1\n", - " \n", - " \n", - " \n", - " <td id=\"T_83c3c93e_3997_11e8_a7df_4c327598678brow3_col19\"\n", - " class=\"data row3 col19\" >\n", - " 19.5833\n", - " \n", - " \n", - " </tr>\n", - " \n", - " </tbody>\n", - " </table>\n", - " " - ], - "text/plain": [ - "<pandas.formats.style.Styler at 0x10bbdc668>" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "score_per_mesure=extension_1.groupby([\"id_g1\",\"mesureL\"], as_index=False).mean()\n", - "score_ext_1=score_per_mesure.groupby([\"mesureL\"],as_index=False).mean()\n", - "score_ext_1.style.apply(highlight_max,subset=colorized_subset).apply(highlight_min,subset=colorized_subset)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -6572,7 +66,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.0" + "version": "3.6.5" }, "toc": { "nav_menu": {}, @@ -6586,9 +80,9 @@ }, "varInspector": { "cols": { - "lenName": 16.0, - "lenType": 16.0, - "lenVar": 40.0 + "lenName": 16, + "lenType": 16, + "lenVar": 40 }, "kernels_config": { "python": { diff --git a/notebooks/MadaMada.ipynb b/notebooks/MadaMada.ipynb index 1b56af3..80e9363 100644 --- a/notebooks/MadaMada.ipynb +++ b/notebooks/MadaMada.ipynb @@ -151,7 +151,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.0" + "version": "3.6.5" }, "toc": { "nav_menu": {}, @@ -165,9 +165,9 @@ }, "varInspector": { "cols": { - "lenName": 16.0, - "lenType": 16.0, - "lenVar": 40.0 + "lenName": 16, + "lenType": 16, + "lenVar": 40 }, "kernels_config": { "python": { diff --git a/notebooks/WorthItEval.ipynb b/notebooks/WorthItEval.ipynb index 716d13a..767999f 100644 --- a/notebooks/WorthItEval.ipynb +++ b/notebooks/WorthItEval.ipynb @@ -1344,7 +1344,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.0" + "version": "3.6.5" }, "toc": { "nav_menu": {}, diff --git a/pipeline.py b/pipeline.py index 264f4a0..51bf2db 100644 --- a/pipeline.py +++ b/pipeline.py @@ -4,6 +4,7 @@ from models.str_variations import * from models.str_with_semantic import STR_SEM from models.transformation.transform import Generalisation, Expansion from nlp.disambiguator.disambiguator import Disambiguator +from nlp.disambiguator.most_common import MostCommonDisambiguator from nlp.disambiguator.pagerank import PageRankDisambiguator from nlp.exception.disambiguator import NotADisambiguatorInstance from nlp.exception.ner import NotANERInstance @@ -31,7 +32,7 @@ class Pipeline(object): self.lang=lang[:2] self.tagger=kwargs["tagger"] if "tagger" in kwargs else TreeTagger(language=lang) self.ner = kwargs["ner"] if "ner" in kwargs else StanfordNER(lang=lang[:2]) - self.disambiguator=kwargs["disambiguator"] if "disambiguator" in kwargs else PageRankDisambiguator() + self.disambiguator=kwargs["disambiguator"] if "disambiguator" in kwargs else MostCommonDisambiguator() def parse(self,text,debug=False): """ @@ -49,7 +50,7 @@ class Pipeline(object): # Disambiguation count,se_identified = self.disambiguator.disambiguate(output, self.lang) - + print(se_identified) if debug: print(se_identified) @@ -104,7 +105,7 @@ class Pipeline(object): else: count, output, tt = self.parse(text) str_=STR(output,se_identified) - str_.build(cooc=cooc,adj=adj,inc=inc) + str_.build(adj=adj,inc=inc) str_=self.transform(str_,**kwargs) #TODO : Add count return str_,count,str_.spatial_entities diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..bf5c9b0 --- /dev/null +++ b/setup.py @@ -0,0 +1,7 @@ +# coding = utf-8 +from distutils.core import setup +from Cython.Build import cythonize + +setup( + ext_modules = cythonize("helpers/collision_c.pyx") +) \ No newline at end of file diff --git a/temp.py b/temp.py deleted file mode 100644 index 37b907c..0000000 --- a/temp.py +++ /dev/null @@ -1,181 +0,0 @@ -# coding = utf-8 -import argparse -import glob -import logging -import string -import time -from concurrent.futures import ThreadPoolExecutor - -from langdetect import detect -from progressbar import ProgressBar, Timer, Bar, ETA, Counter - -from nlp.disambiguator.geodict_gaurav import * -from pipeline import * - - -logging.basicConfig(format='%(asctime)s %(message)s') - -def filter_nonprintable(text): - # Get the difference of all ASCII characters from the set of printable characters - nonprintable = set([chr(i) for i in range(128)]).difference(string.printable) - # Use translate to remove all non-printable characters - return text.translate({ord(character):None for character in nonprintable}) - -parser = argparse.ArgumentParser() -parser.add_argument("texts_input_dir") -parser.add_argument("graphs_output_dir") -parser.add_argument("metadata_output_fn") - -subparsers = parser.add_subparsers(help='commands') - -normal = subparsers.add_parser( - 'normal', help='Basic STR generation. No argument are necessary !') -normal.set_defaults(which="norm") - - -gen_parser = subparsers.add_parser( - 'generalisation', help='Apply a generalisation transformation on the generated STRs') -gen_parser.set_defaults(which="gene") -gen_parser.add_argument( - '-t','--type_gen', help='Type of generalisation',default="all") -gen_parser.add_argument( - '-n', help='Language',default=1) -gen_parser.add_argument( - '-b','--bound', help='If Generalisation is bounded, this arg. correspond' - 'to the maximal ',default="country") - -ext_parser = subparsers.add_parser( - 'extension', help='Apply a extension process on the STRs') -ext_parser.set_defaults(which="ext") -ext_parser.add_argument( - '-d','--distance', help='radius distance',default=150) -ext_parser.add_argument( - '-u','--unit', help='unit used for the radius distance',default="km") -ext_parser.add_argument( - '-a','--adjacent_count', help='number of adjacent SE add to the STR',default=1) - -args = parser.parse_args() -if "which" in args: - if args.which =="gene": - args.type_trans="gen" - elif args.which =="ext": - args.type_trans="ext" - -print("Parameters entered : ",args) - - -start = time.time() -class_=StanfordNER -# Initialise Graphs Transformers -pipeline= { - "en":Pipeline(lang="english",tagger=Tagger(),ner=class_(lang="en")), - "fr":Pipeline(lang="french",tagger=Tagger(),ner=class_(lang="fr")), - "es":Pipeline(lang="espagnol",tagger=Tagger(),ner=class_(lang="es")) -} - - - -# Read Input Files -import re -texts_=[] -if os.path.exists(args.texts_input_dir): - files_glob= glob.glob(args.texts_input_dir+"/*.txt") - files_=["" ]* len(files_glob) - for fn in files_glob: - id = int(re.findall("\d+", fn)[-1]) - files_[id]=fn - if not files_: - print("No .txt files found in {0}".format(args.texts_input_dir)) - exit() - for fn in files_: - try: - tex=open(fn).read() - #lang = detect(tex) #for bug encoding - texts_.append(tex) - except: - print("{0} could'nt be read ! Add Lorem Ipsum instead".format(fn)) - texts_.append("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.") - - -# If output Dir doesn't exists -if not os.path.exists(args.graphs_output_dir): - os.makedirs(args.graphs_output_dir) - -if not texts_: - print("No text files were loaded !") - exit() - - - - -data={} -n=0 -logging.info("Identify Document(s) language(s)") -with ProgressBar(max_value=len(texts_),widgets=[' [', Timer(), '] ',Bar(),'(', Counter(),')','(', ETA(), ')']) as pg: - for text in range(len(texts_)): - pg.update(text) - if not text: - lang="en" - else: - try: - lang=detect(texts_[text]) - - except Exception as e: - lang="en" - #print(lang, text) - if not lang in data and lang in pipeline: - data[lang]=[] - if lang in pipeline: - data[lang].append(text) - else: - if not "en" in data:data["en"]=[] # Ca peut arriver :s :s :s !!! - data["en"].append(text) - # except: - # n+=1 # encoding error - -associated_es={} -count_per_doc={} -list_gs=[] -i=0 - - - -def workSTR(id_doc,text,count_per_doc,associated_es, list_gs,pg,lang): - global i - if not text: - count_per_doc[id_doc] = {} - associated_es[id_doc] = {} - g = nx.MultiDiGraph() - list_gs.append(g) - - else: - t = filter_nonprintable(text) - # try: - str, count, se_identified = pipeline[lang].build(t, None, **vars(args)) - list_gs.append(str.graph) - # Save Metadata - count_per_doc[id_doc] = count - associated_es[id_doc] = se_identified - - - # Save Graph structure - nx.write_gexf(list_gs[-1], args.graphs_output_dir + "/{0}.gexf".format(id_doc)) - i+=1 - pg.update(i) - - -logging.info("Extracting Toponyms and Building STR...") -queue=[] -with ThreadPoolExecutor(max_workers=4) as executor: - with ProgressBar(max_value=len(texts_),widgets=[' [', Timer(), '] ',Bar(),'(', Counter(),')','(', ETA(), ')']) as pg: - pg.start() - for lang in data: - for id_doc in data[lang]: - future = executor.submit(workSTR,id_doc,texts_[id_doc],count_per_doc,associated_es, list_gs,pg,lang) - - -# Save Metadata -open(os.path.join(args.graphs_output_dir,args.metadata_output_fn),'w').write(json.dumps([associated_es,count_per_doc],indent=4)) - - -print("--- %s seconds ---" % (time.time() - start)) \ No newline at end of file -- GitLab