Skip to main content

network-dismantling

network-dismantling is a library for network dismantling, which refers to the process of strategically removing nodes from a network to disrupt its functionality. This repository provides implementations of various network dismantling algorithms, leveraging the power of PyTorch for efficient computation and flexibility.

Installation

To install the dependencies, easily install from PyPI:

pip install network-dismantling

Make sure you have PyTorch installed if you want to run a neural-network model. You can install PyTorch from here.

Or directly using conda:

conda install network-dismantling

Alternatively, you can clone the repository and install it locally:

git clone https://github.com/njublockchain/network-dismantling.git
cd network-dismantling
pip install -e .

Usage

# Create a test graph
G = nx.karate_club_graph()

# Initialize CoreHD strategies
corehd_strategy = CoreHDDismantling()

# Create NetworkDismantlers with different strategies
corehd_dismantler = NetworkDismantler(corehd_strategy)

# Dismantle the graph using both strategies
num_nodes_to_remove = int(G.number_of_nodes() * 0.1)  # Remove 10% of nodes

dismantled_G_corehd, removed_nodes_corehd = corehd_dismantler.dismantle(G, num_nodes_to_remove)

print(f"Original graph: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges")
print(f"CoreHD dismantled graph: {dismantled_G_corehd.number_of_nodes()} nodes, {dismantled_G_corehd.number_of_edges()} edges")
print(f"CoreHD removed nodes: {removed_nodes_corehd}")
G = nx.karate_club_graph()

# Initialize CoreGDM strategy
coregdm_strategy = CoreGDMDismantling()

# Create NetworkDismantler with CoreGDM strategy
coregdm_dismantler = NetworkDismantler(coregdm_strategy)

# Dismantle the graph using CoreGDM
num_nodes_to_remove = int(G.number_of_nodes() * 0.1)  # Remove 10% of nodes

dismantled_G_coregdm, removed_nodes_coregdm = coregdm_dismantler.dismantle(G, num_nodes_to_remove)

print(f"Original graph: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges")
print(f"CoreGDM dismantled graph: {dismantled_G_coregdm.number_of_nodes()} nodes, {dismantled_G_coregdm.number_of_edges()} edges")
print(f"CoreGDM removed nodes: {removed_nodes_coregdm}")
    # Create a test graph
    G = nx.karate_club_graph()
    
    # Initialize different dismantling strategies
    dismantling_strategies = [
        CollectiveInfluenceDismantling(l=2),
        ExplosiveImmunizationDismantling(q=0.1, num_iterations=10),
        CoreGDMDismantling(),
        GNDDismantling(),
        CoreHDDismantling()
    ]
    
    # Initialize evaluation metrics
    metrics = [
        LCCSizeMetric(),
        NumComponentsMetric(),
        AvgPathLengthMetric(),
        GlobalEfficiencyMetric(),
        AvgClusteringMetric()
    ]
    
    # Choose evaluation strategy
    evaluation_strategy = RelativeChangeStrategy()
    
    # Create evaluator
    evaluator = DismantlingEvaluator(metrics, evaluation_strategy)
    
    # Compare strategies
    num_nodes_to_remove = int(G.number_of_nodes() * 0.1)  # Remove 10% of nodes
    comparison_results = DismantlingEvaluator.compare_strategies(G, dismantling_strategies, num_nodes_to_remove, evaluator)
    
    # Print detailed results
    for strategy_name, metrics in comparison_results.items():
        print(f"\n{strategy_name}:")
        for metric, value in metrics.items():
            print(f"  {metric}: {value:.4f}")

Documentation

The full documentation is available at network-dismantling.readthedocs.io.

Contributing

We welcome contributions to the network-dismantling library! If you have an idea for an improvement or a new feature, feel free to open an issue or submit a pull request. Please make sure to follow our contributing guidelines.

Metadata

Release files for network-dismantling 0.0.1

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

Source distribution (sdist)

Source distribution for network-dismantling 0.0.1
File Size Uploaded
network_dismantling-0.0.1.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for network-dismantling 0.0.1
File Interpreter ABI Platform
network_dismantling-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.5 kB

Release files / network_dismantling-0.0.1.tar.gz

Download URL network_dismantling-0.0.1.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0f74d6f7e0d58c399ddf481a3398304736590a9d3bf9ae9ed480f802a08fa36c
BLAKE2b-256 checksum
How to use checksums
87bd82a82d1708864da9c61a95ffa4d4f50bde4b5d46ba10eb46e3b07d03946a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Linux/6.9.6-arch1-1

Release files / network_dismantling-0.0.1-py3-none-any.whl

Download URL network_dismantling-0.0.1-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d23900ecf6e5960af114a3ca8377dfb6ccc10738fa952cf5416c68072360d78a
BLAKE2b-256 checksum
How to use checksums
c940ff0f21714a5d992ae48931a1a82ad1b839b76f9e5e51ba8d0c3ce08a76ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Linux/6.9.6-arch1-1

Release history Release notifications | RSS feed

This release

0.0.1 This release

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