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

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.

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


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.14.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

cynetdiff-0.1.14-cp311-cp311-manylinux_2_31_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.31+ x86-64

File details

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

File metadata

  • Download URL: cynetdiff-0.1.14.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.0 Linux/6.5.0-1025-azure

File hashes

Hashes for cynetdiff-0.1.14.tar.gz
Algorithm Hash digest
SHA256 364ff1508f8902e07706f2c66b7e389887d5c36791246a36a0680bf789a6e125
MD5 bb0f61c1cf8806195eb73cb85434d72e
BLAKE2b-256 15ed38bad896089ad5af3fa4ea1c737c8bb0c815dedd3cdbf5d7dda94704510e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cynetdiff-0.1.14-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 12a20ad02ff19e7b67cf8b33029b0ca5d23e55f1aa959e474ba03bba6ab2b843
MD5 0fe21cd446a7351c33a16db9c1f3ad52
BLAKE2b-256 260eb7018cc8cf85889690f4092aeb0a0a198e3b114e24256f91ba7657b2d90f

See more details on using hashes here.

Supported by

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