Result of overlapping community detection (e.g., Clique Percolation).
Unlike standard community detection, nodes can belong to multiple communities simultaneously, reflecting the reality that individuals often participate in multiple social groups.
Fields
memberships- Map from node ID to list of community IDsnum_communities- Total number of distinct communitiescommunity_index- Inverted index: community_id -> MapSet of nodesmetadata- Optional metadata (algorithm name, parameters, etc.)
Examples
iex> # Node 1 in communities 0 and 1, node 2 only in 1
iex> overlapping = Yog.Community.Overlapping.new(%{1 => [0, 1], 2 => [1], 3 => [0]})
iex> overlapping.num_communities
2
iex> overlapping.memberships[1]
[0, 1]
Summary
Functions
Get all communities a node belongs to.
Backward compatibility: convert from legacy map format.
Creates an overlapping community result from a memberships map.
Creates an overlapping community result with explicit metadata and optional pre-computed values.
Get all nodes in a specific community.
Calculate the overlap (number of shared nodes) between two communities.
Convert to legacy map format.
Convert to non-overlapping result by assigning each node to its first community.
Types
@type community_id() :: any()
@type node_id() :: Yog.Model.node_id()
@type t() :: %Yog.Community.Overlapping{ community_index: %{required(community_id()) => MapSet.t(node_id())} | nil, memberships: %{required(node_id()) => [community_id()]}, metadata: map(), num_communities: non_neg_integer() }
Functions
@spec communities_for_node(t(), node_id()) :: [community_id()]
Get all communities a node belongs to.
Backward compatibility: convert from legacy map format.
@spec new(%{required(node_id()) => [community_id()]}) :: t()
Creates an overlapping community result from a memberships map.
Automatically calculates the number of communities by counting unique community IDs. Also builds an inverted index for O(1) community queries.
@spec new(%{required(node_id()) => [community_id()]}, map(), keyword()) :: t()
Creates an overlapping community result with explicit metadata and optional pre-computed values.
Options
:num_communities- Pre-computed community count to avoid re-scanning:community_index- Pre-computed inverted index for O(1) queries
@spec nodes_in_community(t(), community_id()) :: MapSet.t(node_id())
Get all nodes in a specific community.
Uses inverted index for O(1) lookup.
@spec overlap(t(), community_id(), community_id()) :: non_neg_integer()
Calculate the overlap (number of shared nodes) between two communities.
Convert to legacy map format.
@spec to_result(t()) :: Yog.Community.Result.t()
Convert to non-overlapping result by assigning each node to its first community.
Nodes with no membership are excluded (not assigned to any community).