Skip to content

core: Graph.coordinationRiskScore — 14th graduation (composite cartel detector)#328

Merged
AceHack merged 1 commit intomainfrom
feat/graph-coordination-risk-score-composite
Apr 24, 2026
Merged

core: Graph.coordinationRiskScore — 14th graduation (composite cartel detector)#328
AceHack merged 1 commit intomainfrom
feat/graph-coordination-risk-score-composite

Conversation

@AceHack
Copy link
Copy Markdown
Member

@AceHack AceHack commented Apr 24, 2026

First full integration ship: combines largestEigenvalue + labelPropagation + modularityScore into a single risk score.

Cartel-injection test: score > 1.0 (both signals fire). Baseline-vs-baseline near-zero. Empty → None.

34 GraphTests passing. Robust-z-score variant deferred to future graduation when baseline-null-calibration harness ships.

… detector)

First full integration of the Graph detection pipeline: combines
largestEigenvalue (spectral growth) + labelPropagation (community
partition) + modularityScore (partition evaluation) into a single
scalar risk score.

Surface:
  Graph.coordinationRiskScore
      (alpha: double) (beta: double)
      (eigenTol: double) (eigenIter: int) (lpIter: int)
      (baseline: Graph<'N>) (attacked: Graph<'N>)
      : double option

Composite formula (MVP):
  risk = alpha * Δλ₁_rel + beta * ΔQ

where:
- Δλ₁_rel = (λ₁(attacked) - λ₁(baseline)) / max(λ₁(baseline), eps)
- ΔQ = Q(attacked, LP(attacked)) - Q(baseline, LP(baseline))

Both signals fire when a dense subgraph is injected: λ₁ grows
because the cartel adjacency has high leading eigenvalue; Q grows
because LP finds the cartel as its own community and Newman Q
evaluates that partition highly.

Weight defaults per Amara 17th-ferry initial priors:
- alpha = 0.5 spectral growth
- beta  = 0.5 modularity shift

Tests (3 new, 34 total in GraphTests, all passing):
- Empty graphs -> None
- Cartel injection -> composite > 1.0 (both signals fire)
- attacked == baseline -> composite near 0 (|score| < 0.2)

