jacquesfize / GMatch4py

A graph matching library for Python
MIT License
192 stars 41 forks source link

Build Status

GMatch4py a graph matching library for Python

GMatch4py is a library dedicated to graph matching. Graph structure are stored in NetworkX graph objects. GMatch4py algorithms were implemented with Cython to enhance performance.

Requirements

Installation

To install GMatch4py, run the following commands:

git clone https://github.com/Jacobe2169/GMatch4py.git
cd GMatch4py
(sudo) pip(3) install .

Get Started

Graph input format

In GMatch4py, algorithms manipulate networkx.Graph, a complete graph model that comes with a large spectrum of parser to load your graph from various inputs : *.graphml,*.gexf,.. (check here to see all the format accepted)

Use GMatch4py

If you want to use algorithms like graph edit distances, here is an example:

# Gmatch4py use networkx graph 
import networkx as nx 
# import the GED using the munkres algorithm
import gmatch4py as gm

In this example, we use generated graphs using networkx helpers:

g1=nx.complete_bipartite_graph(5,4) 
g2=nx.complete_bipartite_graph(6,4)

All graph matching algorithms in Gmatch4py work this way:

ged=gm.GraphEditDistance(1,1,1,1) # all edit costs are equal to 1
result=ged.compare([g1,g2],None) 
print(result)

The output is a similarity/distance matrix :

array([[0., 14.],
       [10., 0.]])

This output result is "raw", if you wish to have normalized results in terms of distance (or similarity) you can use :

ged.similarity(result)
# or 
ged.distance(result)

Exploit nodes and edges attributes

In this latest version, we add the possibility to exploit graph attributes ! To do so, the base.Base is extended with the set_attr_graph_used(node_attr,edge_attr) method.

import networkx as nx 
import gmatch4py as gm
ged = gm.GraphEditDistance(1,1,1,1)
ged.set_attr_graph_used("theme","color") # Edge colors and node themes attributes will be used.

List of algorithms

Publications associated

Author(s)

Jacques Fize, jacques[dot]fize[at]cirad[dot]fr

Some algorithms from other projects were integrated to Gmatch4py. Be assured that each code is associated with a reference to the original.

CHANGELOG

18.06.2022

7.05.2019

12.03.2019

05.03.2019

25.02.2019

TODO List