generative method on graphs via graph grammar
Project description
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...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file graphlearn-0.0.934.tar.gz
.
File metadata
- Download URL: graphlearn-0.0.934.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4d61dec148167df57e416e40779571d7261c6a0e26285829cd36abdf4067251 |
|
MD5 | b6cbb5e74d138376cde9b23c2e5d8908 |
|
BLAKE2b-256 | 6cf1384b8f5d9126fca52e8ce29d6addee2c00b3212dcb8e3baaa946bdcfede5 |