Calibration deferred (Amara Otto-132 Part 2 correction #4 — robust
statistics via median + MAD): this MVP uses raw linear weighting
over differences. Full CoordinationRiskScore with robust z-scores
over baseline null-distribution is a future graduation once
baseline-calibration machinery ships. RobustStats.robustAggregate
(PR #295) already provides the median-MAD machinery; just needs a
calibration harness to use it.

14th graduation under Otto-105 cadence. First full integration
ship using 4 Graph primitives composed together (λ₁ + LP +
modularity + composer).

Build: 0 Warning / 0 Error.

Provenance:
- Concept: Aaron (firefly network + trivial-cartel-detect) +
  Amara's composite-score formulations across 12th/13th/14th/
  17th ferries
- Implementation: Otto (14th graduation)

Composes with:
- Graph.largestEigenvalue (PR #321)
- Graph.labelPropagation (PR #326)
- Graph.modularityScore (PR #324)
- RobustStats.robustAggregate (PR #295) — for future robust
  variant

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 24, 2026 07:58
@AceHack AceHack enabled auto-merge (squash) April 24, 2026 07:58
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@AceHack AceHack merged commit 0b731cb into main Apr 24, 2026
13 checks passed
@AceHack AceHack deleted the feat/graph-coordination-risk-score-composite branch April 24, 2026 08:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new composite cartel/coordination detector to Zeta.Core.Graph by combining spectral growth (Δλ₁) and modularity shift (ΔQ) into a single coordinationRiskScore, along with new integration-style tests to validate expected behavior on empty input, injected-cartel structure, and baseline==attacked.

Changes:

  • Added Graph.coordinationRiskScore composite risk score combining largestEigenvalue, labelPropagation, and modularityScore.
  • Added F# tests covering empty-input (None), cartel injection (score > 1.0), and baseline equality (near-zero score).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Core/Graph.fs Introduces coordinationRiskScore and accompanying XML-doc comment describing the composite formula and calibration notes.
tests/Tests.FSharp/Algebra/Graph.Tests.fs Adds three new tests exercising the composite score on empty graphs, injected clique/cartel structure, and baseline==attacked.

Comment thread src/Core/Graph.fs
Comment on lines +482 to +490
/// **Calibration note (per Amara Otto-132 Part 2
/// correction #4 — robust statistics):** this MVP uses
/// simple linear weighting over raw differences. A full
/// `CoordinationRiskScore` (per Amara's 17th-ferry
/// corrected composite) uses robust z-scores
/// `(x - median(baseline)) / (1.4826 * MAD(baseline))` over
/// each metric, combined with tunable weights. That version
/// is a future graduation once baseline-null-distribution
/// calibration machinery ships.
Comment thread src/Core/Graph.fs
Comment on lines +518 to +527
let qBaseline =
modularityScore partitionBaseline baseline
|> Option.defaultValue 0.0
let qAttacked =
modularityScore partitionAttacked attacked
|> Option.defaultValue 0.0
let eps = 1e-12
let spectralGrowth = (la - lb) / (max lb eps)
let modularityShift = qAttacked - qBaseline
Some (alpha * spectralGrowth + beta * modularityShift)
Comment thread src/Core/Graph.fs
Comment on lines +498 to +503
/// Provenance: 12th + 13th + 14th + 17th-ferry composite
/// score formulations. Otto's 14th graduation — first
/// full integration ship using four Graph primitives
/// (`largestEigenvalue` + `labelPropagation` +
/// `modularityScore` + this composer).
let coordinationRiskScore
AceHack added a commit that referenced this pull request Apr 24, 2026
…ns tracked; 3 already shipped) (#330)

* ferry: Amara 17th absorb — Cartel-Lab Implementation Closure + 5.5 Verification (8 corrections tracked)

Two-part ferry: Amara's deep-research Implementation Closure for
Cartel-Lab + her own GPT-5.5 Thinking verification pass with 8
load-bearing corrections.

Otto correction-pass status (all 8 tracked):
1. λ₁(K₃) = 2 — ALREADY CORRECT PR #321 Otto-127 (independent
   convergence before verification arrived)
2. Modularity relational-not-absolute — ALREADY CORRECT PR #324
   Otto-128 (caught mid-tick via hand-calc)
3. Cohesion/Exclusivity/Conductance replace entropy-collapse —
   SHIPPED PR #329 Otto-135 (3 primitives + 6 tests)
4. Windowed stake covariance acceleration — FUTURE GRADUATION
5. Event-stream → phase pipeline for PLV — FUTURE GRADUATION
6. 'ZSet invertible' → 'deltas support retractions' — ADR
   ALREADY PHRASED CORRECTLY (PR #316 never claimed full invertibility)
7. KSK 'contract' → 'policy layer' — FILED BACKLOG PR #318
   Otto-124 (Max coord pending)
8. SOTA humility — DOC PHRASING (applied in new absorb docs)

Amara's proposed 3-PR split NOT adopted (Otto-105 small-
graduation cadence; content delivered across 7 ticks instead:
PRs #317, #321, #323, #324, #326, #328, #329).

Amara's proposed /cartel-lab/ folder NOT adopted (Otto-108
Conway's-Law: single-module-tree until interfaces harden).
Current Graph.fs + test-support split works.

Aaron's SharderInfoTheoreticTests flake flag (trailing Otto-132
note) filed as BACKLOG PR #327 Otto-133 — unrelated hygiene
item.

Amara's Otto-136 follow-up note: '#323 conceptually accepted,
do not canonicalize until sharder test is seed-locked/
recalibrated'. Acknowledged — #323 lives in tests/Simulation/
already (test-scoped); 'canonicalize' = future promotion to
src/Core/NetworkIntegrity/ per Amara's PR #3 split suggestion;
that's gated on #327 completion.

§33 archive header compliance.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* lint: fix line-start PR-number header false-positive in 17th-ferry absorb

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
AceHack added a commit that referenced this pull request Apr 24, 2026
…18th graduation (Amara #4 robust)

Two ships consolidated per the 'parallel PRs hit positional
conflicts on tail-append' lesson:

1. RobustStats.robustZScore
   (baseline: double seq) -> (measurement: double) -> double option
   Returns (measurement - median) / (1.4826 · MAD). The 1.4826
   constant scales MAD to be consistent with Gaussian stddev.
   MadFloor prevents blow-up when every baseline value equal.

2. Graph.coordinationRiskScoreRobust
   alpha beta eigenTol eigenIter lpIter
   (baselineLambdas: double seq) (baselineQs: double seq)
   (attacked: Graph<'N>) -> double option
   Upgrades coordinationRiskScore (PR #328) from raw linear
   differences to robust-standardized z-scores per Amara
   17th-ferry correction #4. Caller provides baseline metric
   distributions; Z-scores calibrate thresholds from data.

Why robust z-scores: adversarial data isn't normally
distributed. An attacker can poison a ~normal distribution
by adding a few outliers that inflate stddev, making
subsequent real attacks look 'within one sigma'. Median+MAD
survives ~50% adversarial outliers. Standard move in robust
statistics literature; Amara's correction puts it on the
Zeta composite.

Tests (5 new; total 39 since main hasn't merged #331/#332 yet):
- robustZScore None on empty baseline
- robustZScore of measurement = median is 0
- robustZScore scales MAD by 1.4826 for Gaussian consistency
  (measurement 4 on baseline [1..5] ≈ 0.674)
- coordinationRiskScoreRobust fires strongly on K4-injected graph
  given 5 baseline samples
- coordinationRiskScoreRobust returns None on empty baselines

BACKLOG rows added this tick per Aaron Otto-139 directives:
1. Signal-processing primitives (FFT + Hilbert) — unblocks
   Amara correction #5 Option B; Aaron standing-approval
2. F# DSL for entry points + graph-query-language standards
   compliance (Cypher / GQL / Gremlin / SPARQL / Datalog)
3. LINQ-compatible entry points for C# consumers — pair with
   F# DSL; two frontends, one algebraic backend

6 of 8 Amara 17th-ferry corrections now shipped or confirmed:
Remaining: #6 ADR phrasing (already fine); #7 KSK naming
(BACKLOG #318 Max coord pending); #8 SOTA humility
(doc-phrasing discipline ongoing).

Build: 0 Warning / 0 Error.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
AceHack added a commit that referenced this pull request Apr 24, 2026
…mara #4 robust) + 3 BACKLOG rows (#333)

* core: RobustStats.robustZScore + Graph.coordinationRiskScoreRobust — 18th graduation (Amara #4 robust)

Two ships consolidated per the 'parallel PRs hit positional
conflicts on tail-append' lesson:

1. RobustStats.robustZScore
   (baseline: double seq) -> (measurement: double) -> double option
   Returns (measurement - median) / (1.4826 · MAD). The 1.4826
   constant scales MAD to be consistent with Gaussian stddev.
   MadFloor prevents blow-up when every baseline value equal.

2. Graph.coordinationRiskScoreRobust
   alpha beta eigenTol eigenIter lpIter
   (baselineLambdas: double seq) (baselineQs: double seq)
   (attacked: Graph<'N>) -> double option
   Upgrades coordinationRiskScore (PR #328) from raw linear
   differences to robust-standardized z-scores per Amara
   17th-ferry correction #4. Caller provides baseline metric
   distributions; Z-scores calibrate thresholds from data.

Why robust z-scores: adversarial data isn't normally
distributed. An attacker can poison a ~normal distribution
by adding a few outliers that inflate stddev, making
subsequent real attacks look 'within one sigma'. Median+MAD
survives ~50% adversarial outliers. Standard move in robust
statistics literature; Amara's correction puts it on the
Zeta composite.

Tests (5 new; total 39 since main hasn't merged #331/#332 yet):
- robustZScore None on empty baseline
- robustZScore of measurement = median is 0
- robustZScore scales MAD by 1.4826 for Gaussian consistency
  (measurement 4 on baseline [1..5] ≈ 0.674)
- coordinationRiskScoreRobust fires strongly on K4-injected graph
  given 5 baseline samples
- coordinationRiskScoreRobust returns None on empty baselines

BACKLOG rows added this tick per Aaron Otto-139 directives:
1. Signal-processing primitives (FFT + Hilbert) — unblocks
   Amara correction #5 Option B; Aaron standing-approval
2. F# DSL for entry points + graph-query-language standards
   compliance (Cypher / GQL / Gremlin / SPARQL / Datalog)
3. LINQ-compatible entry points for C# consumers — pair with
   F# DSL; two frontends, one algebraic backend

6 of 8 Amara 17th-ferry corrections now shipped or confirmed:
Remaining: #6 ADR phrasing (already fine); #7 KSK naming
(BACKLOG #318 Max coord pending); #8 SOTA humility
(doc-phrasing discipline ongoing).

Build: 0 Warning / 0 Error.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(#333): 4 review-thread P1/P2s on robustZScore + coordinationRiskScoreRobust

Active PR-resolve-loop on #333.

1. Doc/impl contradiction on MAD=0 (thread 59VhYb, P1):
   RobustStats.robustZScore doc said "returns None when
   MAD(baseline)=0" but impl uses MadFloor and returns
   Some finite value. Rewrote doc to match impl:
   explicit "MadFloor substituted when MAD collapses to
   zero" — floor reflects "scale is below epsilon" not
   "undefined." Implementation is the contract.

2. Multi-enumeration of baseline seq (thread 59VhYq, P1):
   robustZScore previously passed `baseline` to both
   `median` + `mad` which each call `Seq.toArray`.
   Expensive AND inconsistent for lazy/non-repeatable
   sequences (different values between enumerations =
   undefined behavior). Fixed: `Seq.toArray` once at
   entry, pass the materialized array to both. O(n)
   instead of O(2n); stable across lazy sources.

3. Name attribution in Graph.fs doc comment (thread
   59VhY5, P1): "Amara 17th-ferry... Otto 18th
   graduation" → "external AI collaborator's 17th
   courier ferry... Eighteenth graduation under the
   Otto-105 cadence." Role-reference convention per
   AGENT-BEST-PRACTICES code/doc rule.

4. Array-vs-seq terminology (thread 59VhZG, P2):
   Graph.fs doc said callers "provide arrays" but the
   API is `double seq`. Rewrote: sequences + noted the
   materialize-once optimization in robustZScore so
   callers can pass any seq form without re-enumeration
   cost.

Thread 59VhX9 (P3-label-in-P2-section mismatch) — already
resolved on main via PR #341 which landed the signal-
processing row correctly labeled "P2 research-grade."
No fix needed on this branch.

Build: 0 Warning(s) / 0 Error(s). 53 RobustStats + Graph
tests pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants