This repository is the official implementation of Recovering Fairness Directly from Modularity: a New Way for Fair Community Partitioning.
The repository achieves four algorithms: Fast Newman, GenLouvain, FairFN, FairLouvain.
To install requirements:
pip install -r requirements.txt
The code is accelerate by Cupy, you can install it as in https://cupy.dev/.
data_preprocessing.py is provided to preprocess datasets:
python Datasets\data_preprocessing.py
Due to the size of datasets, we don't provide raw datasets in "Datasets" folder. All datasets are preprocessed in advanced.
Raw datasets can be found in:
Point data: bank,adult,census,diabetic,credit
Multiplex networks: airports,airports,arabidopsis,arxiv,twitter
The following example illustrates how to reproduce the main results of the paper. For more results, see test_fair_clustering.py.
To evaluate FairFN on point datasets, run:
python test_fair_clustering.py --algorithm fair_fn --exp_type point --datasets bank adult census synthetic_equal synthetic_unequal creditcard diabetic --alpha 4 8 4 4 64 4 4
To evaluate FairFN on LFR network, run:
python test_fair_clustering.py --algorithm fair_fn --exp_type lfr --community_num 5
To evaluate FairLouvain on multiplex network, run:
python test_fair_clustering.py --algorithm fair_louvain --exp_type multiplex --datasets airports arabidopsis arxiv twitter --beta 5 5 5 50
To evaluate FN and Louvain, replace fair_fn and fair_louvain with fn and louvain in above commands, respectively.
All results can be found in "output" folder.
We get following results on point datasets:
FN
| balance (FR) | awd | modularity | fairness_modularity | communities | |
|---|---|---|---|---|---|
| bank | 0.248036 | 0.077553 | 0.816653 | 0.002036 | 11 |
| adult | 0.558145 | 0.096328 | 0.759951 | 0.009441 | 7 |
| census | 0 | 0.32792 | 0.846602 | 0.057567 | 25 |
| synthetic_equal | 0.760611 | 0.033492 | 0.926244 | 0.000318 | 21 |
| synthetic_unequal | 0 | 0.039597 | 0.926244 | 0.000274 | 21 |
| creditcard | 0.522925 | 0.047604 | 0.717786 | 0.002279 | 10 |
| diabetic | 0.718701 | 0.025559 | 0.706033 | 0.00093 | 9 |
FairFN
| balance (FR) | awd | modularity | fairness_modularity | communities | |
|---|---|---|---|---|---|
| bank | 0.961291 | 0.002537 | 0.818538 | 8.11E-07 | 14 |
| adult | 0.999258 | 0.000105 | 0.762395 | 1.04E-08 | 11 |
| census | 0.995075 | 0.000314 | 0.831046 | 7.97E-08 | 14 |
| synthetic_equal | 0.985528 | 0.002003 | 0.930444 | 7.91E-07 | 28 |
| synthetic_unequal | 0.73828 | 0.00459 | 0.90358 | 1.95E-06 | 18 |
| creditcard | 0.983644 | 0.000353 | 0.722183 | 7.11E-08 | 8 |
| diabetic | 0.988213 | 0.000572 | 0.772907 | 1.69E-07 | 10 |
For the results of FairLouvain on multiplex networks:
| balance (FR) | awd | modularity | fairness_modularity | communities | |
|---|---|---|---|---|---|
| arxiv | 0.960935994 | 0.006739733 | 0.997297958 | 1.27E-05 | 23 |
| arabidopsis | 0.944075305 | 0.010457615 | 0.9840675 | 7.61E-05 | 14 |
| airports | 0.996645469 | 0.000819721 | 0.988642566 | 6.90E-07 | 5 |
| 0.948185118 | 0.005515819 | 0.937041534 | 6.35E-06 | 33 |
The FairFN algorithm is accelerated by Cupy and needs at least 4GB video memory. If video memory is limited, you can replace Cupy with Numpy manually.
In our paper, we proposes a new way to improve fairness in community detection by adjusting modularity, one of the most widely used measures for finding communities in networks. To our knowledge, this is the first fairness method that builds deeply on modularity, beyond simple subtraction tricks. Our work opens a new direction for fair community detection and may inspire more research using modularity-based methods.