Yog.Community.Result (YogEx v0.97.0)

Copy Markdown View Source

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 ID
  • num_communities - Total number of distinct communities
  • metadata - 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

community_id()

@type community_id() :: any()

node_id()

@type node_id() :: Yog.Model.node_id()

t()

@type t() :: %Yog.Community.Result{
  assignments: %{required(node_id()) => community_id()},
  metadata: map(),
  num_communities: non_neg_integer()
}

Functions

from_map(map)

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

Backward compatibility: convert from legacy map format.

new(assignments)

@spec new(%{required(node_id()) => community_id()}) :: t()

Creates a community result from an assignments map.

Automatically calculates the number of communities.

new(assignments, metadata, opts \\ [])

@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

to_map(result)

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

Convert to legacy map format (for gradual migration).