Community detection is a fundamental problem in network science, where algorithms attempt to uncover groups of nodes, called communities, that share strong internal connections. While this task is widely applied in areas such as social networks, recommendation systems, and biological data analysis, it raises significant privacy concerns. Being identified as a member of a community can expose sensitive affiliations, such as political, religious, or professional memberships, which individuals may wish to keep private.
The Community Membership Hiding (CMH) problem addresses this issue by strategically modifying a network’s structure to obscure a target node’s membership in a specific community. Given a network and a community detection algorithm, the goal is to perturb the network in a way that prevents the target node from being recognized as part of its original community.
This repository is built on igraph, and provides an implementation of ∇-CMH, a gradient-based optimisation approach, a Deep Reinforcement Learning (DRL-agent) method, and several baselines, such as DICE, ROAM, Random-based, Degree-based, and Centrality-based. It supports multiple real-world network datasets and different community detection algorithms.
Let
To achieve this, we define a perturbation function
subject to a budget constraint on the number of modifications
The effectiveness of the hiding process is measured using a similarity function
where
Make sure to have conda installed:
conda create --name graph-cmh python=3.9
conda activate graph-cmh Then, install the requirements:
pip install -r requirements.txt If you have a GPU, run (according to CUDA version):
pip install torch-cluster -f https://data.pyg.org/whl/torch-2.6.0+cu124.html If you want to run on CPU:
pip install torch-cluster -f https://data.pyg.org/whl/torch-2.6.0+cpu.html - Run the CMH-experiment:
python main.py where the hyperparameters of the experiment, i.e.
-
dataset :
[KAR, WORDS, VOTE, POW, FB_75, COND_MAT] -
detection algorithm :
[GRE, LOUV, LEID, INF, LAB, WALK, SCD, LOC, DGC] -
hiding method :
[NABLA, DRL, DICE, ROAM, RAND, DEG, BETW] -
budget factor
$\beta$ :[0.5,1,2] -
similarity threshold
$\tau$ :[0.3,0.5,0.8]
can be modified at lines 51-64 of main.py.
To change the seed of the experiment, refer to line 92 of src/utils/utils.py.
- Run a single evasion
python single_evasion.py where the hyperparameters of the experiment can be modified at lines 61-68 of single_evasion.py.
This script does not support multiple datasets, betas and taus.
├── dataset
│ ├── networks # Contains the graphs
│ │ └── ...
│ └── README.md
├── images
│ └── ...
├── notebooks # Contains the notebooks used for the analysis
│ └── ...
├── outputs # Contains the results of new runs
│ └── ...
├── outputs_review # Contains the final results of the study
│ ├── all_datasets
│ │ └── ...
│ ├── dataset_analysis
│ │ └── ...
│ └── runs
│ └── ...
├── src # Contains the source code
│ ├── baselines
│ │ ├── betweenneess.py
│ │ ├── degree.py
│ │ ├── dice.py
│ │ ├── random.py
│ │ ├── roam.py
│ │ └── README.md
│ ├── community_detection # Contains community detection algorithms
│ │ ├── extra_algs
│ │ │ ├── dgcluster
│ │ │ │ ├── models
│ │ │ │ ├── results
│ │ │ │ ├── dgcluster_robustness.py
│ │ │ │ ├── dgcluster_training.py
│ │ │ │ ├── dgcluster.py
│ │ │ │ └── README.md
│ │ │ ├── locale
│ │ │ │ ├── temp_graphs
│ │ │ │ │ └── ...
│ │ │ │ ├── locale.py
│ │ │ │ └── README.md.py
│ │ │ ├── scd.py
│ │ │ └── README.md
│ │ ├── algorithms.py
│ │ ├── similarity_functions.py
│ │ └── README.md
│ ├── conf # Cointains the yaml files for Hydra logs
│ │ └── ...
│ ├── graph_environment
│ │ ├── env.py
│ │ └── README.md
│ ├── methods
│ │ ├── drl_agent # Cointains the Deep Reinforcement Learning agent
│ │ │ ├── a2c
│ │ │ │ └── ...
│ │ │ ├── models
│ │ │ │ └── ...
│ │ │ ├── agent.py
│ │ │ └── README.md
│ │ └── nabla_cmh # Cointains the Nabla-CMH method
│ │ ├── config.py
│ │ ├── nabla_cmh-hyp_search.py
│ │ ├── nabla_cmh.py
│ │ ├── nabla_utils.py
│ │ └── README.md
│ └── utils # Cointains the utils functions
│ ├── cmh_experiment.py
│ ├── dataset_analysis.py
│ ├── feature_analysis.py
│ ├── impact_analysis.py
│ ├── utils.py
│ └── README.md
│
├── main.py
├── single_evasion.py
├── README.md
└── requirements.txt