yog/community/internal
Internal utilities shared by Louvain and Leiden algorithms.
This module contains helper functions for modularity-based community detection. These are implementation details used by the Louvain and Leiden modules.
Internal Types
CommunityState: Tracks assignments, weights, and totals during optimization
Functions
These functions are primarily for internal use:
shuffle/2- Deterministic shuffle using LCGcalculate_modularity_gain/6- Delta Q for moving a nodemove_node/5- Update state after moving a nodephase2_aggregate/2- Aggregate communities into super-nodes
Note: This module is exposed for advanced users who want to implement
custom variants of modularity-based algorithms. Most users should use the
louvain or leiden modules directly.
Types
Values
pub fn calculate_community_totals(
assignments: dict.Dict(Int, Int),
node_weights: dict.Dict(Int, Float),
) -> dict.Dict(Int, Float)
Calculate total weight incident to each community.
pub fn calculate_ki_in(
graph: model.Graph(n, Int),
state: CommunityState,
node: Int,
target_comm: Int,
) -> Float
Calculate sum of edge weights from node to target community. Calculate sum of edge weights from node to target community.
pub fn calculate_modularity_gain(
graph: model.Graph(n, Int),
node: Int,
current_comm: Int,
target_comm: Int,
node_weight: Float,
state: CommunityState,
) -> Float
Calculate modularity gain from moving a node between communities.
pub fn calculate_node_weights(
graph: model.Graph(n, Int),
) -> dict.Dict(Int, Float)
Calculate degree (weight) for each node. Calculate degree (weight) for each node.
pub fn calculate_total_weight(
graph: model.Graph(n, Int),
) -> Float
Calculate total edge weight in graph. Calculate total edge weight in graph.
pub fn count_unique_communities(
assignments: dict.Dict(Int, Int),
) -> Int
Count unique communities in assignments.
pub fn get_community_nodes(
assignments: dict.Dict(Int, Int),
) -> dict.Dict(Int, set.Set(Int))
Convert assignments to community -> nodes mapping.
pub fn get_neighbor_communities(
graph: model.Graph(n, Int),
state: CommunityState,
node: Int,
) -> List(Int)
Get communities that are neighbors of a node.
pub fn move_node(
state: CommunityState,
node: Int,
from_comm: Int,
to_comm: Int,
node_weight: Float,
) -> CommunityState
Move a node from one community to another.
pub fn normalize_assignments(
assignments: dict.Dict(Int, Int),
) -> dict.Dict(Int, Int)
Normalize community IDs to be contiguous from 0 to k-1. This ensures that if there are k communities, they are numbered 0, 1, …, k-1 with no gaps, which is required for various property tests and downstream algorithms.
pub fn phase2_aggregate(
graph: model.Graph(n, Int),
assignments: dict.Dict(Int, Int),
) -> model.Graph(Nil, Int)
Aggregate graph by merging communities into super-nodes.
pub fn rebuild_state(
aggregated_graph: model.Graph(Nil, Int),
) -> CommunityState
Rebuild state for aggregated graph.