From fbb020c39964fc644c20881218d0b9d6422bbe49 Mon Sep 17 00:00:00 2001 From: Fize Jacques <jacques.fize@cirad.fr> Date: Tue, 10 Jul 2018 17:30:59 +0200 Subject: [PATCH] Debug WLK and GED Change README --- README.md | 17 +++++++---------- gmatch4py/ged/graph_edit_dist.pyx | 5 +++-- gmatch4py/kernels/weisfeiler_lehman.pyx | 16 +++++++++++----- setup.py | 12 +++++------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index b8cb80f..acf6750 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,14 @@ Gmatch4py is a library dedicated to graph matching. Graph structure are stored i ## Installation -First, compile the library by running this command: +To install `GMatch4py`, run the following commands: ``` -$ python3 setup.py build_ext +$ git clone https://github.com/Jacobe2169/GMatch4py.git +$ cd GMatch4py +$ python3 setup.py install ``` -Then, install the compiled module with: - -``` -$ pip3 install . -``` ## Get Started @@ -75,8 +72,8 @@ each code is associated with a reference to the original.** * Debug algorithms with --> (*debug needed*) * Improve code structure and performance - * Simplify `setup.py` + * Simplify `setup.py` :heavy_check_mark: * Some algorithms are distance and others are similarity measure. Must change the compare methods so it can adapt to the user need. For example, maybe the user want to deal with - graph similarity rather than distance between graph. - * Write the documentation \ No newline at end of file + graph similarity rather than distance between graph.:heavy_check_mark: + * Write the documentation :see_no_evil: \ No newline at end of file diff --git a/gmatch4py/ged/graph_edit_dist.pyx b/gmatch4py/ged/graph_edit_dist.pyx index db351d4..f2a39c3 100644 --- a/gmatch4py/ged/graph_edit_dist.pyx +++ b/gmatch4py/ged/graph_edit_dist.pyx @@ -26,9 +26,10 @@ cdef class GraphEditDistance(AbstractGraphEditDistance): R2 = nx.create_empty_copy(H) R2.add_edges_from(H.edges(node2,data=True)) - return abs(R2.number_of_edges()-intersection(R,R2).number_of_edges()) + diff=abs(R2.number_of_edges()-intersection(R,R2).number_of_edges()) + return (diff*self.edge_ins)+(diff*self.edge_del) else: - return self.node_ins+self.node_del + return 0. cdef double delete_cost(self, int i, int j, nodesG, G): if i == j: diff --git a/gmatch4py/kernels/weisfeiler_lehman.pyx b/gmatch4py/kernels/weisfeiler_lehman.pyx index dd0a1d3..95fb085 100644 --- a/gmatch4py/kernels/weisfeiler_lehman.pyx +++ b/gmatch4py/kernels/weisfeiler_lehman.pyx @@ -17,12 +17,18 @@ import copy import networkx as nx import numpy as np cimport numpy as np +from ..base cimport Base +cdef class WeisfeleirLehmanKernel(Base): -class WeisfeleirLehmanKernel(object): - __type__ = "sim" - @staticmethod - def compare(graph_list,selected,h=2): + cdef int h + + def __init__(self,h=2): + Base.__init__(self,0,True) + self.h=h + + + cpdef np.ndarray compare(self,list graph_list, list selected): """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 @@ -103,7 +109,7 @@ class WeisfeleirLehmanKernel(object): new_labels = copy.deepcopy(labels) # Can't work without it !!! - while it < h: + while it < self.h: # create an empty lookup table label_lookup = {} label_counter = 0 diff --git a/setup.py b/setup.py index a9d67f2..634b12b 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,8 @@ except: print("You don't seem to have Cython installed. Please get a") print("copy from www.cython.org and install it") sys.exit(1) + + def scandir(dir, files=[]): for file in os.listdir(dir): path = os.path.join(dir, file) @@ -18,7 +20,6 @@ def scandir(dir, files=[]): scandir(path, files) return files - # generate an Extension object from its dotted name def makeExtension(extName): extPath = extName.replace(".", os.path.sep)+".pyx" @@ -34,12 +35,9 @@ extNames = scandir("gmatch4py") extensions = cythonize([makeExtension(name) for name in extNames]) setup( - name="Gmatch4py", + name="GMatch4py", description="A module for graph matching", - packages=["gmatch4py"], - #ext_modules=cythonize([ - # Extension("*", ["gmatch4py/*.pyx"],include_dirs=[np.get_include()]) - #]), + packages=["gmatch4py","gmatch4py.ged","gmatch4py.kernels"], ext_modules=extensions, cmdclass={'build_ext': build_ext}, setup_requires=["numpy","networkx"], @@ -47,7 +45,7 @@ setup( version="0.1" ) #Clean cpp and compiled file -f=False +f=True if f: if os.path.exists("build"): shutil.rmtree("build") -- GitLab