Documentation
¶
Overview ¶
Example 11_social_network — an end-to-end social-network workload over a labelled property graph (LPG): PageRank influence ranking, Leiden community detection, and a manual friend-of-friend recommendation walk, all over ONE seeded, scale-parametrised social graph.
It generates a realistic friendship network whose shape is fixed by the RNG seed, freezes it into an immutable CSR snapshot, and reads it three ways:
- PageRank influence ranking — who is most central, reported as a deterministic top-k of influencer ids (centrality.PageRank).
- Leiden community detection — which clusters the friendships form, reported as a community-count band and a modularity lower bound (community.LeidenCtx).
- Friend-of-friend recommendation — who a fixed seed user should befriend next, a manual two-hop walk over the live adjacency list.
The output is split into deterministic *facts* (bare lines: counts, influencer ids, community count, recommendation result — reproducible for a fixed seed) and volatile *telemetry* (lines prefixed with "# ": per-stage wall-clock and live heap — varies per run and per machine). A regression test pins the facts and ignores the telemetry.
Model ¶
(:User {id, name, community}) // id is "u%07d" in creation order
(:User)-[:FRIEND]-(:User) // an undirected, unweighted friendship
The graph is undirected (friendship is symmetric), so Leiden and the friend-of-friend walk both see a symmetric neighbourhood, and PageRank runs over the symmetric CSR (each undirected edge is stored as two directed entries) where degree heterogeneity still yields a meaningful centrality.
Topology — per-community Barabási–Albert blocks + a sparse bridge layer ¶
The generative model was chosen with the project's graph-theory-expert sub-agent so that ONE graph serves all three analytics. Verbatim:
GENERATIVE MODEL: per-community Barabási–Albert (BA) blocks + a sparse
bridge layer. Why this model: it is the only candidate that is natively
single-pass and O(E) with no rejection loop. BA gives a heavy degree
tail (gamma=3) per block -> meaningful PageRank influencers; separate
blocks + sparse bridges give assortative community structure -> Leiden
recovers the planted partition; triangle-rich BA neighbourhoods give a
non-trivial intra-community friend-of-friend set. (DCSBM = principled
but needs a power-law sequence + sparse edge sampler; LFR = the
benchmark gold standard but rejection-heavy — both over-engineered for
an example.) Refs: Barabási & Albert, Science 286:509 (1999);
Holland-Laskey-Leinhardt, Social Networks 5:109 (1983); Newman,
Networks 2e §13 (linear-time target-list sampling). Modularity: Newman &
Girvan, Phys. Rev. E 69:026113 (2004), Q ≈ (intra-edge fraction) − 1/K.
Detectability: Abbe, JMLR 18(177) (2017), SNR=(a−b)²/[K(a+(K−1)b)].
PARAMETER REGIME (validate()):
1. K >= 3 (so Q_max = 1−1/K can exceed 0.5)
2. m >= 1 AND s >= m+1 (each BA block connected BY CONSTRUCTION)
3. B >= K−1, laid as a spanning tree over blocks first (whole graph
connected structurally, not by luck)
4. B <= rho·K·m·s, rho ∈ [0.01,0.05] (intra fraction high -> Q ≈
(1−1/K)−rho ∈ [0.4,0.7])
5. SNR = (a−b)²/(K(a+(K−1)b)) >= 2, a≈2m, b≈2B/N (detectability margin)
Small default: K=4, s=64, m=2, B=8 -> Q≈0.73; assert Q>=0.55 & comms∈[3,5].
FoF (fixed seed user u, sorted by shared-friend count, tie-break by id):
- count of distinct FoF candidates -> DETERMINISTIC fact, pin it.
- exact ordered list (id tie-break) -> DETERMINISTIC fact, pin it.
- "every candidate is in community(u)" -> a THEOREM iff u is placed away
from any bridge (no bridge on u or its direct friends).
- "top recommendation is same-community as u" -> guarantee only under
that bridge-free-neighbourhood placement.
The generator follows this regime exactly. The fixed seed user is node 0 (the first-born hub of community 0); the bridge layer is laid down so that neither node 0 nor any of its direct friends is a bridge endpoint, which makes "every friend-of-friend candidate is in the seed user's community" a theorem of the construction (see buildBridges and friendsOfFriends).
Scale ¶
Run with no flags, the example builds the small deterministic default — four communities of sixty-four users (256 users), m=2 attachment, 8 bridges — which builds and analyses in well under a second and is pinned by the regression test. Every dimension is a flag, so the same binary scales up to where PageRank's convergence cost and the live-heap footprint become observable:
go run ./examples/11_social_network -users 1000000 -communities 50 -m 4 -seed 7
The deterministic facts are reproducible for a fixed -seed; only the telemetry (lines prefixed with "# ") varies between runs and machines.