Label Propagation Algorithm (LPA) for community detection.
A fast, near-linear time algorithm where each node adopts the label that most of its neighbors have. The algorithm converges when each node has the same label as the majority of its neighbors.
When to Use
- Very large graphs (near-linear time complexity)
- Speed is more important than optimal quality
- Large-scale network analysis
Options
:max_iterations- Maximum iterations (default: 100):seed- Random seed for initialization (default: 0)
Examples
iex> graph = Yog.undirected()
...> |> Yog.add_node(1, nil)
...> |> Yog.add_node(2, nil)
...> |> Yog.add_node(3, nil)
...> |> Yog.add_edge_ensure(from: 1, to: 2, with: 1)
...> |> Yog.add_edge_ensure(from: 2, to: 3, with: 1)
iex> communities = Yog.Community.LabelPropagation.detect(graph)
iex> is_map(communities.assignments)
true
Summary
Functions
Returns default options for LPA.
Detects communities using Label Propagation with default options.
Detects communities using Label Propagation with custom options.
Functions
Returns default options for LPA.
@spec detect(Yog.graph()) :: Yog.Community.Result.t()
Detects communities using Label Propagation with default options.
Examples
iex> graph = Yog.undirected()
...> |> Yog.add_node(1, nil)
...> |> Yog.add_node(2, nil)
...> |> Yog.add_edge_ensure(from: 1, to: 2, with: 1)
iex> communities = Yog.Community.LabelPropagation.detect(graph)
iex> is_map(communities.assignments)
true
@spec detect_with_options( Yog.graph(), keyword() ) :: Yog.Community.Result.t()
Detects communities using Label Propagation with custom options.
Options
:max_iterations- Maximum iterations (default: 100):seed- Random seed (default: 0)
Examples
iex> graph = Yog.undirected()
...> |> Yog.add_node(1, nil)
...> |> Yog.add_node(2, nil)
...> |> Yog.add_edge_ensure(from: 1, to: 2, with: 1)
iex> communities = Yog.Community.LabelPropagation.detect_with_options(graph,
...> max_iterations: 200,
...> seed: 42
...> )
iex> is_map(communities.assignments)
true