Skip to main content

A fast network diffusion library

Project description

CyNetDiff

PyPI version tests docs PyPI - Python Version Ruff Project Status: Active – The project has reached a stable, usable state and is being actively developed. License: MIT DOI SPEC 7 — Seeding pseudo-random number generation

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 book chapter or the preliminaries page in the documentation.

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.

Citation

If you use this code in your research, please use the following citation:

@article{DBLP:journals/pvldb/RobsonRU24,
  author       = {Eilot W. Robson and
                  Dhemath Reddy and
                  Abhishek Kumar Umrawal},
  title        = {CyNetDiff: {A} Python Library for Accelerated Implementation of Network
                  Diffusion Models},
  journal      = {Proc. {VLDB} Endow.},
  volume       = {17},
  number       = {12},
  pages        = {4409--4412},
  year         = {2024},
  url          = {https://www.vldb.org/pvldb/vol17/p4409-umrawal.pdf},
  timestamp    = {Thu, 19 Sep 2024 13:09:38 +0200},
  biburl       = {https://dblp.org/rec/journals/pvldb/RobsonRU24.bib},
  bibsource    = {dblp computer science bibliography, https://dblp.org}
}

Project Status

This project is still considered in a beta 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


Download files

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

Source Distribution

cynetdiff-0.1.16.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

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

cynetdiff-0.1.16-cp311-cp311-manylinux_2_31_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

File details

Details for the file cynetdiff-0.1.16.tar.gz.

File metadata

  • Download URL: cynetdiff-0.1.16.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.0 Linux/6.8.0-1017-azure

File hashes

Hashes for cynetdiff-0.1.16.tar.gz
Algorithm Hash digest
SHA256 a6bc08301cb62520b316f9e99b8afb78d58ce3173c8758148b31ff8c43344a5f
MD5 a5ecb8dd9efaf72318421d85cb1141d2
BLAKE2b-256 efabee78fbba6c3199184245f65a16fd706aa12709ed34492cd69ba8ec1364c1

See more details on using hashes here.

File details

Details for the file cynetdiff-0.1.16-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for cynetdiff-0.1.16-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 2ec77816c0174ffcc7b5c06ba4a8ef28ddd80e7fbeab156a0490c350725491d9
MD5 38a70cddae47367b06bbad68ae43b099
BLAKE2b-256 c1d32714a9281ec3e3be56c37ece53c52be20aa143b43f13195f97a37f3d7282

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