cluster

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cluster runs community detection (Louvain, via gonum) on the graph, then post-processes the result the way the Python original does: oversized communities are split, and IDs are assigned by descending size with a lexical tie-break so the same grouping always yields the same IDs across runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cluster

func Cluster(g *model.Graph) map[int][]string

Cluster partitions g into communities, returning communityID -> sorted node IDs.

func Cohesion

func Cohesion(g *model.Graph, nodes []string) float64

Cohesion is the ratio of actual intra-community edges to the maximum possible.

func NodeCommunity

func NodeCommunity(communities map[int][]string) map[string]int

NodeCommunity inverts communities into node ID -> community ID.

func RemapToPrevious added in v0.6.0

func RemapToPrevious(communities map[int][]string, prevNodeCommunity map[string]int) map[int][]string

RemapToPrevious relabels communities so their integer IDs stay stable across incremental rebuilds. It greedily matches each new community to the previous assignment that overlaps it most (one-to-one, by intersection size with an (oldID, newID) tie-break), then assigns fresh IDs to the unmatched communities in deterministic order (size desc, then lexical tie-break, reusing less). This keeps a per-node community diff meaningful when the grouping is unchanged.

func Scores

func Scores(g *model.Graph, communities map[int][]string) map[int]float64

Scores returns each community's cohesion score.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL