Network Dismanling is a Network Dismantling Task Aimedextension library
Project description
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.
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
File details
Details for the file network_dismantling-0.0.1.tar.gz
.
File metadata
- Download URL: network_dismantling-0.0.1.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.6-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f74d6f7e0d58c399ddf481a3398304736590a9d3bf9ae9ed480f802a08fa36c |
|
MD5 | 71d7f8a670b31bdc7029d3b29df8c8b3 |
|
BLAKE2b-256 | 87bd82a82d1708864da9c61a95ffa4d4f50bde4b5d46ba10eb46e3b07d03946a |
File details
Details for the file network_dismantling-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: network_dismantling-0.0.1-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.6-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d23900ecf6e5960af114a3ca8377dfb6ccc10738fa952cf5416c68072360d78a |
|
MD5 | 6c7d6fd261ef4555b6c895272774e7b3 |
|
BLAKE2b-256 | c940ff0f21714a5d992ae48931a1a82ad1b839b76f9e5e51ba8d0c3ce08a76ab |