Graph Motif Model (gmm)

gmm.py

Purpose: Classes used to generate networks from the graph motif model proposed
in paper entitled, “Graph Motif Models.” This method is an alternate process for generating network structure from observed structure.

Author: Drew Conway Email: drew.conway@nyu.edu

class gmm.gmm.gmm(G, T=None, R=None)

This is the base class used to simulate networks with graph motif models (GMM). The class inherits graph structure from NetworkX (http://networkx.lanl.gov/), a Python library for the manipulation of graph data. This class contains only base data necessary calls to to manipulate gmm.

Algorithms to simulate network structre from this object are contained in gmm_simulate.py.

Parameters :

G : base graph, NetworkX Graph or DiGraph object, required at initialization

The base graph must be a NetworkX Graph or DiGraph object with more than a singleedge. It is used as the initial structure for the GMM, and is the only parameter required to initialze a gmm object.

NOTE: Nodes in base graph are not required to be integers, but if the are not they are converted to integers, and the original labels are stored as a dictionary by nx.convert_nodel_labels_to_integers

T : model termination rule, function, optional at initialization

The rule by which the model will terminate. Must be a function that can operate on a NetworkX Graph or DiGraph object, and takes a single graph object as its only parameter.

R : model growth rule, function, optional at initialization

The rule by which new structure is added to the base graph. Must be a function that can operate on NetworkX Graph or DiGraph objects. Function must take exactly two arguments: 1) gmm base structure; 2) new structure to be added, as NetworkX Graph or DiGraph object. If second argument does not match first it will be coerced to match.

Notes

Any deviation in function design for T or R will cause modeling errors. Basic checks are performed by the gmm class at initialization, but design bugs in either F or T may go undetected despite successful gmm initialization.

Examples

# Create most basic GMM object with five node cycle graph as base.

>>> import gmm
>>> G=nx.cycle_graph(5)
>>> model=gmm(G)

# Using five node cycle graph, create gmm object with node ceiling # termination rule of 100 nodes

>>> def degree_ceiling(G):
   ...:     if G.number_of_nodes()>=100:
   ...:         return True
   ...:     else:
   ...:         return False
>>> model=gmm.gmm(G,degree_ceiling)

# Next, add a simple random growth rule

>>> def rand_add(base, new):
   ...:     from numpy.random import randint
   ...:     new=nx.convert_node_labels_to_integers(new,first_label=max(base.nodes())+1)
   ...:     new_base=nx.compose(base,new)
   ...:     base_connector=randint(base.number_of_nodes())
   ...:     new_connector=randint(min(new.nodes()),max(new.nodes()))
   ...:     new_base.add_edge(base_connector,new_connector)
   ...:     return new_base
>>> model.set_rule(rand_add)

# Run simualation with tau=4 and Poisson density for motifs

>>> gmm.algorithms.simulate(model,4)

# View results

>>> new_graph=model.get_base()
>>> print(nx.info(new_graph))

Methods

am_gmm()

Simple function to test if object is a gmm

apply_rule(new, set_result=False)

Applies the growth rule to the current base graph with some new structure. If set_result is True then set base graph to result of rule application

apply_termination()

Applies the termination rule to the current base graph

get_base(original=False)

Returns base graph of gmm

If original is True, return copy of base graph passed at initialization. If original is False, return current base graph.

revert_base()

Reverts base graph to initial structure

set_base(G)

Set new base graph for gmm, but does not alter original copy

set_rule(R)

Set growth function

set_termination(T)

Set the termination rule

Previous topic

Welcome to gmm’s documentation!

Next topic

algorithms

This Page