Community Detection using Hedonic Game Theory
Follow these steps to set up the project on your local machine.
git clone https://github.com/lucaslopes/hedonic.git
cd hedonic
python -m venv venv
pip install --upgrade pip
. venv/bin/activate
.\venv\Scripts\activate
pip install -e .
Using pip install -e .
installs the project in "editable" mode, which means any changes made to the project files will be immediately reflected without needing to reinstall the package. This is particularly useful during development, as it allows you to see the effects of your changes right away.
The hedonic.HedonicGame
class extends from igraph.Graph
, inheriting all its methods and properties. This means you can use it in a similar way to how you use igraph.Graph
, with additional functionality specific to hedonic games.
Here's an example of how to use it:
# Import the package
import hedonic as hd
# Create a famous graph, like the Zachary's Karate Club graph
G = hd.HedonicGame.Famous('Zachary')
# G = hd.HedonicGame(graph) # or if you already have an igraph.Graph object
# You can now detect communities using the `community_hedonic()` method:
partition = G.community_hedonic()
# You can also compare the detected communities with the ground truth communities:
ground_truth = G.vs['community']
accuracy = hd.compare_communities(partition, ground_truth, method='adjusted_rand')
print(f'Accuracy: {accuracy}')
In this example, G
is an instance of the HedonicGame
class created from a famous graph, similar to how you would use igraph.Graph.Famous
. The HedonicGame
class inherits from igraph.Graph
, so you can use all the standard igraph.Graph
methods on G
while also having access to additional methods specific to hedonic games, such as community_hedonic()
.
If you would like to contribute, please fork the repository and use a feature branch. Pull requests are welcome.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a pull request
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.