community

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package community provides pluggable graph community detection algorithms.

Each algorithm implements the Algorithm interface. The registry maps string names to implementations so callers can select by name (CLI flag, MCP param, export option).

To add a new algorithm:

  1. Create a file (e.g. leiden.go) implementing Algorithm
  2. Register it in init() or Registry

Index

Constants

View Source
const Default = "louvain"

Default is the algorithm used when none is specified.

Variables

View Source
var Registry = map[string]Algorithm{
	"louvain":           &Louvain{Resolution: 1.0, MaxPasses: 20},
	"louvain-fine":      &Louvain{Resolution: 0.3, MaxPasses: 20},
	"label-propagation": &LabelPropagation{MaxIterations: 50},
}

Registry maps algorithm names to implementations.

Functions

func Names

func Names() []string

Names returns all registered algorithm names.

Types

type Algorithm

type Algorithm interface {
	Name() string
	Detect(g *Graph) map[types.Hash]int
}

Algorithm detects communities in a graph. Returns a map from node hash to community ID (int). Community IDs should be contiguous starting from 0.

func Get

func Get(name string) Algorithm

Get returns the algorithm for the given name, or nil if not found.

type Graph

type Graph struct {
	Nodes     []types.Hash
	Adj       map[types.Hash][]WeightedEdge
	NodeSet   map[types.Hash]bool
	EdgeCount int
}

Graph holds the adjacency list and node set for community detection.

type LabelPropagation

type LabelPropagation struct {
	MaxIterations int
}

LabelPropagation implements the label propagation community detection algorithm. Each node adopts the most common label among its neighbors. Fast and simple but non-deterministic (results vary between runs).

func (*LabelPropagation) Detect

func (lp *LabelPropagation) Detect(g *Graph) map[types.Hash]int

func (*LabelPropagation) Name

func (lp *LabelPropagation) Name() string

type Louvain

type Louvain struct {
	Resolution float64
	MaxPasses  int
}

Louvain implements single-pass Louvain modularity optimization. Resolution controls granularity: lower values produce fewer, larger communities.

func (*Louvain) Detect

func (l *Louvain) Detect(g *Graph) map[types.Hash]int

func (*Louvain) Name

func (l *Louvain) Name() string

type WeightedEdge

type WeightedEdge struct {
	Target types.Hash
	Weight float64
}

WeightedEdge represents a graph edge with a weight (typically confidence).

Jump to

Keyboard shortcuts

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