Result of community detection algorithms.
Represents a partition of nodes into non-overlapping communities, where each node belongs to exactly one community.
Fields
assignments- Map from node ID to community IDnum_communities- Total number of distinct communitiesmetadata- Optional metadata (algorithm name, quality metrics, etc.)
Examples
iex> result = Yog.Community.Result.new(%{1 => 0, 2 => 0, 3 => 1})
iex> result.num_communities
2
iex> result.assignments[1]
0
Summary
Functions
Backward compatibility: convert from legacy map format.
Creates a community result from an assignments map.
Creates a community result with explicit metadata and optional pre-computed values.
Convert to legacy map format (for gradual migration).
Types
@type community_id() :: any()
@type node_id() :: Yog.Model.node_id()
@type t() :: %Yog.Community.Result{ assignments: %{required(node_id()) => community_id()}, metadata: map(), num_communities: non_neg_integer() }
Functions
Backward compatibility: convert from legacy map format.
@spec new(%{required(node_id()) => community_id()}) :: t()
Creates a community result from an assignments map.
Automatically calculates the number of communities.
@spec new(%{required(node_id()) => community_id()}, map(), keyword()) :: t()
Creates a community result with explicit metadata and optional pre-computed values.
Options
:num_communities- Pre-computed community count to avoid re-scanning
Examples
iex> result = Yog.Community.Result.new(%{1 => 0, 2 => 0, 3 => 1}, %{}, num_communities: 2)
iex> result.num_communities
2
Convert to legacy map format (for gradual migration).