A fast network diffusion library
Project description
CyNetDiff
- Documentation: https://eliotwrobson.github.io/CyNetDiff/
Network diffusion processes aim to model the spread of trends through social networks, represented using graphs. Experimental work with these models usually involves simulating these processes many times over large graphs, which can be computationally very expensive. To address this, CyNetDiff is a Cython module implementing the independent cascade and linear threshold models. Development has been focused on performance, while still giving an intuitive, high-level interface to assist in research tasks. To learn more about these specific models, read this.
Quick Start
Installation
pip install cynetdiff
Note: The installation includes a build step that requires having a C++ complier installed.
Basic Usage
We can run models over graphs we define, using pre-defined weighting schemes. Here is a simple example:
import random
import networkx as nx
from cynetdiff.utils import networkx_to_ic_model
# Randomly generate the graph
n = 1_000
p = 0.05
graph = nx.fast_gnp_random_graph(n, p)
# Randomly choose seed nodes
k = 10
nodes = list(graph.nodes)
seeds = random.sample(nodes, k)
# Set the activation probability uniformly and set seeds
model = networkx_to_ic_model(graph, activation_prob=0.2)
model.set_seeds(seeds)
# Run a single diffusion process until completion
model.advance_until_completion()
# Get the number of nodes activated
model.get_num_activated_nodes()
The output from the last line is the number of nodes activated in a single
simulation of the model. To get the average number of activated nodes
across n_sim = 1_000
simulations, we can replace the last line in the
above with the following:
n_sim = 1_000
total = 0.0
for _ in range(n_sim):
# Resetting the model doesn't change the initial seed set used.
model.reset_model()
model.advance_until_completion()
total += model.get_num_activated_nodes()
avg = total / n_sim
Advanced Usage
See the documentation.
Project Status
This project is still considered in an alpha stage of development. As such, the API could still change to facilitate easier community adoption.
All feedback is greatly appreciated!
Contributing
Contributions are always welcome! Take a look at the contributing guide.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cynetdiff-0.1.11-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6106163aab97a778867bb16e7b2427cc45c97c35e5d4b7ccdb1e211c32eb5797 |
|
MD5 | 86bc9e22b3be49e4b09eec45da75c1d2 |
|
BLAKE2b-256 | 9df0c2d3b8847579397111fa876731134b29220fe80fd48a3db50aca06bd3934 |