NDlib: a python library to model and analyze diffusion processes over complex networks

Giulio Rossetti, Letizia Milli, Salvatore Rinzivillo, Alina Sîrbu, Dino Pedreschi, Fosca Giannotti

TL;DR

NDlib is a multi-level Python ecosystem designed to simulate and analyze how information, viruses, or opinions spread across complex networks. By providing a core library, a RESTful simulation server, and a code-free web interface, it makes sophisticated diffusion modeling accessible to everyone from software engineers to social science students.

What Problem Does This Paper Address?

Social Network Analysis (SNA) has exploded in popularity, but the tools for modeling "diffusion" (the spreading of something through a network) remain fragmented. Researchers often face a dilemma: use powerful but complex programming libraries that require deep coding knowledge, or use graphical tools that are user-friendly but lack flexibility and advanced features like support for dynamic networks.

Furthermore, most existing tools struggle with "dynamics of networks"—scenarios where the network structure itself changes over time (e.g., people making new friends or losing contact). NDlib aims to consolidate these needs into a single, extensible framework that handles both static and evolving network topologies.

Methods

NDlib is built as a modular ecosystem consisting of three main components:

  1. NDlib Core: A Python library built on top of NetworkX. It uses a discrete-time agent-based approach where each node's state is updated in iterations based on predefined rules.
  2. NDlib-REST: A simulation server that allows users to run experiments remotely via API calls. This decouples the heavy lifting of simulation from the user's local machine.
  3. NDlib-Viz: A web-based visual platform that abstracts away the code, allowing non-technicians to configure and run experiments through a browser.

A standout feature is the integration of DyNetX (Dynamic NetworkX), a library developed by the authors to handle temporal networks. It allows models to run on "Snapshot Graphs" (a series of static network states) or "Temporal Networks" (where edges have specific birth and death timestamps).

Datasets

To evaluate performance, the authors used synthetic network models, specifically Barabási-Albert graphs, ranging from $10^3$ to $10^6$ nodes. These benchmarks were used to compare NDlib's execution time against other popular libraries like ComplexNetworkSim, Nepidemix, and R's EpiModel.

Key Insights and Ideas

  • Multi-Level Accessibility: By offering a REST API and a Web UI, the authors acknowledge that the "end-user" of SNA isn't always a programmer. This lowers the barrier to entry for students and social scientists.
  • Dynamic Topology Support: Unlike many of its competitors, NDlib treats the evolution of the network structure as a first-class citizen. This is crucial for modeling real-world scenarios like mobile phone virus spreading, where connections are fleeting.
  • Standardized Experiment Logic: The library uses a ModelConfig object to standardize how parameters (like infection probability $\beta$ or recovery rate $\gamma$) are passed to different models, making it easy to swap models (e.g., from SIR to SIS) without rewriting the entire simulation script.
  • Visual Comparative Analysis: The framework includes built-in facilities to compare different models or multiple runs of the same model.
Figure 1: Diffusion Trend and Prevalence plots for SIR and SI models.

Key Results

  • Performance: In quantitative benchmarks (Table 2), NDlib significantly outperformed other Python-based competitors. For a 1-million-node SIR simulation, NDlib finished in ~90 seconds, while ComplexNetworkSim and Nepidemix took over 500 seconds.
  • Comparison with R: NDlib's performance is comparable to R's EpiModel (which uses the C-based igraph library), despite NDlib being built on the pure-Python NetworkX.
  • Stability Analysis: The library handles multiple parallel executions to account for stochasticity in seed node selection. As shown in Figure 2, it can visualize inter-quartile ranges to help researchers understand model stability.
Figure 2: Multiple executions for the SIR model, with shaded areas identifying inter-quartile ranges.

Limitations and Future Work

The primary limitation is inherited from its foundation: NetworkX. Because NetworkX is written in pure Python, it hits a scalability ceiling compared to C++ optimized libraries like graph-tool or SNAP. While NDlib is fast for a Python library, it may struggle with massive-scale networks (hundreds of millions of nodes) that require high-performance computing clusters.

Future work includes expanding the library of available models (currently 11 epidemic and 5 opinion dynamics models) and deeper integration with the CIMPLEX H2020 project to enhance its visual simulation capabilities.

Summary updated

BibTeX
@article{rossetti2018ndlib,
  author = {Giulio Rossetti and Letizia Milli and Salvatore Rinzivillo and Alina Sîrbu and Dino Pedreschi and Fosca Giannotti},
  title = {{NDlib: a python library to model and analyze diffusion processes over complex networks}},
  journal = {Int. J. Data Sci. Anal.},
  year = {2018},
  url = {https://openreview.net/forum?id=Wxxs7TGtZy},
}
Figure