Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: Community Detection Implementation (v5.0.0)
Summary
This PR introduces a comprehensive community detection suite to Yog, enabling users to identify and analyze densely connected groups of nodes in graphs. The implementation includes 8 community detection algorithms, metrics module for evaluation, and random walk primitives.
What's New
Core Module (
yog/community.gleam)Core types and utilities for community detection:
Communities- Maps nodes to community IDs with community countDendrogram- Hierarchical community structure with merge historyCommunityId- Type alias for community identifierscommunities_to_dict/1,largest_community/1,community_sizes/1,merge_communities/3Community Detection Algorithms
yog/community/louvainyog/community/leidenyog/community/label_propagationyog/community/girvan_newmanyog/community/walktrapyog/community/infomapyog/community/clique_percolationyog/community/random_walkMetrics Module (
yog/community/metrics.gleam)Evaluation metrics for community quality:
modularity/2- Newman's modularity Q (O(E))count_triangles/1- Global triangle count (O(V × k²))triangles_per_node/1- Local triangle countsclustering_coefficient/2- Local clustering coefficientaverage_clustering_coefficient/1- Global clusteringdensity/1- Graph densitycommunity_density/2- Internal community densityaverage_community_density/2- Average across all communitiesInternal Utilities (
yog/community/internal.gleam)Shared infrastructure for modularity-based algorithms:
CommunityStatetype for tracking assignments and weightsAPI Design
All algorithms follow a consistent pattern:
Documentation
Every module includes:
File Structure
Implementation Highlights
Louvain Method
detect_hierarchical/1detect_with_stats/2Leiden Method
Label Propagation
Girvan-Newman
Walktrap
Infomap
Clique Percolation
Metrics
Testing
All algorithms have been tested with:
Test count: All 1053 existing tests pass.
Performance Considerations
Algorithm Selection Guide
Speed Priority: Label Propagation > Louvain > Leiden
Quality Priority: Leiden > Louvain > Infomap > Walktrap
Hierarchical Structure: Girvan-Newman, Louvain, Leiden, Walktrap
Overlapping Communities: Clique Percolation (only option)
Flow-Based: Infomap
Small Graphs (<1000 nodes): Any algorithm works well
Breaking Changes
None. This is a pure addition to the API.
Migration Guide
N/A - New feature, no migration needed.
Future Enhancements (v6.0.0+)
References
Checklist
Target Version: 5.0.0
Estimated Review Time: 30-45 minutes
Suggested Reviewers: Anyone familiar with graph algorithms