yog/community/label_propagation

Label Propagation Algorithm (LPA) for community detection.

A near-linear time algorithm that detects community structure by propagating labels through the network. Each node adopts the most frequent label among its neighbors until convergence.

Algorithm

  1. Initialize: Each node gets a unique label
  2. Iterate: Nodes update their label to the most common among neighbors
  3. Converge: Stop when no changes occur or max iterations reached

When to Use

Use CaseRecommendation
Very large graphs✓ Excellent (near-linear time)
Speed critical✓ Fastest option
Quality priorityConsider Louvain/Leiden
Overlapping communitiesUse Clique Percolation

Complexity

Example

import yog
import yog/community/label_propagation as lpa

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)])

// Basic usage
let communities = lpa.detect(graph)
io.debug(communities.num_communities)

// With custom options
let options = lpa.LabelPropagationOptions(max_iterations: 100, seed: 42)
let communities = lpa.detect_with_options(graph, options)

References

Types

Options for Label Propagation Algorithm.

pub type LabelPropagationOptions {
  LabelPropagationOptions(max_iterations: Int, seed: Int)
}

Constructors

  • LabelPropagationOptions(max_iterations: Int, seed: Int)

Values

pub fn default_options() -> LabelPropagationOptions

Default options for LPA.

pub fn detect(graph: model.Graph(n, e)) -> community.Communities

Detects communities using the Label Propagation Algorithm.

pub fn detect_with_options(
  graph: model.Graph(n, e),
  options: LabelPropagationOptions,
) -> community.Communities

Detects communities using LPA with custom options.

Search Document