gmm.py
Author: Drew Conway Email: drew.conway@nyu.edu
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
T : model termination rule, function, optional at initialization
R : model growth rule, function, optional at initialization
|
---|
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
Simple function to test if object is a gmm
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
Applies the termination rule to the current base graph
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.
Reverts base graph to initial structure
Set new base graph for gmm, but does not alter original copy
Set growth function
Set the termination rule