Help us shape the future of Go! Take the 2026 Go Developer Survey

score

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package score — centrality.go provides Brandes betweenness centrality with source sampling, used by the GRAPH_REPORT generator to surface "bridge nodes": symbols that connect otherwise-distant parts of the graph and therefore drive cross-cutting concerns.

Why sampling: full Brandes is O(V·(V+E)), which is ~4.6×10^11 ops on the go-stablenet self-graph (220K nodes / 2M edges). Source-sampled Brandes (k random sources, default 100) is O(k·(V+E)) — ~200M ops, sub-second in Go. Estimates are unbiased after the V/k scale-up multiplier, accurate to within ~5% for top-N ranking purposes (graphify uses the same approach in nx.betweenness_centrality(k=…)).

Meta nodes (Commit, Hunk — schema 1.4/1.8 G6 Temporal) are excluded from both the source pool AND the output map: they have no semantic edges that would produce meaningful centrality scores, and including them would dilute the V scale factor.

Package score computes per-node graph metrics in place: in/out degree, PageRank (damping=0.85, iterations=30), and usage_score (sum of incoming "calls"/"invokes" edge counts — used to size super-nodes in the viewer).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApproxBetweenness

func ApproxBetweenness(nodes []types.Node, edges []types.Edge, k int, seed int64) map[string]float64

ApproxBetweenness returns per-node betweenness centrality using Brandes' algorithm with source sampling. k≤0 or k≥|V| selects every node (exact). The graph is treated as undirected — bridge identification doesn't depend on direction (same convention graphify and most network- analysis libraries follow). Edges from/to meta nodes are dropped before the BFS, so e.g. a Function→Commit changed_in edge doesn't inflate the Function's centrality through history-only links.

seed pins the source-sampling RNG so the report is deterministic across runs against the same graph.

func Compute

func Compute(g *graph.Graph)

Compute populates InDegree, OutDegree, PageRank, and UsageScore for each node.

Meta nodes (Commit, Hunk — schema 1.4/1.8 G6 Temporal) are excluded from PageRank participation per hunk-graph.md §11.7 (decision 2026-05-09): Hunks have ~1 inbound edge each (has_hunk) and would rank near-zero, adding noise to the metric without contributing signal. They keep in/out degree counters populated (those are local, additive, and useful for the viewer's "how many hunks does this commit have" query) but their PageRank stays at the zero-initialised default.

Types

This section is empty.

Jump to

Keyboard shortcuts

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