# `Yog.Community.LabelPropagation`
[🔗](https://github.com/code-shoily/yog_ex/blob/v0.97.0/lib/yog/community/label_propagation.ex#L1)

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

# `default_options`

```elixir
@spec default_options() :: %{max_iterations: integer(), seed: integer()}
```

Returns default options for LPA.

# `detect`

```elixir
@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

# `detect_with_options`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
