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

Hierarchical community structure from algorithms like Louvain, Walktrap, Leiden.

A dendrogram represents multiple levels of community structure, from fine-grained
(many small communities) to coarse-grained (few large communities).

## Fields

- `levels` - List of community partitions, ordered from finest to coarsest
- `merge_order` - Sequence of community merges (optional)
- `metadata` - Optional metadata (algorithm name, modularity scores, etc.)

## Examples

    iex> level1 = Yog.Community.Result.new(%{1 => 0, 2 => 0, 3 => 1, 4 => 1})
    iex> level2 = Yog.Community.Result.new(%{1 => 0, 2 => 0, 3 => 0, 4 => 0})
    iex> dend = Yog.Community.Dendrogram.new([level1, level2])
    iex> Yog.Community.Dendrogram.finest(dend).num_communities
    2
    iex> Yog.Community.Dendrogram.coarsest(dend).num_communities
    1

# `t`

```elixir
@type t() :: %Yog.Community.Dendrogram{
  levels: [Yog.Community.Result.t()],
  merge_order: [{non_neg_integer(), non_neg_integer()}],
  metadata: map()
}
```

# `at_level`

```elixir
@spec at_level(t(), non_neg_integer()) :: Yog.Community.Result.t() | nil
```

Get partition with approximately n communities.

Returns the first level with <= n communities.

# `coarsest`

```elixir
@spec coarsest(t()) :: Yog.Community.Result.t()
```

Get the coarsest partition (fewest communities).

# `finest`

```elixir
@spec finest(t()) :: Yog.Community.Result.t()
```

Get the finest partition (most communities).

# `from_map`

```elixir
@spec from_map(map()) :: t()
```

Backward compatibility: convert from legacy map format.

# `get_level`

```elixir
@spec get_level(t(), non_neg_integer()) :: Yog.Community.Result.t() | nil
```

Get partition at a specific level index.

# `new`

```elixir
@spec new([Yog.Community.Result.t()]) :: t()
```

Creates a new dendrogram from a list of community levels.

# `new`

```elixir
@spec new([Yog.Community.Result.t()], [{non_neg_integer(), non_neg_integer()}]) :: t()
```

Creates a new dendrogram with merge order tracking.

# `num_levels`

```elixir
@spec num_levels(t()) :: non_neg_integer()
```

Get the number of hierarchical levels.

# `to_map`

```elixir
@spec to_map(t()) :: map()
```

Convert to legacy map format.

---

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