yog/community/clique_percolation
Clique Percolation Method (CPM) for detecting overlapping communities.
Identifies communities by finding “chains” of adjacent k-cliques. Two k-cliques are adjacent if they share k-1 nodes. Unlike other algorithms, CPM can identify nodes that belong to multiple communities.
Algorithm
- Find all maximal cliques (using Bron-Kerbosch)
- Extract all k-cliques from maximal cliques
- Build adjacency between k-cliques (share k-1 nodes)
- Find connected components of k-cliques
- Merge cliques in each component to form communities
When to Use
| Use Case | Recommendation |
|---|---|
| Overlapping communities | ✓ Only algorithm in this module |
| Dense networks with cliques | ✓ Excellent |
| Sparse graphs | ✗ May find no communities |
| Non-overlapping needed | Convert with to_communities/1 |
Complexity
- Time: O(3^(V/3)) for maximal clique enumeration (worst case)
- Space: O(V + E)
Note: Clique enumeration can be expensive on large or dense graphs.
Example
import yog
import yog/community/clique_percolation as cpm
let graph =
yog.undirected()
|> yog.add_node(1, "A")
|> yog.add_node(2, "B")
|> yog.add_node(3, "C")
|> yog.add_edges([#(1, 2, 1), #(2, 3, 1), #(3, 1, 1)]) // Triangle
// Detect overlapping communities (k=3 finds triangles)
let overlapping = cpm.detect_overlapping(graph)
// overlapping.communities contains sets of nodes
// Convert to non-overlapping (assigns node to first community)
let communities = cpm.to_communities(overlapping)
// With custom k
let options = cpm.CPMOptions(k: 4)
let overlapping = cpm.detect_overlapping_with_options(graph, options)
References
Types
Options for Clique Percolation Method.
pub type CPMOptions {
CPMOptions(k: Int)
}
Constructors
-
CPMOptions(k: Int)Arguments
- k
-
Size of the clique (k). Typically 3 or 4.
Values
pub fn detect_overlapping(
graph: model.Graph(n, e),
) -> OverlappingCommunities
Detects overlapping communities using CPM with default options.
pub fn detect_overlapping_with_options(
graph: model.Graph(n, e),
options: CPMOptions,
) -> OverlappingCommunities
Detects overlapping communities using CPM with custom options.
pub fn to_communities(
overlapping: OverlappingCommunities,
) -> community.Communities
Converts overlapping communities to hard assignments by picking the first community for each node.