Skip to main content

Exponential Random Graph Models in Python

Project description

pyERGM - A Python implementation for ERGM's

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 $\mathbf{Y}$, which is simply a random graph on $n$ nodes. The probability of observing a specific graph $y\in \lbrace 0,1 \rbrace ^{n \times n}$ is given by -

$$\Pr(\mathbf{Y}=y | \theta) = \frac{\exp(\theta^Tg(y))}{\sum_{z\in\mathcal{Y}} \exp(\theta^Tg(z))}$$

where $g(y)$ is a vector of statistics that describe the graph $y$, and $\theta \in \mathbb{R}^q$ is a vector of model parameters. Each graph is represented by a binary adjacency matrix, where $y_{ij}=1$ if there is an edge between nodes $i$ and $j$ (and $y_{ji}=1$ in the undirected case).

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

Installation

https://pypi.org/project/pyERGM/

Getting started

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.ergm import ERGM
from pyERGM.metrics import *
from pyERGM.datasets import sampson_matrix


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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyergm-0.2.9.tar.gz (90.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyergm-0.2.9-py3-none-any.whl (59.2 kB view details)

Uploaded Python 3

File details

Details for the file pyergm-0.2.9.tar.gz.

File metadata

  • Download URL: pyergm-0.2.9.tar.gz
  • Upload date:
  • Size: 90.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for pyergm-0.2.9.tar.gz
Algorithm Hash digest
SHA256 f7a82f747034bf20f7a9bd7db5d1d4a6d3ed8eb3d9f5056ac78cf452ff97f874
MD5 6d9cba5e0e889082228841f54c68db22
BLAKE2b-256 d45c606a3112d24d2a615f23cb6322d4d48b6e1431aa2134a7a369b60cdf4dbb

See more details on using hashes here.

File details

Details for the file pyergm-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: pyergm-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 59.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for pyergm-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 78b3ec074ae156531a1f3cfbe6d8b4e816bfbeba4b6583f51067ae559cdc38b8
MD5 2090fc89919fdd31d3500179afbac890
BLAKE2b-256 cf58ef988865e8c7493571c97e11dcf79fc7326fb90a26c76191e7cb8bd1c3b2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page