Skip to content

v1.1.0

Choose a tag to compare

@denironyx denironyx released this 04 Oct 15:52
· 30 commits to main since this release

GraphFaker generates graph data that behaves the way real people and real money do, with the ground truth included. 1.1 adds a second labelled domain, and makes the machinery behind both of them part of the engine rather than part of the fraud pack.

pip install graphfaker==1.1.0
graphfaker generate coordination --scale 0.001 --tradecraft medium --seed 42 --out ./platform

The coordination pack

A social platform, and the coordinated behaviour inside it: accounts, topics and devices; a follow graph with heavy-tailed degree, about 50% reciprocity and recoverable communities; an organic stream of posts, reshares and replies with a diurnal rhythm and a lurker majority; and labelled campaigns hidden in it.

The command above gives 5,000 accounts, 50 topics, 93,000 follows, 147,000 events and 22 campaigns, of which 6 are organic. --tradecraft low|medium|high decides how well the inauthentic ones hide.

Eight inauthentic playbooks: copypasta, amplification_ring, reply_brigade, follow_farm, hashtag_flood, sockpuppet_cluster, astroturf_campaign, account_handover. follow_farm is in the catalogue because an event-only detector cannot see it at all: its members hardly post.

And three organic decoys, which are the point. Coordinated behaviour has a strong legitimate twin. A fandom reacting to a release, a city reacting to an earthquake and a paid amplification ring are structurally the same thing: a burst of near-simultaneous activity from a tightly connected group. A dataset whose only labelled structures are inauthentic rewards any detector that fires on synchrony, and that is the detector that suspends fan clubs. So fandom_burst, breaking_news and mutual_follow_community are generated by the same machinery, labelled is_coordinated=False, and counted as false positives when a detector flags them.

Tradecraft is measured, not asserted

from graphfaker.domains.coordination import generate, hardness_report

run = generate(scale=0.001, tradecraft="medium", seed=42)
print(hardness_report(run).summary())
tradecraft: medium
playbook                kind               n   max AUC  best feature (family)
follow_farm             coordinated       29     0.898  clustering_proxy (structure)
amplification_ring      coordinated       23     0.898  topic_concentration (content)
sockpuppet_cluster      coordinated       12     0.895  device_shared_with (identity)
mutual_follow_community organic           30     0.892  reciprocity (structure)
copypasta               coordinated       26     0.873  topic_concentration (content)
hashtag_flood           coordinated       43     0.870  topic_concentration (content)
fandom_burst            organic           41     0.862  topic_concentration (content)

Read the fourth row. mutual_follow_community is a group of people who genuinely know each other, and it is as hard to separate from a follow farm as the follow farm is to find. That is a decoy doing its job.

Across the three levels, the mean per-playbook best single feature falls 0.984, 0.852, 0.789, and the evidence that still works broadens from identity and timing to structure and content. decoy_separability scores each organic structure against the playbook it imitates and names the feature responsible, because a decoy separable by one feature is not a decoy.

Scoring a detector

evaluate scores at account, event and campaign granularity, and reports the organic false positive rate separately, because on a real platform the cost of suspending a fan club is not symmetric with the cost of missing one ring.

from graphfaker.domains.coordination import evaluate

result = evaluate(run, flagged_accounts=my_detector(run))
print(result.summary())

examples/coordination_detectors.py runs five rules a platform would try first at all three levels. The conclusion matches the fraud pack's Cypher cookbook: single-signal detectors do badly. The best F1 anywhere is 0.499, at the easiest setting, and the co-occurrence rule goes from 0.843 precision with no organic false positives at low to 0.118 precision and 15% of organic accounts flagged at medium.

Training on it

graphfaker generate coordination --scale 0.002 --tradecraft medium --seed 42 --sink pyg --out ./platform
python examples/coordination_pyg_baseline.py --scale 0.002

Account carries y, decoy and stratified splits; the three event channels carry y and edge_time; community is a latent tensor rather than a feature. A heterogeneous GraphSAGE against a logistic regression on account features alone: the graph helps everywhere, average precision more than doubles at medium (0.101 to 0.243), and it flags three times as many organic accounts (4.0% against 12.0%), because it buys its power by learning "tightly connected group acting together" and a fan club is exactly that. Measure AUC alone and the conclusion is "graphs win", which is true and incomplete.

The PyG sink's label rules are now a convention rather than the fraud pack's column names: a truth frame keyed by <entity>_id with a single boolean column labels those entities, so accounts.is_fraud and accounts.is_coordinated both work and a third domain gets labels without touching the module.

Patterns are declared now

Both packs hide something, and until now each had its own copy of the machinery for it. 1.1 moves that into the schema and the engine.

from graphfaker.schema import PatternCatalog, PatternSpec

CATALOG = PatternCatalog(
    base=1_000,   # patterns at scale 1.0
    floor=2,      # at least this many of every shape, so small datasets cover the catalogue
    patterns=[
        PatternSpec(name="fan_in", share=0.14, span_days=2.0),
        PatternSpec(name="cycle", share=0.10, span_days=2.0),
        PatternSpec(name="decoy_fan_in", imitates="fan_in", span_days=2.0),
    ],
)

PatternSpec and PatternCatalog declare what a pack injects: every shape with its share of the budget, its natural span, and, for a decoy, the shape it imitates. Camouflage is the set of dials every pack has (signature blend, timing spread, overlap, decoy ratio, activity camouflage, size scale), which HardnessProfile and TradecraftProfile subclass and rename to their own vocabulary. graphfaker.engine.injection holds the shared bookkeeping: the pattern record, the recruitment ledger, the budget allocator, the decoy orders and the driver loop.

What stays in the packs is the drawing itself: how many sources a fan-in has, what a copypasta posts, what an amount looks like. That is the part that does not generalise, and the part worth writing by hand. docs/adding-a-domain.md has the walkthrough.

The two packs lose about 200 lines of duplicated machinery between them, including two byte-identical copies of the budget allocator. Datasets are unchanged: the same seed gives the same fingerprint in both packs, at every hardness and tradecraft level.

Also

  • The social topology model is about 30 times faster and no longer quadratic in the graph. Edge building asked NetworkX for number_of_edges() twice per attempt, and that call sums the degree of every node. 2,000 nodes and 12,000 edges went from 22.4 s to 0.65 s; a million edges takes about 105 s and was not practical before. Same seed, same data.
  • fingerprint() visits tables by name, so a run read back from Parquet has the same digest as the run that wrote it.
  • Dependency floors raised for seven advisories: urllib3>=2.8.0, and in the examples extra notebook>=7.6.3 and jupyterlab>=4.6.4.

Documentation: https://graphfaker.readthedocs.io. Full changelog: HISTORY.rst.