recombine network graphs


License
MIT-feh
Install
pip install graphlearn==0.0.932

Documentation

DOI

GraphLearn

Learn how to construct graphs given representative examples.

Discriminative systems that can deal with graphs in input are known, however, generative or constructive approaches that can sample graphs from empirical distributions are less developed. This is a Metropolis–Hastings approach that uses a novel type of graph grammar to efficiently learn proposal distributions in a data driven fashion.

References

Costa, Fabrizio. "Learning an efficient constructive sampler for graphs." Artificial Intelligence (2016). link

Python3

This demonstrates the grammar which is the heart of graphlearn. Sampling as in the py2 example is demonstrated in graphlearn/sample.py.

from graphlearn.local_substitution_graph_grammar import LocalSubstitutionGraphGrammar
from graphlearn.util import util
import structout as so

# get graphs
gr = util.get_cyclegraphs()

#  induce a grammar, pick a graph, and apply all possible substitutions
mylsgg = LocalSubstitutionGraphGrammar()
mylsgg.fit(gr)
graphs =  list(mylsgg.neighbors(gr[0]))
so.gprint(graphs)

''

Python2

# set up graph source

from eden.io.gspan import gspan_to_eden
from itertools import islice
def get_graphs(dataset_fname='../../toolsdata/bursi.pos.gspan', size=100):
    return  islice(gspan_to_eden(dataset_fname),size)
    
# sample some graphs

from graphlearn.graphlearn import  Sampler
sampler=Sampler(n_steps=50)
samples = sampler.fit_transform(get_graphs())

# draw result

from graphlearn.utils import draw
for i in range(5):
        draw.graphlearn(samples.next())

''

Install (Py2)

We only maintain the python3 version at this point. an outdated but detailed installation guide for the python2 version is available here.

Examples (py2)

See here for more examples. Examples still use python2...