Skip to main content

networkx-robustness

DOI PyPI Version

A package for simulating network attacks on NetworkX graphs. The current supported attacks include random attacks and targeted attacks on nodes with the highest degree centrality, betweenness centrality, closeness centrality, and eigenvector centrality. Attack functions return the initial fraction of nodes in the giant component, a list of the fraction of nodes in the giant component after each node removal, and a list of the average path length in the giant component after each node removal.

The package also contains functions for calculating the Molloy-Reed criterion and the critical threshold for a network.

Citation

If you use this package, please cite the package as:

Tejas Santanam. (2023). tsantanam/networkx-robustness: v0.0.7 (v0.0.7). Zenodo. https://doi.org/10.5281/zenodo.7855211

Installation

The package can be installed using the pip package manager and requires Python 3.7 or greater. There is a package dependency with NetworkX.

pip install networkx-robustness

Example

An example of importing and using the package is shown below

import networkx as nx
from networkx_robustness import networkx_robustness

#Random NetworkX graph with 100 nodes
G = nx.gnp_random_graph(100, 0.5)

#Simulate a random attack on 20 nodes
initial, frac, apl = networkx_robustness.simulate_random_attack(G, attack_fraction=0.2)

Documentation

Simulating random attacks

initial, frac, apl = simulate_random_attack(G=None, attack_fraction=0.1, weight=None)
    """
    Simulate random attack on a network
    :param G: networkx graph
    :param attack_fraction: fraction of nodes to be attacked (default: 0.1)
    :param weight: weight of edges (default: None)
    :return: initial (float), frac (list), apl (list)
    """

Simulating degree centrality targeted attacks

initial, frac, apl = simulate_degree_attack(G=None, attack_fraction=0.1, weight=None)
    """
    Simulate degree attack on a network
    :param G: networkx graph
    :param attack_fraction: fraction of nodes to be attacked (default: 0.1)
    :param weight: weight of edges (default: None)
    :return: initial (float), frac (list), apl (list)
    """

Simulating betweenness centrality targeted attacks

initial, frac, apl = simulate_betweenness_attack(G=None, attack_fraction=0.1, weight=None, normalized=True, k=None, seed=None, endpoints=False)
    """
    Simulate betweenness attack on a network
    :param G: networkx graph
    :param attack_fraction: fraction of nodes to be attacked (default: 0.1)
    :param weight: weight of edges (default: None)
    :param normalized: if True, betweenness is normalized by 2/((n-1)(n-2)) for graphs, and 1/((n-1)(n-2)) for directed graphs where n is the number of nodes in G (default: True)
    :param k: use k node samples to estimate betweenness (default: None)
    :param seed: seed for random number generator (default: None)
    :param endpoints: If True include the endpoints in the shortest path counts (default: False)
    :return: initial (float), frac (list), apl (list)
    """

Simulating closeness centrality targeted attacks

initial, frac, apl = simulate_closeness_attack(G=None, attack_fraction=0.1, weight=None, u=None, wf_improved=True)
    """
    Simulate closeness attack on a network
    :param G: networkx graph
    :param attack_fraction: fraction of nodes to be attacked (default: 0.1)
    :param weight: weight of edges (default: None)
    :param u: node for which closeness is to be computed (default: None)
    :param wf_improved: use of the improved algorithm to scale by the fraction of nodes reachable (default: True)
    :return: initial (float), frac (list), apl (list)
    """

Simulating eigenvector centrality targeted attacks

initial, frac, apl = simulate_eigenvector_attack(G=None, attack_fraction=0.1, weight=None, tol=1e-06, max_iter=100, nstart=None)
    """
    Simulate eigenvector attack on a network
    :param G: networkx graph
    :param attack_fraction: fraction of nodes to be attacked (default: 0.1)
    :param weight: weight of edges (default: None)
    :param tol: tolerance for the power iteration method (default: 1e-06)
    :param max_iter: maximum number of iterations for the power iteration method (default: 100)
    :param nstart: initial vector for the power iteration method (default: None)
    :return: initial (float), frac (list), apl (list)
    """

Calculating the Molloy-Reed Criterion

molloy_reed = molloy_reed(G=None)
    """
    Compute the Molloy-Reed criterion for a network
    :param G: networkx graph
    :return: Molloy-Reed criterion
    """

Calculating the critical threshold

critical_threshold = critical_threshold(G=None)
    """
    Compute the critical threshold for a network
    :param G: networkx graph
    :return: critical threshold
    """

Release files for networkx-robustness 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for networkx-robustness 0.0.7
File Size Uploaded
networkx_robustness-0.0.7.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for networkx-robustness 0.0.7
File Interpreter ABI Platform
networkx_robustness-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / networkx_robustness-0.0.7.tar.gz

Download URL networkx_robustness-0.0.7.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2a513bf47be91cf0168170ab0853f6b67783785ce34b0a934417ecb32693aaa0
BLAKE2b-256 checksum
How to use checksums
99fa3b88ee526c742db133c6770886f0bff0e377085b4d6a3593b5fa64cbea16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release files / networkx_robustness-0.0.7-py3-none-any.whl

Download URL networkx_robustness-0.0.7-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc6dcff79cf6db0288b66b66ebc6e309f8f25ff5bc8ffad044bf91ba35e0ae71
BLAKE2b-256 checksum
How to use checksums
c713be25860f0a90d2b85a562cdab1d6806f8cb687019b1b0a13d2f3a89584a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page