Package: graphkit-learn
graphkit-learnA Python package for graph kernels, graph edit distances and graph pre-image problem.Requirementspython>=3.6numpy>=1.16.2scipy>=1.1.0matplotlib>=3.1.0networkx>=2.2scikit-learn>=0.20.0tabulate>=0.8.2tqdm>=4.26.0control>=0.8.2 (for generalized random walk kernels only)slycot>=0.3.3 (for generalized random walk kernels only, which requires a fortran compiler (e.g.,gfortran) and BLAS/LAPACK (e.g.liblapack-dev))How to use?Install the libraryInstall stable version from PyPI (may not be up-to-date):$ pip install graphkit-learnInstall latest version from GitHub:$ git clone https://github.com/jajupmochi/graphkit-learn.git
$ cd graphkit-learn/
$ python setup.py installRun the testA series oftestscan be run to check if the library works correctly:$ pip install -U pip pytest codecov coverage pytest-cov
$ pytest -v --cov-config=.coveragerc --cov-report term --cov=gklearn gklearn/tests/Check examplesA series of demos of using the library can be found onGoogle Colaband in theexamplefolder.Other demosChecknotebooksdirectory for more demos:notebooksdirectory includes test codes of graph kernels based on linear patterns;notebooks/testsdirectory includes codes that test some libraries and functions;notebooks/utilsdirectory includes some useful tools, such as a Gram matrix checker and a function to get properties of datasets;notebooks/elsedirectory includes other codes that we used for experiments.DocumentationThe docs of the library can be foundhere.Main contents1 List of graph kernelsBased on walksThe common walk kernel[1]ExponentialGeometricThe marginalized kernelWith tottering [2]Without tottering [7]The generalized random walk kernel[3]Sylvester equationConjugate gradientFixed-point iterationsSpectral decompositionBased on pathsThe shortest path kernel[4]The structural shortest path kernel[5]The path kernel up to length h[6]The Tanimoto kernelThe MinMax kernelNon-linear kernelsThe treelet kernel[10]Weisfeiler-Lehman kernel[11]SubtreeA demo of computing graph kernels can be found onGoogle Colaband in theexamplesfolder.2 Graph Edit Distances3 Graph preimage methodsA demo of generating graph preimages can be found onGoogle Colaband in theexamplesfolder.4 Interface toGEDLIBGEDLIBis an easily extensible C++ library for (suboptimally) computing the graph edit distance between attributed graphs.A Python interfaceforGEDLIBis integrated in this library, based ongedlibpylibrary.5 Computation optimization methodsPython’smultiprocessing.Poolmodule is applied to performparallelizationon the computations of all kernels as well as the model selection.The Fast Computation of Shortest Path Kernel (FCSP) method[8] is implemented inthe random walk kernel,the shortest path kernel, as well asthe structural shortest path kernelwhere FCSP is applied on both vertex and edge kernels.The trie data structure[9] is employed inthe path kernel up to length hto store paths in graphs.IssuesThis library usesmultiprocessing.Pool.imap_unorderedfunction to do the parallelization, which may not be able to run correctly under Windows system. For now, Windows users may need to comment the parallel codes and uncomment the codes below them which run serially. We will consider adding a parameter to control serial or parallel computations as needed.Some modules (such asNumpy,Scipy,sklearn) applyOpenBLASto perform parallel computation by default, which causes conflicts with other parallelization modules such asmultiprossing.Pool, highly increasing the computing time. By setting its thread to 1,OpenBLASis forced to use a single thread/CPU, thus avoids the conflicts. For now, this procedure has to be done manually. Under Linux, type this command in terminal before running the code:$ export OPENBLAS_NUM_THREADS=1Or addexport OPENBLAS_NUM_THREADS=1at the end of your~/.bashrcfile, then run$ source ~/.bashrcto make this effective permanently.ResultsCheck this paper for detailed description of graph kernels and experimental results:Linlin Jia, Benoit Gaüzère, and Paul Honeine. Graph Kernels Based on Linear Patterns: Theoretical and Experimental Comparisons. working paper or preprint, March 2019. URLhttps://hal-normandie-univ.archives-ouvertes.fr/hal-02053946.A comparison of performances of graph kernels on benchmark datasets can be foundhere.How to contributeFork the library and open a pull request! Make your own contribute to the community!AuthorsLinlin Jia, LITIS, INSA Rouen NormandieBenoit Gaüzère, LITIS, INSA Rouen NormandiePaul Honeine, LITIS, Université de Rouen NormandieCitationIf you have usedgraphkit-learnin your publication, please cite the the following paper:@article{JIA2021,
	title = "graphkit-learn: A Python Library for Graph Kernels Based on Linear Patterns",
	journal = "Pattern Recognition Letters",
	year = "2021",
	issn = "0167-8655",
	doi = "https://doi.org/10.1016/j.patrec.2021.01.003",
	url = "http://www.sciencedirect.com/science/article/pii/S0167865521000131",
	author = "Linlin Jia and Benoit Gaüzère and Paul Honeine",
	keywords = "Graph Kernels, Linear Patterns, Python Implementation",
	abstract = "This paper presents graphkit-learn, the first Python library for efficient computation of graph kernels based on linear patterns, able to address various types of graphs. Graph kernels based on linear patterns are thoroughly implemented, each with specific computing methods, as well as two well-known graph kernels based on non-linear patterns for comparative analysis. Since computational complexity is an Achilles’ heel of graph kernels, we provide several strategies to address this critical issue, including parallelization, the trie data structure, and the FCSP method that we extend to other kernels and edge comparison. All proposed strategies save orders of magnitudes of computing time and memory usage. Moreover, all the graph kernels can be simply computed with a single Python statement, thus are appealing to researchers and practitioners. For the convenience of use, an advanced model selection procedure is provided for both regression and classification problems. Experiments on synthesized datasets and 11 real-world benchmark datasets show the relevance of the proposed library."
}AcknowledgmentsThis research was supported by CSC (China Scholarship Council) and the French national research agency (ANR) under the grant APi (ANR-18-CE23-0014). The authors would like to thank the CRIANN (Le Centre Régional Informatique et d’Applications Numériques de Normandie) for providing computational resources.References[1] Thomas Gärtner, Peter Flach, and Stefan Wrobel. On graph kernels: Hardness results and efficient alternatives. Learning Theory and Kernel Machines, pages 129–143, 2003.[2] H. Kashima, K. Tsuda, and A. Inokuchi. Marginalized kernels between labeled graphs. In Proceedings of the 20th International Conference on Machine Learning, Washington, DC, United States, 2003.[3] Vishwanathan, S.V.N., Schraudolph, N.N., Kondor, R., Borgwardt, K.M., 2010. Graph kernels. Journal of Machine Learning Research 11, 1201–1242.[4] K. M. Borgwardt and H.-P. Kriegel. Shortest-path kernels on graphs. In Proceedings of the International Conference on Data Mining, pages 74-81, 2005.[5] Liva Ralaivola, Sanjay J Swamidass, Hiroto Saigo, and Pierre Baldi. Graph kernels for chemical informatics. Neural networks, 18(8):1093–1110, 2005.[6] Suard F, Rakotomamonjy A, Bensrhair A. Kernel on Bag of Paths For Measuring Similarity of Shapes. InESANN 2007 Apr 25 (pp. 355-360).[7] Mahé, P., Ueda, N., Akutsu, T., Perret, J.L., Vert, J.P., 2004. Extensions of marginalized graph kernels, in: Proc. the twenty-first international conference on Machine learning, ACM. p. 70.[8] Lifan Xu, Wei Wang, M Alvarez, John Cavazos, and Dongping Zhang. Parallelization of shortest path graph kernels on multi-core cpus and gpus. Proceedings of the Programmability Issues for Heterogeneous Multicores (MultiProg), Vienna, Austria, 2014.[9] Edward Fredkin. Trie memory. Communications of the ACM, 3(9):490–499, 1960.[10] Gaüzere, B., Brun, L., Villemin, D., 2012. Two new graphs kernels in chemoinformatics. Pattern Recognition Letters 33, 2038–2047.[11] Shervashidze, N., Schweitzer, P., Leeuwen, E.J.v., Mehlhorn, K., Borgwardt, K.M., 2011. Weisfeiler-lehman graph kernels. Journal of Machine Learning Research 12, 2539–2561.