An exponential random graphs model (ERGM) is a statistical model that describes a distribution of random graphs. This package provides a simple and easy way to fit and sample from ERGMs.
An ERGM defines a random variable
where
Fitting a model for even moderately large graphs can be a computationally challenging task. pyERGM keeps this in mind and is implemented to be efficient and scalable by using numpy
and Numba
, as well as providing an interface for fitting models on a distributed computing environment.
View the full documentation here
https://pypi.org/project/pyERGM/
Fitting an ERGM model requires a graph and a set of statistics that describe the graph. The model is then fit by maximizing the likelihood of the observed graph under the model.
The following example demonstrates how to fit a simple ERGM model from Sampson's monastery data.
from pyERGM import ERGM
from pyERGM.metrics import *
from pyERGM.datasets import load_sampson
sampson_matrix = load_sampson()
num_nodes = sampson_matrix.shape[0]
is_directed = True
metrics = [NumberOfEdgesDirected(), TotalReciprocity()]
model = ERGM(num_nodes, metrics, is_directed=is_directed)
model.fit(sampson_matrix)
The above example fits a model from the Sampson's monastery data using the number of edges and total reciprocity as statistics. The graph is represented as an adjacency matrix, but pyERGM also supports graphs represented as networkx
objects.