Commit fbb020c3 authored by Fize Jacques's avatar Fize Jacques

Debug WLK and GED

Change README
parent 01d33886
...@@ -11,17 +11,14 @@ Gmatch4py is a library dedicated to graph matching. Graph structure are stored i ...@@ -11,17 +11,14 @@ Gmatch4py is a library dedicated to graph matching. Graph structure are stored i
## Installation ## 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 ## Get Started
...@@ -75,8 +72,8 @@ each code is associated with a reference to the original.** ...@@ -75,8 +72,8 @@ each code is associated with a reference to the original.**
* Debug algorithms with --> (*debug needed*) * Debug algorithms with --> (*debug needed*)
* Improve code structure and performance * 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 * 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 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. graph similarity rather than distance between graph.:heavy_check_mark:
* Write the documentation * Write the documentation :see_no_evil:
\ No newline at end of file \ No newline at end of file
...@@ -26,9 +26,10 @@ cdef class GraphEditDistance(AbstractGraphEditDistance): ...@@ -26,9 +26,10 @@ cdef class GraphEditDistance(AbstractGraphEditDistance):
R2 = nx.create_empty_copy(H) R2 = nx.create_empty_copy(H)
R2.add_edges_from(H.edges(node2,data=True)) 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: else:
return self.node_ins+self.node_del return 0.
cdef double delete_cost(self, int i, int j, nodesG, G): cdef double delete_cost(self, int i, int j, nodesG, G):
if i == j: if i == j:
......
...@@ -17,12 +17,18 @@ import copy ...@@ -17,12 +17,18 @@ import copy
import networkx as nx import networkx as nx
import numpy as np import numpy as np
cimport numpy as np cimport numpy as np
from ..base cimport Base
cdef class WeisfeleirLehmanKernel(Base):
class WeisfeleirLehmanKernel(object): cdef int h
__type__ = "sim"
@staticmethod def __init__(self,h=2):
def compare(graph_list,selected,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. """Compute the all-pairs kernel values for a list of graphs.
This function can be used to directly compute the kernel This function can be used to directly compute the kernel
matrix for a list of graphs. The direct computation of the matrix for a list of graphs. The direct computation of the
...@@ -103,7 +109,7 @@ class WeisfeleirLehmanKernel(object): ...@@ -103,7 +109,7 @@ class WeisfeleirLehmanKernel(object):
new_labels = copy.deepcopy(labels) # Can't work without it !!! new_labels = copy.deepcopy(labels) # Can't work without it !!!
while it < h: while it < self.h:
# create an empty lookup table # create an empty lookup table
label_lookup = {} label_lookup = {}
label_counter = 0 label_counter = 0
......
...@@ -9,6 +9,8 @@ except: ...@@ -9,6 +9,8 @@ except:
print("You don't seem to have Cython installed. Please get a") print("You don't seem to have Cython installed. Please get a")
print("copy from www.cython.org and install it") print("copy from www.cython.org and install it")
sys.exit(1) sys.exit(1)
def scandir(dir, files=[]): def scandir(dir, files=[]):
for file in os.listdir(dir): for file in os.listdir(dir):
path = os.path.join(dir, file) path = os.path.join(dir, file)
...@@ -18,7 +20,6 @@ def scandir(dir, files=[]): ...@@ -18,7 +20,6 @@ def scandir(dir, files=[]):
scandir(path, files) scandir(path, files)
return files return files
# generate an Extension object from its dotted name # generate an Extension object from its dotted name
def makeExtension(extName): def makeExtension(extName):
extPath = extName.replace(".", os.path.sep)+".pyx" extPath = extName.replace(".", os.path.sep)+".pyx"
...@@ -34,12 +35,9 @@ extNames = scandir("gmatch4py") ...@@ -34,12 +35,9 @@ extNames = scandir("gmatch4py")
extensions = cythonize([makeExtension(name) for name in extNames]) extensions = cythonize([makeExtension(name) for name in extNames])
setup( setup(
name="Gmatch4py", name="GMatch4py",
description="A module for graph matching", description="A module for graph matching",
packages=["gmatch4py"], packages=["gmatch4py","gmatch4py.ged","gmatch4py.kernels"],
#ext_modules=cythonize([
# Extension("*", ["gmatch4py/*.pyx"],include_dirs=[np.get_include()])
#]),
ext_modules=extensions, ext_modules=extensions,
cmdclass={'build_ext': build_ext}, cmdclass={'build_ext': build_ext},
setup_requires=["numpy","networkx"], setup_requires=["numpy","networkx"],
...@@ -47,7 +45,7 @@ setup( ...@@ -47,7 +45,7 @@ setup(
version="0.1" version="0.1"
) )
#Clean cpp and compiled file #Clean cpp and compiled file
f=False f=True
if f: if f:
if os.path.exists("build"): if os.path.exists("build"):
shutil.rmtree("build") shutil.rmtree("build")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment