@tangle-network/agent-eval 0.175.0 → 0.176.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/adapters/http.d.ts +1 -1
- package/dist/agent-profile-cell-0gSi5ffD.js +374 -0
- package/dist/agent-profile-cell-0gSi5ffD.js.map +1 -0
- package/dist/analyst/index.d.ts +2 -2
- package/dist/analyst/index.js +3 -3
- package/dist/{benchmark-command-D_5xG9LG.js → benchmark-command-yPqjcZnC.js} +7 -7
- package/dist/{benchmark-command-D_5xG9LG.js.map → benchmark-command-yPqjcZnC.js.map} +1 -1
- package/dist/benchmarks/index.d.ts +1 -1
- package/dist/benchmarks/index.js +3 -3
- package/dist/campaign/index.d.ts +3 -3
- package/dist/campaign/index.js +9 -9
- package/dist/{campaign-BzMSCejE.js → campaign-85igdlgG.js} +12 -12
- package/dist/{campaign-BzMSCejE.js.map → campaign-85igdlgG.js.map} +1 -1
- package/dist/campaign-evidence-D8DBLqLI.js +2083 -0
- package/dist/campaign-evidence-D8DBLqLI.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/contract/index.d.ts +4 -4
- package/dist/contract/index.js +8 -8
- package/dist/{define-agent-eval-V1jQyCDR.d.ts → define-agent-eval-CCbl8k2E.d.ts} +11 -4
- package/dist/define-agent-eval-CCbl8k2E.d.ts.map +1 -0
- package/dist/{define-agent-eval-ox5McL6e.js → define-agent-eval-DEMsu5eA.js} +54 -36
- package/dist/define-agent-eval-DEMsu5eA.js.map +1 -0
- package/dist/{dspy-rlm-engine-Caz2pl4L.js → dspy-rlm-engine-DqjER2sV.js} +2 -2
- package/dist/{dspy-rlm-engine-Caz2pl4L.js.map → dspy-rlm-engine-DqjER2sV.js.map} +1 -1
- package/dist/{eval-campaign-BeAjdhzC.js → eval-campaign-Cs-7MiCs.js} +4 -5
- package/dist/{eval-campaign-BeAjdhzC.js.map → eval-campaign-Cs-7MiCs.js.map} +1 -1
- package/dist/experiment/index.d.ts +3 -68
- package/dist/experiment/index.d.ts.map +1 -1
- package/dist/experiment/index.js +6 -128
- package/dist/experiment/index.js.map +1 -1
- package/dist/{attestation-XSUpbc4o.js → experiment-tracker-BKEumQug.js} +2 -96
- package/dist/experiment-tracker-BKEumQug.js.map +1 -0
- package/dist/{attestation-c1QvaBdX.d.ts → experiment-tracker-CNwqCZFD.d.ts} +2 -78
- package/dist/experiment-tracker-CNwqCZFD.d.ts.map +1 -0
- package/dist/{external-optimizer-process-CxnFL1hd.js → external-optimizer-process-Dlz8YxrT.js} +3 -3
- package/dist/{external-optimizer-process-CxnFL1hd.js.map → external-optimizer-process-Dlz8YxrT.js.map} +1 -1
- package/dist/{external-optimizer-subprocess-CQi27uEI.js → external-optimizer-subprocess-q3VzlGAO.js} +2 -2
- package/dist/{external-optimizer-subprocess-CQi27uEI.js.map → external-optimizer-subprocess-q3VzlGAO.js.map} +1 -1
- package/dist/{index-DKXuBPXf.d.ts → index-Bg6OT2Dd.d.ts} +23 -10
- package/dist/{index-DKXuBPXf.d.ts.map → index-Bg6OT2Dd.d.ts.map} +1 -1
- package/dist/{index-BTrx5s8m.d.ts → index-DBkcm_9H.d.ts} +4 -4
- package/dist/{index-BTrx5s8m.d.ts.map → index-DBkcm_9H.d.ts.map} +1 -1
- package/dist/{index-D-UdhAmg.d.ts → index-u0d1Jp4F.d.ts} +4 -2
- package/dist/{index-D-UdhAmg.d.ts.map → index-u0d1Jp4F.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +14 -15
- package/dist/index.js.map +1 -1
- package/dist/ledger-core/index.d.ts +2 -2
- package/dist/ledger-core/index.js +2 -2
- package/dist/{ledger-core-PIfjCbKn.js → ledger-core-Cs9f7385.js} +60 -47
- package/dist/{ledger-core-PIfjCbKn.js.map → ledger-core-Cs9f7385.js.map} +1 -1
- package/dist/{llm-judge-DmNaBrXB.js → llm-judge-DliimmRb.js} +994 -1517
- package/dist/llm-judge-DliimmRb.js.map +1 -0
- package/dist/{mint-vWOdD8Ae.js → mint-Cc1_zwRQ.js} +2 -2
- package/dist/{mint-vWOdD8Ae.js.map → mint-Cc1_zwRQ.js.map} +1 -1
- package/dist/openapi.json +1 -1
- package/dist/{produced-state-B8mw6zj9.js → produced-state-DrMqa2HD.js} +3 -2
- package/dist/{produced-state-B8mw6zj9.js.map → produced-state-DrMqa2HD.js.map} +1 -1
- package/dist/profile-cell.js +1 -268
- package/dist/{promotion-policy-LY9mVQ7W.js → promotion-policy-DWOm70gx.js} +2 -2
- package/dist/{promotion-policy-LY9mVQ7W.js.map → promotion-policy-DWOm70gx.js.map} +1 -1
- package/dist/{release-confidence-BsGEg_xg.js → release-confidence-BcGCclTB.js} +2 -2
- package/dist/{release-confidence-BsGEg_xg.js.map → release-confidence-BcGCclTB.js.map} +1 -1
- package/dist/reporting.js +2 -2
- package/dist/{reward-hacking-CKW4teig.js → reward-hacking-D0XwhVWE.js} +2 -215
- package/dist/reward-hacking-D0XwhVWE.js.map +1 -0
- package/dist/rl.js +5 -4
- package/dist/rl.js.map +1 -1
- package/dist/rollout/index.js +2 -2
- package/dist/{rollout-CGlDq1GI.js → rollout-DmoJVqrF.js} +2 -2
- package/dist/{rollout-CGlDq1GI.js.map → rollout-DmoJVqrF.js.map} +1 -1
- package/dist/run-record-CR63CpHK.js +216 -0
- package/dist/run-record-CR63CpHK.js.map +1 -0
- package/dist/{run-record-ZIsR9Fif.js → run-record-DQpSf7t-.js} +2 -2
- package/dist/{run-record-ZIsR9Fif.js.map → run-record-DQpSf7t-.js.map} +1 -1
- package/dist/{semantic-concept-judge-E3s_fEjB.js → semantic-concept-judge-Dw-f7TEs.js} +3 -3
- package/dist/{semantic-concept-judge-E3s_fEjB.js.map → semantic-concept-judge-Dw-f7TEs.js.map} +1 -1
- package/dist/{sequential-B51qAYE4.js → sequential-B5gXgcyp.js} +3 -3
- package/dist/{sequential-B51qAYE4.js.map → sequential-B5gXgcyp.js.map} +1 -1
- package/dist/{skillopt-optimization-method-f7399oGb.js → skillopt-optimization-method-CV7go7ex.js} +6 -749
- package/dist/skillopt-optimization-method-CV7go7ex.js.map +1 -0
- package/dist/{statistical-heldout-Cqb73yE9.d.ts → statistical-heldout-Z9NROFFS.d.ts} +156 -3
- package/dist/statistical-heldout-Z9NROFFS.d.ts.map +1 -0
- package/dist/{summary-report-Bgh8CpNK.js → summary-report-B16xy9Kd.js} +2 -2
- package/dist/{summary-report-Bgh8CpNK.js.map → summary-report-B16xy9Kd.js.map} +1 -1
- package/dist/traces.js +1 -1
- package/docs/public-api.md +62 -39
- package/docs/search-history-receipts.md +48 -1
- package/package.json +1 -1
- package/dist/attestation-XSUpbc4o.js.map +0 -1
- package/dist/attestation-c1QvaBdX.d.ts.map +0 -1
- package/dist/define-agent-eval-V1jQyCDR.d.ts.map +0 -1
- package/dist/define-agent-eval-ox5McL6e.js.map +0 -1
- package/dist/llm-judge-DmNaBrXB.js.map +0 -1
- package/dist/power-preflight-CFXm0Vjo.js +0 -502
- package/dist/power-preflight-CFXm0Vjo.js.map +0 -1
- package/dist/pre-registration-D94b7Of5.js +0 -110
- package/dist/pre-registration-D94b7Of5.js.map +0 -1
- package/dist/profile-cell.js.map +0 -1
- package/dist/reward-hacking-CKW4teig.js.map +0 -1
- package/dist/skillopt-optimization-method-f7399oGb.js.map +0 -1
- package/dist/statistical-heldout-Cqb73yE9.d.ts.map +0 -1
|
@@ -1,502 +0,0 @@
|
|
|
1
|
-
import { g as pairedRiskDifferenceScore, h as pairedRiskDifferenceExact, p as pairedBinaryScale } from "./paired-arms-D4aeIHUy.js";
|
|
2
|
-
import { a as pairedSignTest, i as pairedDeltaTieFraction, r as pairedBootstrap } from "./paired-tests-C8iCsioC.js";
|
|
3
|
-
//#region src/paired-delta-test.ts
|
|
4
|
-
/** Smallest all-positive sample that can clear a one-sided exact sign test. */
|
|
5
|
-
function minimumPairsForPairedDeltaTest(confidence = .95) {
|
|
6
|
-
if (!Number.isFinite(confidence) || confidence <= 0 || confidence >= 1) throw new Error(`minimumPairsForPairedDeltaTest: confidence must be in (0,1), got ${confidence}`);
|
|
7
|
-
const oneSidedAlpha = (1 - confidence) / 2;
|
|
8
|
-
return Math.ceil(Math.log2(1 / oneSidedAlpha));
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Tests whether a paired candidate-minus-baseline delta clears a threshold.
|
|
12
|
-
*
|
|
13
|
-
* At 20 or more pairs, the percentile bootstrap lower bound carries the
|
|
14
|
-
* decision. Below that point the interval is descriptive only, so the function
|
|
15
|
-
* switches to a pre-registered one-sided exact sign test. The exact path is
|
|
16
|
-
* deliberately conservative: it requires both a point estimate above the
|
|
17
|
-
* threshold and enough consistently positive paired differences.
|
|
18
|
-
*
|
|
19
|
-
* ## A zero-width interval is never significant
|
|
20
|
-
*
|
|
21
|
-
* When every paired delta is identical the resample distribution is a point
|
|
22
|
-
* mass and the interval collapses: `[0, 0]` when all pairs tie, `[g, g]` on n
|
|
23
|
-
* identical deltas of g. Neither says the effect is certain — both say the
|
|
24
|
-
* sample carries no information about how far the estimate could be wrong, and
|
|
25
|
-
* `low > threshold` then answers on the point estimate alone. It fails in both
|
|
26
|
-
* directions: `[0, 0]` clears every NEGATIVE threshold, which is how a
|
|
27
|
-
* tie-dominated pass/fail comparison laundered a regression into a
|
|
28
|
-
* noninferiority pass, and `[g, g]` clears every threshold below g with no
|
|
29
|
-
* spread behind it. Under a bounded asymmetric null whose true mean paired
|
|
30
|
-
* delta is exactly 0 — 2 % of pairs dropping by 1.0, the rest gaining 0.0204 —
|
|
31
|
-
* every sample that misses the drop is exactly that shape, and deciding on
|
|
32
|
-
* `low > 0` promoted 65.65 % of samples at n = 20 against a nominal 5 %.
|
|
33
|
-
*
|
|
34
|
-
* So `indeterminate` is reported and `significant` is false whenever the
|
|
35
|
-
* interval has zero width, on BOTH paths: at small n the exact sign test is a
|
|
36
|
-
* test of the MEDIAN and a zero-spread sample is precisely where it stops
|
|
37
|
-
* saying anything about the mean the caller is thresholding.
|
|
38
|
-
*
|
|
39
|
-
* `threshold` may be negative — that is a noninferiority margin, and it is the
|
|
40
|
-
* regime the zero-width hole is worst in. For a two-point (pass/fail) outcome
|
|
41
|
-
* the percentile bootstrap is not a valid interval at a nonzero margin at all;
|
|
42
|
-
* use {@link decidePairedPromotion}, which routes those to Tango's score
|
|
43
|
-
* interval, rather than thresholding this function's bootstrap directly.
|
|
44
|
-
*/
|
|
45
|
-
function pairedDeltaTest(before, after, options = {}) {
|
|
46
|
-
const threshold = options.threshold ?? 0;
|
|
47
|
-
if (!Number.isFinite(threshold)) throw new Error(`pairedDeltaTest: threshold must be finite, got ${threshold}`);
|
|
48
|
-
const exactMinimum = minimumPairsForPairedDeltaTest(options.confidence ?? .95);
|
|
49
|
-
const requestedMinimum = options.minPairs ?? exactMinimum;
|
|
50
|
-
if (!Number.isInteger(requestedMinimum) || requestedMinimum < 1) throw new Error(`pairedDeltaTest: minPairs must be a positive integer, got ${requestedMinimum}`);
|
|
51
|
-
const minimumPairs = Math.max(requestedMinimum, exactMinimum);
|
|
52
|
-
const bootstrap = pairedBootstrap(before, after, options);
|
|
53
|
-
const sufficient = bootstrap.n >= minimumPairs;
|
|
54
|
-
const indeterminate = bootstrap.n > 0 && (!Number.isFinite(bootstrap.low) || !Number.isFinite(bootstrap.high) || bootstrap.low === bootstrap.high);
|
|
55
|
-
if (bootstrap.gateEligible) return {
|
|
56
|
-
bootstrap,
|
|
57
|
-
method: "bootstrap-ci",
|
|
58
|
-
pValue: null,
|
|
59
|
-
minimumPairs,
|
|
60
|
-
sufficient,
|
|
61
|
-
indeterminate,
|
|
62
|
-
significant: sufficient && !indeterminate && bootstrap.low > threshold
|
|
63
|
-
};
|
|
64
|
-
const exact = pairedSignTest(before.map((value, index) => after[index] - value - threshold), "greater");
|
|
65
|
-
const estimate = options.statistic === "mean" ? bootstrap.mean : bootstrap.median;
|
|
66
|
-
return {
|
|
67
|
-
bootstrap,
|
|
68
|
-
method: "exact-sign",
|
|
69
|
-
pValue: exact.pValue,
|
|
70
|
-
minimumPairs,
|
|
71
|
-
sufficient,
|
|
72
|
-
indeterminate,
|
|
73
|
-
significant: sufficient && !indeterminate && estimate > threshold && exact.pValue <= (1 - bootstrap.confidence) / 2
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region src/paired-promotion-decision.ts
|
|
78
|
-
/**
|
|
79
|
-
* @module
|
|
80
|
-
* ONE rule for "does this paired interval clear a promotion threshold".
|
|
81
|
-
*
|
|
82
|
-
* The rule below was derived on `HeldOutGate` (#479) after the same estimator
|
|
83
|
-
* bug shipped twice. It then turned out that a SECOND gate — the composable
|
|
84
|
-
* `heldOutGate`, plus everything else routed through `heldoutSignificance` —
|
|
85
|
-
* still carried the original defect, because the rule had been written into one
|
|
86
|
-
* gate's method body rather than into a shared function. Two copies of a
|
|
87
|
-
* statistical rule is how a defect survives in one of them, so there is now
|
|
88
|
-
* exactly one copy and both gates call it.
|
|
89
|
-
*
|
|
90
|
-
* Three things the rule does that a bare `pairedBootstrap(...).low > threshold`
|
|
91
|
-
* does not:
|
|
92
|
-
*
|
|
93
|
-
* 1. **Two-point (pass/fail) outcomes decide on Tango's SCORE interval.** On a
|
|
94
|
-
* pass/fail eval the paired delta vector is dominated by ties, so the
|
|
95
|
-
* bootstrap of the mean is a resample of a lattice with three atoms and its
|
|
96
|
-
* percentile interval is not valid at a nonzero margin. The score interval
|
|
97
|
-
* (`pairedRiskDifferenceScore`) re-estimates the nuisance loss rate under
|
|
98
|
-
* each hypothesised margin instead of fixing it at the observed value, which
|
|
99
|
-
* is the only construction that stays a confidence interval as the margin
|
|
100
|
-
* moves off zero — the regime every noninferiority threshold lives in.
|
|
101
|
-
* Measured on the composable gate before this change, at a true risk
|
|
102
|
-
* difference sitting exactly on the production caller's -0.05 margin and a
|
|
103
|
-
* nominal 5 %: 14.60 % false promotion at n = 40 and 10.10 % at n = 76.
|
|
104
|
-
* 2. **McNemar's exact test holds a VETO at every non-negative threshold.**
|
|
105
|
-
* Redundant with the interval by construction and kept anyway, so that
|
|
106
|
-
* swapping the estimator for one without that duality cannot silently
|
|
107
|
-
* reintroduce "promotes what the exact test refuses". Witness: n = 6, b = 5,
|
|
108
|
-
* c = 0 — no exact argument reaches alpha = 0.05 with 5 discordant pairs
|
|
109
|
-
* (two-sided floor 2/2^5 = 0.0625), whatever an interval says. A NEGATIVE
|
|
110
|
-
* threshold is a noninferiority question, which McNemar's test of "no
|
|
111
|
-
* difference" is not the right test for, so the veto does not apply there.
|
|
112
|
-
* 3. **A ZERO-WIDTH interval is refused, wherever it sits.** At [0, 0] it
|
|
113
|
-
* cannot tell a gain from a regression and clears every negative threshold.
|
|
114
|
-
* Away from zero it fails the opposite way: n identical positive deltas give
|
|
115
|
-
* [g, g], which clears threshold 0 on no spread at all. Both are an absence
|
|
116
|
-
* of evidence. Measured on the composable gate before this change, under a
|
|
117
|
-
* bounded asymmetric null whose true mean paired delta is exactly 0: 88.50 %
|
|
118
|
-
* false promotion at n = 6 and 65.65 % at n = 20 against a nominal 5 %.
|
|
119
|
-
*
|
|
120
|
-
* Orthogonal to the small-sample switch inside {@link pairedDeltaTest}: that
|
|
121
|
-
* picks the TEST from the sample size (bootstrap CI at n >= 20, pre-registered
|
|
122
|
-
* exact sign test below it), this picks the ESTIMATOR from the outcome's shape.
|
|
123
|
-
* Both are needed — an exact sign test applied to a tie-pinned median is still
|
|
124
|
-
* blind, and a mean bootstrap CI at n = 6 is still not a valid test.
|
|
125
|
-
*/
|
|
126
|
-
/**
|
|
127
|
-
* Which estimator {@link decidePairedPromotion} would use on this data, and the
|
|
128
|
-
* shape facts behind it — for callers that must report the shape on a path
|
|
129
|
-
* where no interval is computed at all (an early rejection, or zero pairs).
|
|
130
|
-
* Cheap: no bootstrap, no interval.
|
|
131
|
-
*/
|
|
132
|
-
function pairedDecisionShape(before, after, statistic = "mean") {
|
|
133
|
-
const tieFraction = before.length === 0 ? null : pairedDeltaTieFraction(before, after);
|
|
134
|
-
if (statistic === "median") return {
|
|
135
|
-
statistic: "median_bootstrap",
|
|
136
|
-
binaryScale: null,
|
|
137
|
-
tieFraction
|
|
138
|
-
};
|
|
139
|
-
const binaryScale = pairedBinaryScale(before, after);
|
|
140
|
-
if (binaryScale !== null) return {
|
|
141
|
-
statistic: "paired_risk_difference",
|
|
142
|
-
binaryScale,
|
|
143
|
-
tieFraction
|
|
144
|
-
};
|
|
145
|
-
return {
|
|
146
|
-
statistic: "mean_bootstrap",
|
|
147
|
-
binaryScale: null,
|
|
148
|
-
tieFraction
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Decide whether a paired candidate-minus-baseline delta clears a promotion
|
|
153
|
-
* threshold. `before` is the baseline arm, `after` the candidate arm, paired by
|
|
154
|
-
* position. Throws on unequal lengths.
|
|
155
|
-
*/
|
|
156
|
-
function decidePairedPromotion(before, after, options = {}) {
|
|
157
|
-
if (before.length !== after.length) throw new Error(`decidePairedPromotion: unequal sample sizes (${before.length} vs ${after.length})`);
|
|
158
|
-
const threshold = options.threshold ?? 0;
|
|
159
|
-
if (!Number.isFinite(threshold)) throw new Error(`decidePairedPromotion: threshold must be finite, got ${threshold}`);
|
|
160
|
-
const confidence = options.confidence ?? .95;
|
|
161
|
-
const exactMinimum = minimumPairsForPairedDeltaTest(confidence);
|
|
162
|
-
const requestedMinimum = options.minPairs ?? exactMinimum;
|
|
163
|
-
if (!Number.isInteger(requestedMinimum) || requestedMinimum < 1) throw new Error(`decidePairedPromotion: minPairs must be a positive integer, got ${requestedMinimum}`);
|
|
164
|
-
const minimumPairs = Math.max(requestedMinimum, exactMinimum);
|
|
165
|
-
const n = before.length;
|
|
166
|
-
const sufficient = n >= minimumPairs;
|
|
167
|
-
const { binaryScale, tieFraction } = pairedDecisionShape(before, after, options.statistic);
|
|
168
|
-
let core;
|
|
169
|
-
if (binaryScale !== null) {
|
|
170
|
-
const unitControl = before.map((v) => v / binaryScale);
|
|
171
|
-
const unitTreatment = after.map((v) => v / binaryScale);
|
|
172
|
-
const exact = pairedRiskDifferenceExact(unitControl, unitTreatment, confidence);
|
|
173
|
-
const score = pairedRiskDifferenceScore(unitControl, unitTreatment, confidence);
|
|
174
|
-
const low = score.lower * binaryScale;
|
|
175
|
-
core = {
|
|
176
|
-
statistic: "paired_risk_difference",
|
|
177
|
-
method: "score-interval",
|
|
178
|
-
delta: score.riskDifference * binaryScale,
|
|
179
|
-
low,
|
|
180
|
-
high: score.upper * binaryScale,
|
|
181
|
-
bootstrap: null,
|
|
182
|
-
mcnemar: {
|
|
183
|
-
b: exact.b,
|
|
184
|
-
c: exact.c,
|
|
185
|
-
nDiscordant: exact.nDiscordant,
|
|
186
|
-
pValue: exact.pValue
|
|
187
|
-
},
|
|
188
|
-
pValue: null,
|
|
189
|
-
clearsThreshold: low > threshold,
|
|
190
|
-
label: "success-rate",
|
|
191
|
-
methodDetail: ""
|
|
192
|
-
};
|
|
193
|
-
} else {
|
|
194
|
-
const bootstrapStatistic = options.statistic === "median" ? "median" : "mean";
|
|
195
|
-
const test = pairedDeltaTest(before, after, {
|
|
196
|
-
confidence,
|
|
197
|
-
resamples: options.resamples,
|
|
198
|
-
statistic: bootstrapStatistic,
|
|
199
|
-
seed: options.seed,
|
|
200
|
-
threshold,
|
|
201
|
-
minPairs: options.minPairs
|
|
202
|
-
});
|
|
203
|
-
const ci = test.bootstrap;
|
|
204
|
-
core = {
|
|
205
|
-
statistic: bootstrapStatistic === "mean" ? "mean_bootstrap" : "median_bootstrap",
|
|
206
|
-
method: test.method,
|
|
207
|
-
delta: bootstrapStatistic === "mean" ? ci.mean : ci.median,
|
|
208
|
-
low: ci.low,
|
|
209
|
-
high: ci.high,
|
|
210
|
-
bootstrap: ci,
|
|
211
|
-
mcnemar: null,
|
|
212
|
-
pValue: test.pValue,
|
|
213
|
-
clearsThreshold: test.significant,
|
|
214
|
-
label: bootstrapStatistic,
|
|
215
|
-
methodDetail: test.method === "exact-sign" ? ` Below ${test.minimumPairs} pairs the interval is descriptive only; the decision is the exact one-sided sign test, p=${fmt(test.pValue ?? 1)}.` : ""
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
const indeterminate = !Number.isFinite(core.low) || !Number.isFinite(core.high) || core.low === core.high;
|
|
219
|
-
const indeterminateCause = !indeterminate ? "" : tieFraction === 1 ? "every paired delta is an exact tie" : core.mcnemar !== null && core.mcnemar.nDiscordant === 0 ? "every pair is concordant (0 discordant pairs)" : `the ${core.label} CI collapsed to a point at ${fmt(core.low)}`;
|
|
220
|
-
const exactTestVetoes = core.mcnemar !== null && threshold >= 0 && !(core.mcnemar.pValue < 1 - confidence);
|
|
221
|
-
return {
|
|
222
|
-
n,
|
|
223
|
-
threshold,
|
|
224
|
-
confidence,
|
|
225
|
-
binaryScale,
|
|
226
|
-
tieFraction,
|
|
227
|
-
minimumPairs,
|
|
228
|
-
sufficient,
|
|
229
|
-
indeterminate,
|
|
230
|
-
indeterminateCause,
|
|
231
|
-
exactTestVetoes,
|
|
232
|
-
promote: sufficient && !indeterminate && core.clearsThreshold && !exactTestVetoes,
|
|
233
|
-
...core
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
function fmt(x) {
|
|
237
|
-
return x.toFixed(4);
|
|
238
|
-
}
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region src/campaign/gates/statistical-heldout.ts
|
|
241
|
-
/**
|
|
242
|
-
* Statistical held-out promotion machinery — the trustworthy core the
|
|
243
|
-
* point-estimate `heldout-delta` gate lacked.
|
|
244
|
-
*
|
|
245
|
-
* The shipped false positive it prevents: a winner re-scored against the
|
|
246
|
-
* baseline on the holdout read run-to-run model NOISE (e.g. 91 vs 95) as a
|
|
247
|
-
* "+4 lift" and shipped, because the gate compared point estimates with no
|
|
248
|
-
* confidence interval. Here we pair candidate vs baseline holdout observations
|
|
249
|
-
* and bootstrap a CI on the paired delta — a candidate ships only when the CI
|
|
250
|
-
* lower bound clears the effect-size threshold (the gain is real at the
|
|
251
|
-
* confidence level, not noise), and is blocked when a critical dimension
|
|
252
|
-
* (e.g. `hallucination_free` for a legal agent) significantly regresses even if
|
|
253
|
-
* the net composite rose (anti-Goodhart).
|
|
254
|
-
*
|
|
255
|
-
* Two traps this module is built around (both produce a NEW false positive if
|
|
256
|
-
* gotten wrong):
|
|
257
|
-
* 1. PAIRING GRANULARITY — pairs by FULL `cellId` (`scenario:rep`), never by
|
|
258
|
-
* `scenarioId` (which averages reps away and destroys the within-pair
|
|
259
|
-
* variance reduction that makes a paired bootstrap tighter than unpaired).
|
|
260
|
-
* One paired observation per cell ⇒ reps multiply n.
|
|
261
|
-
* 2. SCALE — a judge may emit composites/dimensions on [0,1] or 0-100. The
|
|
262
|
-
* threshold + tolerance are interpreted in the judge's NATIVE scale; the
|
|
263
|
-
* per-dimension tolerance auto-scales off the observed baseline magnitudes
|
|
264
|
-
* so `-0.10` on [0,1] doesn't silently become a no-op on a 0-100 dimension.
|
|
265
|
-
*/
|
|
266
|
-
/** Tie fraction at/above which a gate annotates its verdict with the tie share.
|
|
267
|
-
* Tie-domination of the median bites structurally at >= 0.5 (the median is then
|
|
268
|
-
* 0 by construction); 0.4 is a softer warn threshold that flags a run APPROACHING
|
|
269
|
-
* that regime, so an operator sees it before the median goes fully blind. */
|
|
270
|
-
const TIE_WARN_FRACTION = .4;
|
|
271
|
-
/**
|
|
272
|
-
* Pair candidate vs baseline holdout observations by FULL cellId. `select`
|
|
273
|
-
* pulls the scalar from a cell's judge reports (composite, or a named
|
|
274
|
-
* dimension); a cell contributes the mean of `select` across its judges. Cells
|
|
275
|
-
* whose scenario is not in `scenarioIds`, or where `select` is undefined for
|
|
276
|
-
* every judge on either side, are skipped on BOTH sides so the arrays stay
|
|
277
|
-
* paired. Throws when the two maps disagree on which holdout cells exist — a
|
|
278
|
-
* load-bearing invariant: the baseline + winner holdout campaigns run the same
|
|
279
|
-
* scenarios with the same seed base, so their cellIds MUST align; a mismatch
|
|
280
|
-
* means a silent pairing bug, not a soft fallback.
|
|
281
|
-
*/
|
|
282
|
-
function pairHoldout(candidate, baseline, scenarioIds, select) {
|
|
283
|
-
const cellValue = (byCell, cellId) => {
|
|
284
|
-
const scores = byCell.get(cellId);
|
|
285
|
-
if (!scores) return void 0;
|
|
286
|
-
const vals = [];
|
|
287
|
-
for (const s of Object.values(scores)) {
|
|
288
|
-
if (s.failed === true) throw new Error(`pairHoldout: cell '${cellId}' contains a failed judge score`);
|
|
289
|
-
const v = select(s);
|
|
290
|
-
if (typeof v === "number" && !Number.isFinite(v)) throw new Error(`pairHoldout: cell '${cellId}' contains a non-finite selected score`);
|
|
291
|
-
if (typeof v === "number") vals.push(v);
|
|
292
|
-
}
|
|
293
|
-
if (vals.length === 0) return void 0;
|
|
294
|
-
return vals.reduce((a, b) => a + b, 0) / vals.length;
|
|
295
|
-
};
|
|
296
|
-
const inScope = (cellId) => scenarioIds.has(cellId.split(":")[0] ?? "");
|
|
297
|
-
const candCells = [...candidate.keys()].filter(inScope).sort();
|
|
298
|
-
const baseCells = [...baseline.keys()].filter(inScope).sort();
|
|
299
|
-
if (candCells.length !== baseCells.length || candCells.some((c, i) => c !== baseCells[i])) throw new Error(`pairHoldout: candidate/baseline holdout cells do not align — candidate=[${candCells.join(",")}] baseline=[${baseCells.join(",")}]. Both holdout campaigns must run the same scenarios with the same seed base.`);
|
|
300
|
-
const before = [];
|
|
301
|
-
const after = [];
|
|
302
|
-
const cellIds = [];
|
|
303
|
-
for (const cellId of candCells) {
|
|
304
|
-
const b = cellValue(baseline, cellId);
|
|
305
|
-
const a = cellValue(candidate, cellId);
|
|
306
|
-
if (b === void 0 && a === void 0) continue;
|
|
307
|
-
if (b === void 0 || a === void 0) throw new Error(`pairHoldout: cell '${cellId}' has a selected score on only one arm`);
|
|
308
|
-
before.push(b);
|
|
309
|
-
after.push(a);
|
|
310
|
-
cellIds.push(cellId);
|
|
311
|
-
}
|
|
312
|
-
return {
|
|
313
|
-
before,
|
|
314
|
-
after,
|
|
315
|
-
cellIds
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Significance of the held-out composite lift: ship only when the lower bound
|
|
320
|
-
* of the interval the outcome's shape ADMITS exceeds `deltaThreshold` (default
|
|
321
|
-
* 0 ⇒ "confidently positive"). Interpret `deltaThreshold` in the judge's native
|
|
322
|
-
* scale.
|
|
323
|
-
*
|
|
324
|
-
* The decision is delegated whole to {@link decidePairedPromotion}, the one
|
|
325
|
-
* copy of the rule (`src/paired-promotion-decision.ts`), which `HeldOutGate`
|
|
326
|
-
* also calls. That module's header carries the measurements; the short version
|
|
327
|
-
* is three guards a bare `bootstrap.low > threshold` does not have:
|
|
328
|
-
*
|
|
329
|
-
* - a two-point (pass/fail) outcome decides on Tango's SCORE interval, the
|
|
330
|
-
* only paired-binary construction that stays valid at a nonzero margin;
|
|
331
|
-
* - McNemar's exact test VETOES at any non-negative threshold;
|
|
332
|
-
* - a ZERO-WIDTH interval is refused rather than promoted, in either
|
|
333
|
-
* direction — [0,0] clears every negative threshold and [g,g] clears every
|
|
334
|
-
* threshold below g, and both are an absence of evidence, not a result.
|
|
335
|
-
*
|
|
336
|
-
* Measured on this function before those guards landed, at a nominal 5 %:
|
|
337
|
-
* 14.60 % false promotion at n = 40 on a paired-binary noninferiority boundary,
|
|
338
|
-
* and 88.50 % at n = 6 under a bounded asymmetric null whose true mean paired
|
|
339
|
-
* delta is exactly 0.
|
|
340
|
-
*
|
|
341
|
-
* At small n, where the percentile bootstrap is descriptive only, a
|
|
342
|
-
* pre-registered exact sign test still carries the bootstrap path.
|
|
343
|
-
*/
|
|
344
|
-
function heldoutSignificance(paired, opts = {}) {
|
|
345
|
-
const deltaThreshold = opts.deltaThreshold ?? 0;
|
|
346
|
-
const confidence = opts.confidence ?? .95;
|
|
347
|
-
const resamples = opts.resamples ?? 2e3;
|
|
348
|
-
const seed = opts.seed ?? 1337;
|
|
349
|
-
const statistic = opts.statistic ?? "mean";
|
|
350
|
-
const decision = decidePairedPromotion(paired.before, paired.after, {
|
|
351
|
-
confidence,
|
|
352
|
-
resamples,
|
|
353
|
-
statistic,
|
|
354
|
-
seed,
|
|
355
|
-
threshold: deltaThreshold,
|
|
356
|
-
minPairs: opts.minProductiveRuns
|
|
357
|
-
});
|
|
358
|
-
const bootstrap = decision.bootstrap ?? pairedBootstrap(paired.before, paired.after, {
|
|
359
|
-
confidence,
|
|
360
|
-
resamples,
|
|
361
|
-
statistic,
|
|
362
|
-
seed
|
|
363
|
-
});
|
|
364
|
-
const medianBootstrap = statistic === "median" ? bootstrap : pairedBootstrap(paired.before, paired.after, {
|
|
365
|
-
confidence,
|
|
366
|
-
resamples,
|
|
367
|
-
statistic: "median",
|
|
368
|
-
seed
|
|
369
|
-
});
|
|
370
|
-
const n = paired.before.length;
|
|
371
|
-
let ties = 0;
|
|
372
|
-
for (let i = 0; i < n; i += 1) {
|
|
373
|
-
const after = paired.after[i] ?? 0;
|
|
374
|
-
const before = paired.before[i] ?? 0;
|
|
375
|
-
if (Math.abs(after - before) < 1e-9) ties += 1;
|
|
376
|
-
}
|
|
377
|
-
const tieFraction = n === 0 ? 0 : ties / n;
|
|
378
|
-
return {
|
|
379
|
-
paired,
|
|
380
|
-
bootstrap,
|
|
381
|
-
medianBootstrap,
|
|
382
|
-
decision,
|
|
383
|
-
decisionStatistic: decision.statistic,
|
|
384
|
-
mcnemar: decision.mcnemar,
|
|
385
|
-
tieFraction,
|
|
386
|
-
n,
|
|
387
|
-
minimumRequired: decision.minimumPairs,
|
|
388
|
-
decisionMethod: decision.method,
|
|
389
|
-
pValue: decision.pValue,
|
|
390
|
-
significant: decision.promote,
|
|
391
|
-
fewRuns: !decision.sufficient
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
/** Detect the native scale of a set of scores: 0-100 when any magnitude clears
|
|
395
|
-
* 1.5, else [0,1]. Used to auto-scale the regression tolerance so a default
|
|
396
|
-
* expressed for [0,1] is not silently a no-op on a 0-100 dimension. */
|
|
397
|
-
function detectScale(values) {
|
|
398
|
-
return values.some((v) => Math.abs(v) > 1.5) ? 100 : 1;
|
|
399
|
-
}
|
|
400
|
-
/** Per-critical-dimension regression guard. For each dimension, pair the
|
|
401
|
-
* candidate vs baseline values by full cellId and bootstrap the paired delta;
|
|
402
|
-
* a dimension is "regressed" when the CI lower bound < −tolerance (conservative
|
|
403
|
-
* — blocks if the credible worst case exceeds tolerance, which is the right
|
|
404
|
-
* posture for safety dimensions like `hallucination_free`). When `tolerance`
|
|
405
|
-
* is omitted it auto-scales: 0.05 on [0,1], 5 on 0-100.
|
|
406
|
-
*
|
|
407
|
-
* The interval comes from {@link decidePairedPromotion}, so a pass/fail
|
|
408
|
-
* dimension is judged on Tango's score interval rather than a percentile
|
|
409
|
-
* bootstrap of the mean — `tolerance` is a NONZERO margin, and the bootstrap
|
|
410
|
-
* is not a valid interval at one. That matters most here because this guard
|
|
411
|
-
* fails OPEN by construction: `tolerance` is positive, so an interval pinned at
|
|
412
|
-
* [0,0] never satisfies `low < −tolerance` and a real regression on a safety
|
|
413
|
-
* dimension would be reported as `regressed: false`. On the median it fails the
|
|
414
|
-
* same way for the same reason — when most pairs tie, which is automatic for a
|
|
415
|
-
* pass/fail dimension on {0,1} and on the 0-100 encoding `detectScale` exists
|
|
416
|
-
* to support, the median CI collapses to [0,0]. Pass `statistic: 'median'` to
|
|
417
|
-
* restore the pre-0.134 behaviour. */
|
|
418
|
-
function dimensionRegressions(candidate, baseline, scenarioIds, criticalDimensions, opts = {}) {
|
|
419
|
-
const out = [];
|
|
420
|
-
for (const dim of criticalDimensions) {
|
|
421
|
-
const paired = pairHoldout(candidate, baseline, scenarioIds, (s) => s.dimensions[dim]);
|
|
422
|
-
if (paired.before.length === 0) continue;
|
|
423
|
-
const tolerance = opts.tolerance ?? .05 * detectScale([...paired.before, ...paired.after]);
|
|
424
|
-
const bootstrapStatistic = opts.statistic ?? "mean";
|
|
425
|
-
const shared = {
|
|
426
|
-
confidence: opts.confidence ?? .95,
|
|
427
|
-
resamples: opts.resamples ?? 2e3,
|
|
428
|
-
statistic: bootstrapStatistic,
|
|
429
|
-
seed: opts.seed ?? 1337
|
|
430
|
-
};
|
|
431
|
-
const guard = decidePairedPromotion(paired.before, paired.after, shared);
|
|
432
|
-
const regression = decidePairedPromotion(paired.after, paired.before, {
|
|
433
|
-
...shared,
|
|
434
|
-
threshold: tolerance
|
|
435
|
-
});
|
|
436
|
-
const bootstrap = guard.bootstrap ?? pairedBootstrap(paired.before, paired.after, shared);
|
|
437
|
-
out.push({
|
|
438
|
-
dimension: dim,
|
|
439
|
-
bootstrap,
|
|
440
|
-
bootstrapStatistic,
|
|
441
|
-
ci: {
|
|
442
|
-
low: guard.low,
|
|
443
|
-
high: guard.high
|
|
444
|
-
},
|
|
445
|
-
decisionStatistic: guard.statistic,
|
|
446
|
-
mcnemar: guard.mcnemar,
|
|
447
|
-
indeterminate: guard.indeterminate,
|
|
448
|
-
regressed: bootstrap.low < -tolerance || regression.promote,
|
|
449
|
-
tolerance,
|
|
450
|
-
n: paired.before.length
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
return out;
|
|
454
|
-
}
|
|
455
|
-
//#endregion
|
|
456
|
-
//#region src/campaign/gates/power-preflight.ts
|
|
457
|
-
/** Two-sided z for the common confidence levels; interpolation is overkill here. */
|
|
458
|
-
function zFor(confidence) {
|
|
459
|
-
if (confidence >= .99) return 2.576;
|
|
460
|
-
if (confidence >= .95) return 1.96;
|
|
461
|
-
if (confidence >= .9) return 1.645;
|
|
462
|
-
return 1.282;
|
|
463
|
-
}
|
|
464
|
-
/** Estimate the minimum detectable lift a paired-holdout improvement run can
|
|
465
|
-
* ship at a given budget, from the baseline holdout composites — call it BEFORE
|
|
466
|
-
* spending a search to learn whether the effect you are hunting is even
|
|
467
|
-
* observable at this holdout size and worker variance. */
|
|
468
|
-
function powerPreflight(opts) {
|
|
469
|
-
const composites = opts.baselineComposites.filter((v) => Number.isFinite(v));
|
|
470
|
-
if (composites.length < 3) throw new Error(`powerPreflight: need >= 3 finite baseline composites to estimate variance, got ${composites.length}`);
|
|
471
|
-
const deltaThreshold = opts.deltaThreshold ?? .05;
|
|
472
|
-
const confidence = opts.confidence ?? .95;
|
|
473
|
-
const n = opts.pairedN ?? composites.length;
|
|
474
|
-
if (n < 2) throw new Error(`powerPreflight: pairedN must be >= 2, got ${n}`);
|
|
475
|
-
const mean = composites.reduce((a, b) => a + b, 0) / composites.length;
|
|
476
|
-
const variance = composites.reduce((a, b) => a + (b - mean) * (b - mean), 0) / (composites.length - 1);
|
|
477
|
-
const sd = Math.sqrt(variance);
|
|
478
|
-
const z = zFor(confidence);
|
|
479
|
-
const mde = deltaThreshold + z * Math.SQRT2 * sd / Math.sqrt(n);
|
|
480
|
-
const scaleAssumed = composites.every((v) => v >= -.001 && v <= 1.5);
|
|
481
|
-
const headroom = Math.max(0, 1 - mean);
|
|
482
|
-
const underpowered = scaleAssumed && mde > headroom;
|
|
483
|
-
const sharedChannelCaveat = opts.sharedScorerChannel ? "Holdout and gate share one scoring channel: raising n/reps reduces only idiosyncratic noise — systematic judge bias remains and this MDE is a lower bound. Full debiasing needs an independent second scoring channel (different judge/benchmark family)." : void 0;
|
|
484
|
-
const recommendation = underpowered ? `UNDERPOWERED: minimum detectable lift ${mde.toFixed(3)} exceeds the ${headroom.toFixed(3)} headroom above the baseline (${mean.toFixed(3)}) — no achievable effect can ship at this budget. Raise paired n (scenarios x reps) to ~${Math.ceil((z * Math.SQRT2 * sd / Math.max(headroom - deltaThreshold, .01)) ** 2)} or reduce worker variance before searching.` : `Minimum detectable lift at n=${n}: ${mde.toFixed(3)} (baseline sd ${sd.toFixed(3)}). Effects smaller than this cannot clear the gate; budget the search for effects you believe exceed it.`;
|
|
485
|
-
return {
|
|
486
|
-
n,
|
|
487
|
-
sd,
|
|
488
|
-
mde,
|
|
489
|
-
baselineMean: mean,
|
|
490
|
-
headroom,
|
|
491
|
-
underpowered,
|
|
492
|
-
scaleAssumed,
|
|
493
|
-
deltaThreshold,
|
|
494
|
-
confidence,
|
|
495
|
-
...sharedChannelCaveat ? { sharedChannelCaveat } : {},
|
|
496
|
-
recommendation: sharedChannelCaveat ? `${recommendation} ${sharedChannelCaveat}` : recommendation
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
//#endregion
|
|
500
|
-
export { heldoutSignificance as a, pairedDecisionShape as c, dimensionRegressions as i, minimumPairsForPairedDeltaTest as l, TIE_WARN_FRACTION as n, pairHoldout as o, detectScale as r, decidePairedPromotion as s, powerPreflight as t, pairedDeltaTest as u };
|
|
501
|
-
|
|
502
|
-
//# sourceMappingURL=power-preflight-CFXm0Vjo.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"power-preflight-CFXm0Vjo.js","names":[],"sources":["../src/paired-delta-test.ts","../src/paired-promotion-decision.ts","../src/campaign/gates/statistical-heldout.ts","../src/campaign/gates/power-preflight.ts"],"sourcesContent":["import {\n type PairedBootstrapOptions,\n type PairedBootstrapResult,\n pairedBootstrap,\n pairedSignTest,\n} from './statistics'\n\nexport interface PairedDeltaTestOptions extends PairedBootstrapOptions {\n /** Smallest candidate-minus-baseline delta that counts as improvement. Default 0. */\n threshold?: number\n /** Caller-required paired observations. The exact test may impose a higher minimum. */\n minPairs?: number\n}\n\nexport interface PairedDeltaTestResult {\n bootstrap: PairedBootstrapResult\n method: 'bootstrap-ci' | 'exact-sign'\n /** Exact one-sided p-value below the bootstrap minimum; otherwise null. */\n pValue: number | null\n /** Effective observation minimum after accounting for confidence. */\n minimumPairs: number\n sufficient: boolean\n /**\n * The bootstrap interval has zero width (or is non-finite), so it carries no\n * information about how far the estimate could be wrong and cannot support a\n * decision in either direction. See {@link pairedDeltaTest}.\n */\n indeterminate: boolean\n significant: boolean\n}\n\n/** Smallest all-positive sample that can clear a one-sided exact sign test. */\nexport function minimumPairsForPairedDeltaTest(confidence = 0.95): number {\n if (!Number.isFinite(confidence) || confidence <= 0 || confidence >= 1) {\n throw new Error(\n `minimumPairsForPairedDeltaTest: confidence must be in (0,1), got ${confidence}`,\n )\n }\n const oneSidedAlpha = (1 - confidence) / 2\n return Math.ceil(Math.log2(1 / oneSidedAlpha))\n}\n\n/**\n * Tests whether a paired candidate-minus-baseline delta clears a threshold.\n *\n * At 20 or more pairs, the percentile bootstrap lower bound carries the\n * decision. Below that point the interval is descriptive only, so the function\n * switches to a pre-registered one-sided exact sign test. The exact path is\n * deliberately conservative: it requires both a point estimate above the\n * threshold and enough consistently positive paired differences.\n *\n * ## A zero-width interval is never significant\n *\n * When every paired delta is identical the resample distribution is a point\n * mass and the interval collapses: `[0, 0]` when all pairs tie, `[g, g]` on n\n * identical deltas of g. Neither says the effect is certain — both say the\n * sample carries no information about how far the estimate could be wrong, and\n * `low > threshold` then answers on the point estimate alone. It fails in both\n * directions: `[0, 0]` clears every NEGATIVE threshold, which is how a\n * tie-dominated pass/fail comparison laundered a regression into a\n * noninferiority pass, and `[g, g]` clears every threshold below g with no\n * spread behind it. Under a bounded asymmetric null whose true mean paired\n * delta is exactly 0 — 2 % of pairs dropping by 1.0, the rest gaining 0.0204 —\n * every sample that misses the drop is exactly that shape, and deciding on\n * `low > 0` promoted 65.65 % of samples at n = 20 against a nominal 5 %.\n *\n * So `indeterminate` is reported and `significant` is false whenever the\n * interval has zero width, on BOTH paths: at small n the exact sign test is a\n * test of the MEDIAN and a zero-spread sample is precisely where it stops\n * saying anything about the mean the caller is thresholding.\n *\n * `threshold` may be negative — that is a noninferiority margin, and it is the\n * regime the zero-width hole is worst in. For a two-point (pass/fail) outcome\n * the percentile bootstrap is not a valid interval at a nonzero margin at all;\n * use {@link decidePairedPromotion}, which routes those to Tango's score\n * interval, rather than thresholding this function's bootstrap directly.\n */\nexport function pairedDeltaTest(\n before: number[],\n after: number[],\n options: PairedDeltaTestOptions = {},\n): PairedDeltaTestResult {\n const threshold = options.threshold ?? 0\n if (!Number.isFinite(threshold)) {\n throw new Error(`pairedDeltaTest: threshold must be finite, got ${threshold}`)\n }\n const confidence = options.confidence ?? 0.95\n const exactMinimum = minimumPairsForPairedDeltaTest(confidence)\n const requestedMinimum = options.minPairs ?? exactMinimum\n if (!Number.isInteger(requestedMinimum) || requestedMinimum < 1) {\n throw new Error(`pairedDeltaTest: minPairs must be a positive integer, got ${requestedMinimum}`)\n }\n const minimumPairs = Math.max(requestedMinimum, exactMinimum)\n const bootstrap = pairedBootstrap(before, after, options)\n const sufficient = bootstrap.n >= minimumPairs\n // A point-mass resample distribution is an absence of evidence, not a\n // certainty, and it is the shape that clears every negative threshold. Both\n // paths refuse it: see the \"zero-width\" section of this function's docs.\n const indeterminate =\n bootstrap.n > 0 &&\n (!Number.isFinite(bootstrap.low) ||\n !Number.isFinite(bootstrap.high) ||\n bootstrap.low === bootstrap.high)\n\n if (bootstrap.gateEligible) {\n return {\n bootstrap,\n method: 'bootstrap-ci',\n pValue: null,\n minimumPairs,\n sufficient,\n indeterminate,\n significant: sufficient && !indeterminate && bootstrap.low > threshold,\n }\n }\n\n const differences = before.map((value, index) => after[index]! - value - threshold)\n const exact = pairedSignTest(differences, 'greater')\n const estimate = options.statistic === 'mean' ? bootstrap.mean : bootstrap.median\n return {\n bootstrap,\n method: 'exact-sign',\n pValue: exact.pValue,\n minimumPairs,\n sufficient,\n indeterminate,\n significant:\n sufficient &&\n !indeterminate &&\n estimate > threshold &&\n exact.pValue <= (1 - bootstrap.confidence) / 2,\n }\n}\n","/**\n * @module\n * ONE rule for \"does this paired interval clear a promotion threshold\".\n *\n * The rule below was derived on `HeldOutGate` (#479) after the same estimator\n * bug shipped twice. It then turned out that a SECOND gate — the composable\n * `heldOutGate`, plus everything else routed through `heldoutSignificance` —\n * still carried the original defect, because the rule had been written into one\n * gate's method body rather than into a shared function. Two copies of a\n * statistical rule is how a defect survives in one of them, so there is now\n * exactly one copy and both gates call it.\n *\n * Three things the rule does that a bare `pairedBootstrap(...).low > threshold`\n * does not:\n *\n * 1. **Two-point (pass/fail) outcomes decide on Tango's SCORE interval.** On a\n * pass/fail eval the paired delta vector is dominated by ties, so the\n * bootstrap of the mean is a resample of a lattice with three atoms and its\n * percentile interval is not valid at a nonzero margin. The score interval\n * (`pairedRiskDifferenceScore`) re-estimates the nuisance loss rate under\n * each hypothesised margin instead of fixing it at the observed value, which\n * is the only construction that stays a confidence interval as the margin\n * moves off zero — the regime every noninferiority threshold lives in.\n * Measured on the composable gate before this change, at a true risk\n * difference sitting exactly on the production caller's -0.05 margin and a\n * nominal 5 %: 14.60 % false promotion at n = 40 and 10.10 % at n = 76.\n * 2. **McNemar's exact test holds a VETO at every non-negative threshold.**\n * Redundant with the interval by construction and kept anyway, so that\n * swapping the estimator for one without that duality cannot silently\n * reintroduce \"promotes what the exact test refuses\". Witness: n = 6, b = 5,\n * c = 0 — no exact argument reaches alpha = 0.05 with 5 discordant pairs\n * (two-sided floor 2/2^5 = 0.0625), whatever an interval says. A NEGATIVE\n * threshold is a noninferiority question, which McNemar's test of \"no\n * difference\" is not the right test for, so the veto does not apply there.\n * 3. **A ZERO-WIDTH interval is refused, wherever it sits.** At [0, 0] it\n * cannot tell a gain from a regression and clears every negative threshold.\n * Away from zero it fails the opposite way: n identical positive deltas give\n * [g, g], which clears threshold 0 on no spread at all. Both are an absence\n * of evidence. Measured on the composable gate before this change, under a\n * bounded asymmetric null whose true mean paired delta is exactly 0: 88.50 %\n * false promotion at n = 6 and 65.65 % at n = 20 against a nominal 5 %.\n *\n * Orthogonal to the small-sample switch inside {@link pairedDeltaTest}: that\n * picks the TEST from the sample size (bootstrap CI at n >= 20, pre-registered\n * exact sign test below it), this picks the ESTIMATOR from the outcome's shape.\n * Both are needed — an exact sign test applied to a tie-pinned median is still\n * blind, and a mean bootstrap CI at n = 6 is still not a valid test.\n */\n\nimport { minimumPairsForPairedDeltaTest, pairedDeltaTest } from './paired-delta-test'\nimport {\n type PairedBootstrapResult,\n pairedBinaryScale,\n pairedDeltaTieFraction,\n pairedRiskDifferenceExact,\n pairedRiskDifferenceScore,\n} from './statistics'\n\n/** Which paired estimator produced the deciding interval. */\nexport type PairedDecisionStatistic =\n | 'paired_risk_difference'\n | 'mean_bootstrap'\n | 'median_bootstrap'\n\n/** Which test carried the decision, given the estimator and the sample size. */\nexport type PairedDecisionMethod = 'score-interval' | 'bootstrap-ci' | 'exact-sign'\n\n/** McNemar's exact paired-binary evidence, on the two-point path only. */\nexport interface PairedMcNemarEvidence {\n /** Discordant pairs the treatment won. */\n b: number\n /** Discordant pairs the control won. */\n c: number\n /** b + c — the only pairs carrying information. */\n nDiscordant: number\n /** Two-sided exact p-value. */\n pValue: number\n}\n\nexport interface PairedPromotionDecisionOptions {\n /** Smallest candidate-minus-baseline delta that counts as improvement, in the\n * caller's native units. May be negative (a noninferiority margin). Default 0. */\n threshold?: number\n /** Confidence level. Default 0.95. */\n confidence?: number\n /** Bootstrap resamples, on the paths where a bootstrap decides. Default 2000. */\n resamples?: number\n /** Deterministic bootstrap seed. Omitted ⇒ derived from the deltas. */\n seed?: number\n /** Caller-required paired observations. The exact test may impose a higher\n * minimum; the effective one is reported as `minimumPairs`. */\n minPairs?: number\n /**\n * `'mean'` (default) routes by SHAPE: a two-point (pass/fail) outcome on any\n * encoding decides on the score interval, everything else on the mean\n * bootstrap. `'median'` forces the median bootstrap on every input, including\n * shapes where it is structurally blind — kept for callers who want outlier\n * robustness on genuinely continuous outcomes and accept that cost.\n */\n statistic?: 'mean' | 'median'\n}\n\nexport interface PairedPromotionDecision {\n /** Paired observations supplied. */\n n: number\n /** Threshold the interval was judged against, native units. */\n threshold: number\n confidence: number\n statistic: PairedDecisionStatistic\n method: PairedDecisionMethod\n /** Common positive level of a two-point outcome ({0,1} ⇒ 1, {0,100} ⇒ 100),\n * or null when the outcome is not two-point. Non-null is exactly the\n * condition for the `paired_risk_difference` path, and it is the factor\n * `delta` / `low` / `high` were rescaled by. */\n binaryScale: number | null\n /** Exact-tie fraction over the paired deltas; null when there are no pairs. */\n tieFraction: number | null\n /** Point estimate of the DECIDING statistic, in the caller's native units. */\n delta: number\n /** Lower bound of the DECIDING interval, native units. */\n low: number\n /** Upper bound of the DECIDING interval, native units. */\n high: number\n /** The bootstrap that decided, or null when the score interval did. Callers\n * that need a bootstrap as a diagnostic on the two-point path compute their\n * own — it is not computed here, so the binary path costs no resamples. */\n bootstrap: PairedBootstrapResult | null\n /** McNemar's exact evidence, or null off the two-point path. */\n mcnemar: PairedMcNemarEvidence | null\n /** Exact one-sided sign-test p-value on the small-sample bootstrap path;\n * null otherwise. */\n pValue: number | null\n /** Effective observation minimum after accounting for confidence. */\n minimumPairs: number\n /** n >= minimumPairs. */\n sufficient: boolean\n /** The deciding interval is zero-width or non-finite — no evidence in either\n * direction, so it cannot clear any threshold on evidence. */\n indeterminate: boolean\n /** McNemar's exact test refuses at a non-negative threshold. */\n exactTestVetoes: boolean\n /** The deciding interval clears the threshold, ignoring the other two guards. */\n clearsThreshold: boolean\n /** `sufficient && !indeterminate && clearsThreshold && !exactTestVetoes` —\n * the whole rule. */\n promote: boolean\n /** What `delta` measures, for a reason string. */\n label: 'success-rate' | 'mean' | 'median'\n /** Why a zero-width interval is zero-width; empty when it is not. */\n indeterminateCause: string\n /** Sentence naming the test when the exact sign test decided; else empty. */\n methodDetail: string\n}\n\n/** The shape facts that pick the estimator, without computing an interval. */\nexport interface PairedDecisionShape {\n statistic: PairedDecisionStatistic\n /** Common positive level of a two-point outcome; null when not two-point. */\n binaryScale: number | null\n /** Exact-tie fraction over the paired deltas; null when there are no pairs. */\n tieFraction: number | null\n}\n\n/**\n * Which estimator {@link decidePairedPromotion} would use on this data, and the\n * shape facts behind it — for callers that must report the shape on a path\n * where no interval is computed at all (an early rejection, or zero pairs).\n * Cheap: no bootstrap, no interval.\n */\nexport function pairedDecisionShape(\n before: number[],\n after: number[],\n statistic: 'mean' | 'median' = 'mean',\n): PairedDecisionShape {\n const tieFraction = before.length === 0 ? null : pairedDeltaTieFraction(before, after)\n if (statistic === 'median') {\n return { statistic: 'median_bootstrap', binaryScale: null, tieFraction }\n }\n const binaryScale = pairedBinaryScale(before, after)\n if (binaryScale !== null) {\n return { statistic: 'paired_risk_difference', binaryScale, tieFraction }\n }\n return { statistic: 'mean_bootstrap', binaryScale: null, tieFraction }\n}\n\n/**\n * Decide whether a paired candidate-minus-baseline delta clears a promotion\n * threshold. `before` is the baseline arm, `after` the candidate arm, paired by\n * position. Throws on unequal lengths.\n */\nexport function decidePairedPromotion(\n before: number[],\n after: number[],\n options: PairedPromotionDecisionOptions = {},\n): PairedPromotionDecision {\n if (before.length !== after.length) {\n throw new Error(\n `decidePairedPromotion: unequal sample sizes (${before.length} vs ${after.length})`,\n )\n }\n const threshold = options.threshold ?? 0\n if (!Number.isFinite(threshold)) {\n throw new Error(`decidePairedPromotion: threshold must be finite, got ${threshold}`)\n }\n const confidence = options.confidence ?? 0.95\n const exactMinimum = minimumPairsForPairedDeltaTest(confidence)\n const requestedMinimum = options.minPairs ?? exactMinimum\n if (!Number.isInteger(requestedMinimum) || requestedMinimum < 1) {\n throw new Error(\n `decidePairedPromotion: minPairs must be a positive integer, got ${requestedMinimum}`,\n )\n }\n const minimumPairs = Math.max(requestedMinimum, exactMinimum)\n const n = before.length\n const sufficient = n >= minimumPairs\n const { binaryScale, tieFraction } = pairedDecisionShape(before, after, options.statistic)\n\n let core: {\n statistic: PairedDecisionStatistic\n method: PairedDecisionMethod\n delta: number\n low: number\n high: number\n bootstrap: PairedBootstrapResult | null\n mcnemar: PairedMcNemarEvidence | null\n pValue: number | null\n clearsThreshold: boolean\n label: PairedPromotionDecision['label']\n methodDetail: string\n }\n\n if (binaryScale !== null) {\n // Normalise the two-point encoding to {0,1} so the estimators see the\n // pass/fail structure, then rescale the answer back into the caller's\n // native units — the threshold is read in the units of the scores, so a\n // 0-100 pass/fail dimension must be gated in points, not in a rate.\n const unitControl = before.map((v) => v / binaryScale)\n const unitTreatment = after.map((v) => v / binaryScale)\n // TWO estimators with different jobs, because no single one does both.\n // `exact` is the authority on RD = 0 and supplies the veto; its\n // Clopper-Pearson interval conditions on the discordant count and is\n // therefore NOT a confidence interval at a nonzero margin. `score` is\n // Tango's, which is.\n const exact = pairedRiskDifferenceExact(unitControl, unitTreatment, confidence)\n const score = pairedRiskDifferenceScore(unitControl, unitTreatment, confidence)\n const low = score.lower * binaryScale\n core = {\n statistic: 'paired_risk_difference',\n method: 'score-interval',\n delta: score.riskDifference * binaryScale,\n low,\n high: score.upper * binaryScale,\n bootstrap: null,\n mcnemar: {\n b: exact.b,\n c: exact.c,\n nDiscordant: exact.nDiscordant,\n pValue: exact.pValue,\n },\n pValue: null,\n clearsThreshold: low > threshold,\n label: 'success-rate',\n methodDetail: '',\n }\n } else {\n const bootstrapStatistic = options.statistic === 'median' ? 'median' : 'mean'\n const test = pairedDeltaTest(before, after, {\n confidence,\n resamples: options.resamples,\n statistic: bootstrapStatistic,\n seed: options.seed,\n threshold,\n minPairs: options.minPairs,\n })\n const ci = test.bootstrap\n core = {\n statistic: bootstrapStatistic === 'mean' ? 'mean_bootstrap' : 'median_bootstrap',\n method: test.method,\n delta: bootstrapStatistic === 'mean' ? ci.mean : ci.median,\n low: ci.low,\n high: ci.high,\n bootstrap: ci,\n mcnemar: null,\n pValue: test.pValue,\n clearsThreshold: test.significant,\n label: bootstrapStatistic,\n methodDetail:\n test.method === 'exact-sign'\n ? ` Below ${test.minimumPairs} pairs the interval is descriptive only;` +\n ` the decision is the exact one-sided sign test, p=${fmt(test.pValue ?? 1)}.`\n : '',\n }\n }\n\n const indeterminate =\n !Number.isFinite(core.low) || !Number.isFinite(core.high) || core.low === core.high\n const indeterminateCause = !indeterminate\n ? ''\n : tieFraction === 1\n ? 'every paired delta is an exact tie'\n : core.mcnemar !== null && core.mcnemar.nDiscordant === 0\n ? 'every pair is concordant (0 discordant pairs)'\n : `the ${core.label} CI collapsed to a point at ${fmt(core.low)}`\n // Only at a non-negative threshold: a negative threshold asks a\n // noninferiority question, which McNemar's test of \"no difference\" does not\n // answer.\n const exactTestVetoes =\n core.mcnemar !== null && threshold >= 0 && !(core.mcnemar.pValue < 1 - confidence)\n\n return {\n n,\n threshold,\n confidence,\n binaryScale,\n tieFraction,\n minimumPairs,\n sufficient,\n indeterminate,\n indeterminateCause,\n exactTestVetoes,\n promote: sufficient && !indeterminate && core.clearsThreshold && !exactTestVetoes,\n ...core,\n }\n}\n\nfunction fmt(x: number): string {\n return x.toFixed(4)\n}\n","/**\n * Statistical held-out promotion machinery — the trustworthy core the\n * point-estimate `heldout-delta` gate lacked.\n *\n * The shipped false positive it prevents: a winner re-scored against the\n * baseline on the holdout read run-to-run model NOISE (e.g. 91 vs 95) as a\n * \"+4 lift\" and shipped, because the gate compared point estimates with no\n * confidence interval. Here we pair candidate vs baseline holdout observations\n * and bootstrap a CI on the paired delta — a candidate ships only when the CI\n * lower bound clears the effect-size threshold (the gain is real at the\n * confidence level, not noise), and is blocked when a critical dimension\n * (e.g. `hallucination_free` for a legal agent) significantly regresses even if\n * the net composite rose (anti-Goodhart).\n *\n * Two traps this module is built around (both produce a NEW false positive if\n * gotten wrong):\n * 1. PAIRING GRANULARITY — pairs by FULL `cellId` (`scenario:rep`), never by\n * `scenarioId` (which averages reps away and destroys the within-pair\n * variance reduction that makes a paired bootstrap tighter than unpaired).\n * One paired observation per cell ⇒ reps multiply n.\n * 2. SCALE — a judge may emit composites/dimensions on [0,1] or 0-100. The\n * threshold + tolerance are interpreted in the judge's NATIVE scale; the\n * per-dimension tolerance auto-scales off the observed baseline magnitudes\n * so `-0.10` on [0,1] doesn't silently become a no-op on a 0-100 dimension.\n */\n\nimport {\n decidePairedPromotion,\n type PairedDecisionMethod,\n type PairedDecisionStatistic,\n type PairedMcNemarEvidence,\n type PairedPromotionDecision,\n} from '../../paired-promotion-decision'\nimport {\n DECISION_PAIRED_DELTA_STATISTIC,\n type PairedBootstrapResult,\n pairedBootstrap,\n} from '../../statistics'\nimport type { JudgeScore } from '../types'\n\n/** Tie fraction at/above which a gate annotates its verdict with the tie share.\n * Tie-domination of the median bites structurally at >= 0.5 (the median is then\n * 0 by construction); 0.4 is a softer warn threshold that flags a run APPROACHING\n * that regime, so an operator sees it before the median goes fully blind. */\nexport const TIE_WARN_FRACTION = 0.4\n\nexport interface PairedHoldout {\n /** Baseline scalar per paired cell (same order as `after`/`cellIds`). */\n before: number[]\n /** Candidate scalar per paired cell. */\n after: number[]\n /** The full cellIds (`scenario:rep`) that paired, in order. */\n cellIds: string[]\n}\n\n/**\n * Pair candidate vs baseline holdout observations by FULL cellId. `select`\n * pulls the scalar from a cell's judge reports (composite, or a named\n * dimension); a cell contributes the mean of `select` across its judges. Cells\n * whose scenario is not in `scenarioIds`, or where `select` is undefined for\n * every judge on either side, are skipped on BOTH sides so the arrays stay\n * paired. Throws when the two maps disagree on which holdout cells exist — a\n * load-bearing invariant: the baseline + winner holdout campaigns run the same\n * scenarios with the same seed base, so their cellIds MUST align; a mismatch\n * means a silent pairing bug, not a soft fallback.\n */\nexport function pairHoldout(\n candidate: Map<string, Record<string, JudgeScore>>,\n baseline: Map<string, Record<string, JudgeScore>>,\n scenarioIds: Set<string>,\n select: (s: JudgeScore) => number | undefined,\n): PairedHoldout {\n const cellValue = (\n byCell: Map<string, Record<string, JudgeScore>>,\n cellId: string,\n ): number | undefined => {\n const scores = byCell.get(cellId)\n if (!scores) return undefined\n const vals: number[] = []\n for (const s of Object.values(scores)) {\n if (s.failed === true) {\n throw new Error(`pairHoldout: cell '${cellId}' contains a failed judge score`)\n }\n const v = select(s)\n if (typeof v === 'number' && !Number.isFinite(v)) {\n throw new Error(`pairHoldout: cell '${cellId}' contains a non-finite selected score`)\n }\n if (typeof v === 'number') vals.push(v)\n }\n if (vals.length === 0) return undefined\n return vals.reduce((a, b) => a + b, 0) / vals.length\n }\n\n const inScope = (cellId: string) => scenarioIds.has(cellId.split(':')[0] ?? '')\n const candCells = [...candidate.keys()].filter(inScope).sort()\n const baseCells = [...baseline.keys()].filter(inScope).sort()\n // Alignment invariant — the holdout campaigns share scenarios + seed, so the\n // cell sets must be identical. Differ ⇒ a real pairing bug; fail loud.\n if (candCells.length !== baseCells.length || candCells.some((c, i) => c !== baseCells[i])) {\n throw new Error(\n `pairHoldout: candidate/baseline holdout cells do not align — ` +\n `candidate=[${candCells.join(',')}] baseline=[${baseCells.join(',')}]. ` +\n `Both holdout campaigns must run the same scenarios with the same seed base.`,\n )\n }\n\n const before: number[] = []\n const after: number[] = []\n const cellIds: string[] = []\n for (const cellId of candCells) {\n const b = cellValue(baseline, cellId)\n const a = cellValue(candidate, cellId)\n // A scalar absent on both sides means that dimension was not scored. A\n // one-sided absence is asymmetric evidence loss, never a row to discard.\n if (b === undefined && a === undefined) continue\n if (b === undefined || a === undefined) {\n throw new Error(`pairHoldout: cell '${cellId}' has a selected score on only one arm`)\n }\n before.push(b)\n after.push(a)\n cellIds.push(cellId)\n }\n return { before, after, cellIds }\n}\n\nexport interface HeldoutSignificance {\n paired: PairedHoldout\n /**\n * The paired bootstrap on the requested statistic (MEAN by default — see the\n * tie note on `heldoutSignificance`).\n *\n * DIAGNOSTIC, not necessarily the interval the verdict keyed on. On a\n * two-point (pass/fail) outcome the decision routes to Tango's score interval\n * instead, because a percentile bootstrap of the mean over a three-atom\n * lattice is not a valid interval at a nonzero margin. Read\n * `decision.low`/`decision.high` for the interval that actually decided, and\n * `decisionStatistic` for which one it is.\n */\n bootstrap: PairedBootstrapResult\n /** The MEDIAN paired-delta bootstrap, reported as a diagnostic. When many\n * scenarios are tied (both sides solve them), the median is pinned near 0\n * regardless of the mean lift — comparing the two exposes tie-domination. */\n medianBootstrap: PairedBootstrapResult\n /**\n * The full promotion decision: which estimator the outcome's shape admits,\n * the interval it produced, McNemar's exact veto on the two-point path, and\n * whether the interval was zero-width (no evidence in either direction). The\n * single source of `significant`.\n */\n decision: PairedPromotionDecision\n /** Which paired estimator the verdict was decided on. */\n decisionStatistic: PairedDecisionStatistic\n /** McNemar's exact evidence on the two-point path; null otherwise. */\n mcnemar: PairedMcNemarEvidence | null\n /** Fraction of paired observations that are exact ties (|delta| < 1e-9). A\n * high tie fraction is WHY a median-based gate would have missed a real lift;\n * it is the observability the tie fix adds. */\n tieFraction: number\n /** n paired observations. */\n n: number\n /** Effective minimum after applying the bootstrap's hard statistical floor. */\n minimumRequired: number\n /** Statistical method that carried the decision. */\n decisionMethod: PairedDecisionMethod\n /** Exact one-sided p-value on the small-sample path; otherwise null. */\n pValue: number | null\n /** True iff n >= minimumRequired, the DECIDING interval has nonzero width,\n * its lower bound clears the threshold, and McNemar's exact test does not\n * veto at a non-negative threshold. */\n significant: boolean\n /** Set when n < minimumRequired — too little evidence to claim significance. */\n fewRuns: boolean\n}\n\nexport interface HeldoutSignificanceOptions {\n deltaThreshold?: number\n minProductiveRuns?: number\n confidence?: number\n resamples?: number\n /** Fixed by default for a deterministic, reproducible gate verdict. */\n seed?: number\n statistic?: 'mean' | 'median'\n}\n\n/**\n * Significance of the held-out composite lift: ship only when the lower bound\n * of the interval the outcome's shape ADMITS exceeds `deltaThreshold` (default\n * 0 ⇒ \"confidently positive\"). Interpret `deltaThreshold` in the judge's native\n * scale.\n *\n * The decision is delegated whole to {@link decidePairedPromotion}, the one\n * copy of the rule (`src/paired-promotion-decision.ts`), which `HeldOutGate`\n * also calls. That module's header carries the measurements; the short version\n * is three guards a bare `bootstrap.low > threshold` does not have:\n *\n * - a two-point (pass/fail) outcome decides on Tango's SCORE interval, the\n * only paired-binary construction that stays valid at a nonzero margin;\n * - McNemar's exact test VETOES at any non-negative threshold;\n * - a ZERO-WIDTH interval is refused rather than promoted, in either\n * direction — [0,0] clears every negative threshold and [g,g] clears every\n * threshold below g, and both are an absence of evidence, not a result.\n *\n * Measured on this function before those guards landed, at a nominal 5 %:\n * 14.60 % false promotion at n = 40 on a paired-binary noninferiority boundary,\n * and 88.50 % at n = 6 under a bounded asymmetric null whose true mean paired\n * delta is exactly 0.\n *\n * At small n, where the percentile bootstrap is descriptive only, a\n * pre-registered exact sign test still carries the bootstrap path.\n */\nexport function heldoutSignificance(\n paired: PairedHoldout,\n opts: HeldoutSignificanceOptions = {},\n): HeldoutSignificance {\n const deltaThreshold = opts.deltaThreshold ?? 0\n const confidence = opts.confidence ?? 0.95\n const resamples = opts.resamples ?? 2000\n const seed = opts.seed ?? 1337\n // DEFAULT to the MEAN paired delta, not the median. The median is destroyed by\n // TIES: whenever both baseline and candidate solve a holdout scenario (a common\n // case once the agent is decent — and INCREASINGLY common as you add holdout\n // scenarios for statistical power), that scenario contributes delta 0. When\n // >=50% of paired cells are ties the median is pinned at 0 regardless of a large,\n // consistent lift on the rest, and the gate holds a genuinely better candidate.\n // (Measured live, supervisor-lab run 6: 40 cells, 20 ties, MEAN +0.177, MEDIAN 0\n // → false hold. Doubling the holdout for \"power\" made it WORSE by adding ties.)\n // The mean equals the reported aggregate lift, ties correctly contribute 0\n // without dominating, and it is the textbook paired-comparison estimator; the\n // median is kept as a reported diagnostic. Callers wanting outlier-robustness at\n // the cost of tie-blindness can still pass `statistic: 'median'`.\n const statistic = opts.statistic ?? 'mean'\n const decision = decidePairedPromotion(paired.before, paired.after, {\n confidence,\n resamples,\n statistic,\n seed,\n threshold: deltaThreshold,\n minPairs: opts.minProductiveRuns,\n })\n // `decision.bootstrap` is null exactly when the score interval decided, so\n // the requested-statistic bootstrap is computed here for the diagnostic\n // field. Same two bootstraps as before on every path.\n const bootstrap =\n decision.bootstrap ??\n pairedBootstrap(paired.before, paired.after, { confidence, resamples, statistic, seed })\n const medianBootstrap =\n statistic === 'median'\n ? bootstrap\n : pairedBootstrap(paired.before, paired.after, {\n confidence,\n resamples,\n statistic: 'median',\n seed,\n })\n const n = paired.before.length\n let ties = 0\n for (let i = 0; i < n; i += 1) {\n const after = paired.after[i] ?? 0\n const before = paired.before[i] ?? 0\n if (Math.abs(after - before) < 1e-9) ties += 1\n }\n const tieFraction = n === 0 ? 0 : ties / n\n return {\n paired,\n bootstrap,\n medianBootstrap,\n decision,\n decisionStatistic: decision.statistic,\n mcnemar: decision.mcnemar,\n tieFraction,\n n,\n minimumRequired: decision.minimumPairs,\n decisionMethod: decision.method,\n pValue: decision.pValue,\n significant: decision.promote,\n fewRuns: !decision.sufficient,\n }\n}\n\nexport interface DimensionRegression {\n dimension: string\n /** Paired bootstrap on (candidate − baseline). DIAGNOSTIC on a pass/fail\n * dimension, where `ci` carries the interval that decided instead. */\n bootstrap: PairedBootstrapResult\n /** Which paired statistic `bootstrap.low` is the lower bound of. `'mean'`\n * unless the caller asked for the median. `bootstrap.median` still carries\n * the median point estimate either way. */\n bootstrapStatistic: 'median' | 'mean'\n /** The interval `regressed` was decided on, in the dimension's native units. */\n ci: { low: number; high: number }\n /** Which estimator produced `ci`. */\n decisionStatistic: PairedDecisionStatistic\n /** McNemar's exact evidence on a pass/fail dimension; null otherwise. */\n mcnemar: PairedMcNemarEvidence | null\n /** `ci` has zero width — no evidence in either direction. */\n indeterminate: boolean\n /** True iff the candidate may have regressed this dimension by more than\n * tolerance: the lower bound of the DECIDING interval on (candidate −\n * baseline) is below −tolerance, OR the exact small-sample test proves a drop\n * past tolerance. */\n regressed: boolean\n tolerance: number\n n: number\n}\n\n/** Detect the native scale of a set of scores: 0-100 when any magnitude clears\n * 1.5, else [0,1]. Used to auto-scale the regression tolerance so a default\n * expressed for [0,1] is not silently a no-op on a 0-100 dimension. */\nexport function detectScale(values: number[]): 1 | 100 {\n return values.some((v) => Math.abs(v) > 1.5) ? 100 : 1\n}\n\n/** Per-critical-dimension regression guard. For each dimension, pair the\n * candidate vs baseline values by full cellId and bootstrap the paired delta;\n * a dimension is \"regressed\" when the CI lower bound < −tolerance (conservative\n * — blocks if the credible worst case exceeds tolerance, which is the right\n * posture for safety dimensions like `hallucination_free`). When `tolerance`\n * is omitted it auto-scales: 0.05 on [0,1], 5 on 0-100.\n *\n * The interval comes from {@link decidePairedPromotion}, so a pass/fail\n * dimension is judged on Tango's score interval rather than a percentile\n * bootstrap of the mean — `tolerance` is a NONZERO margin, and the bootstrap\n * is not a valid interval at one. That matters most here because this guard\n * fails OPEN by construction: `tolerance` is positive, so an interval pinned at\n * [0,0] never satisfies `low < −tolerance` and a real regression on a safety\n * dimension would be reported as `regressed: false`. On the median it fails the\n * same way for the same reason — when most pairs tie, which is automatic for a\n * pass/fail dimension on {0,1} and on the 0-100 encoding `detectScale` exists\n * to support, the median CI collapses to [0,0]. Pass `statistic: 'median'` to\n * restore the pre-0.134 behaviour. */\nexport function dimensionRegressions(\n candidate: Map<string, Record<string, JudgeScore>>,\n baseline: Map<string, Record<string, JudgeScore>>,\n scenarioIds: Set<string>,\n criticalDimensions: string[],\n opts: {\n tolerance?: number\n confidence?: number\n resamples?: number\n seed?: number\n /** Paired statistic the CI is computed on. Default `'mean'` — see\n * {@link DECISION_PAIRED_DELTA_STATISTIC} for why the median is not. */\n statistic?: 'mean' | 'median'\n } = {},\n): DimensionRegression[] {\n const out: DimensionRegression[] = []\n for (const dim of criticalDimensions) {\n const paired = pairHoldout(candidate, baseline, scenarioIds, (s) => s.dimensions[dim])\n if (paired.before.length === 0) continue // dimension not scored on this judge\n const tolerance = opts.tolerance ?? 0.05 * detectScale([...paired.before, ...paired.after])\n const bootstrapStatistic = opts.statistic ?? DECISION_PAIRED_DELTA_STATISTIC\n const shared = {\n confidence: opts.confidence ?? 0.95,\n resamples: opts.resamples ?? 2000,\n statistic: bootstrapStatistic,\n seed: opts.seed ?? 1337,\n }\n const guard = decidePairedPromotion(paired.before, paired.after, shared)\n const regression = decidePairedPromotion(paired.after, paired.before, {\n ...shared,\n threshold: tolerance,\n })\n const bootstrap = guard.bootstrap ?? pairedBootstrap(paired.before, paired.after, shared)\n out.push({\n dimension: dim,\n bootstrap,\n bootstrapStatistic,\n ci: { low: guard.low, high: guard.high },\n decisionStatistic: guard.statistic,\n mcnemar: guard.mcnemar,\n indeterminate: guard.indeterminate,\n // Fires on EITHER burden of proof — see `floorBreached` in\n // `promotion-policy.ts` for the same rule and the reasoning. The CI arm\n // is the contract this interface and `default-production-gate`'s reason\n // string both state (\"CI.low < -tolerance\"), read off the DECIDING\n // interval; the exact-test arm adds the small-sample path where the\n // bootstrap interval is descriptive only.\n // The credible-worst-case arm stays on the BOOTSTRAP — see the same\n // decision in `floorBreached` (`promotion-policy.ts`). On a pass/fail\n // dimension the score interval is ±z²/(n+z²) even when every pair is\n // concordant, so reading the floor off it would flag an unchanged safety\n // dimension as regressed at any realistic n. The PROVEN-drop arm does use\n // the shared rule, which is what closes the fail-open hole that mattered:\n // a genuine pass/fail regression is now judged on an interval valid at\n // the nonzero `tolerance`, instead of a bootstrap that is pinned wherever\n // ties dominate.\n regressed: bootstrap.low < -tolerance || regression.promote,\n tolerance,\n n: paired.before.length,\n })\n }\n return out\n}\n","/**\n * Power preflight — \"can this budget detect the effect you are hunting?\"\n *\n * The failure it prevents (measured, twice): a live prompt-improvement campaign ran\n * 333 sandbox cells over 5.6 hours and produced a +0.08 holdout lift the ship gate\n * (paired bootstrap, CI.low > 0.05) could not distinguish from zero — because at\n * that holdout size and worker variance the MINIMUM DETECTABLE lift was larger than\n * any effect a prompt change plausibly produces. The budget was spent learning what\n * a 30-second calculation on the baseline cells already knew. No eval framework we\n * know of surfaces this; every underpowered improvement run everywhere ends in an\n * uninformative \"hold\".\n *\n * Model: the ship rule is `CI.low(paired Δ) > deltaThreshold`. Approximating the\n * bootstrap CI as normal, `CI.low ≈ effect − z·sd_Δ/√n`, so the smallest shippable\n * true effect is `MDE = deltaThreshold + z·sd_Δ/√n`. The paired-delta SD is unknown\n * before the candidate exists; we bound it by the zero-correlation case\n * `sd_Δ ≤ √2·sd_baseline` — a CONSERVATIVE (upper) MDE, which is the correct\n * direction for a warning. Pairing is per cell (`scenario:rep`), so reps multiply n.\n *\n * Standalone by design: feed it any baseline composites (a `gate:'none'` run, a\n * live-proof table) BEFORE budgeting the real search; `selfImprove` also attaches\n * it to every result and warns when the run was structurally unable to ship.\n */\n\nexport interface PowerPreflightOptions {\n /** Per-cell baseline composites on the HOLDOUT scenarios (one per scenario:rep cell). */\n baselineComposites: number[]\n /** Paired observations the budgeted comparison will produce\n * (holdout scenarios × reps). Defaults to `baselineComposites.length`. */\n pairedN?: number\n /** The ship gate's effect-size threshold. Default 0.05 (defaultProductionGate). */\n deltaThreshold?: number\n /** CI confidence the gate uses. Default 0.95. */\n confidence?: number\n /** True when the holdout is scored by the SAME judge/scorer family as the gate\n * (selfImprove's default composition — one judge scores everything). Under a\n * shared channel, raising paired n reduces only the IDIOSYNCRATIC noise share;\n * systematic judge bias is untouched, so the MDE here is a lower bound and the\n * only full debiaser is an independent second scoring channel\n * (recursive-self-improvement S1c, closed form in EXP-023 P0). Default false. */\n sharedScorerChannel?: boolean\n}\n\nexport interface PowerPreflight {\n /** Paired observations the comparison will have. */\n n: number\n /** Baseline per-cell composite standard deviation (the variance the effect must beat). */\n sd: number\n /** Minimum detectable lift: the smallest TRUE effect the gate could ship at this budget. */\n mde: number\n /** Baseline holdout composite mean. */\n baselineMean: number\n /** Headroom to a perfect 1.0 composite (the largest achievable lift on a [0,1] judge). */\n headroom: number\n /** True when even the largest achievable effect (headroom) is below the MDE —\n * the run is structurally unable to ship regardless of proposal quality.\n * Only asserted for [0,1]-scaled judges (see `scaleAssumed`). */\n underpowered: boolean\n /** True when composites look [0,1]-scaled; headroom/underpowered are only\n * meaningful under that convention (0-100 judges get mde/sd/n but no verdict). */\n scaleAssumed: boolean\n deltaThreshold: number\n confidence: number\n /** Set when the holdout shares the gate's scoring channel: more cells cannot\n * buy back systematic judge bias — treat the MDE as a lower bound. */\n sharedChannelCaveat?: string\n /** One actionable sentence for humans and logs. */\n recommendation: string\n}\n\n/** Two-sided z for the common confidence levels; interpolation is overkill here. */\nfunction zFor(confidence: number): number {\n if (confidence >= 0.99) return 2.576\n if (confidence >= 0.95) return 1.96\n if (confidence >= 0.9) return 1.645\n return 1.282\n}\n\n/** Estimate the minimum detectable lift a paired-holdout improvement run can\n * ship at a given budget, from the baseline holdout composites — call it BEFORE\n * spending a search to learn whether the effect you are hunting is even\n * observable at this holdout size and worker variance. */\nexport function powerPreflight(opts: PowerPreflightOptions): PowerPreflight {\n const composites = opts.baselineComposites.filter((v) => Number.isFinite(v))\n if (composites.length < 3) {\n throw new Error(\n `powerPreflight: need >= 3 finite baseline composites to estimate variance, got ${composites.length}`,\n )\n }\n const deltaThreshold = opts.deltaThreshold ?? 0.05\n const confidence = opts.confidence ?? 0.95\n const n = opts.pairedN ?? composites.length\n if (n < 2) throw new Error(`powerPreflight: pairedN must be >= 2, got ${n}`)\n\n const mean = composites.reduce((a, b) => a + b, 0) / composites.length\n const variance =\n composites.reduce((a, b) => a + (b - mean) * (b - mean), 0) / (composites.length - 1)\n const sd = Math.sqrt(variance)\n const z = zFor(confidence)\n const mde = deltaThreshold + (z * Math.SQRT2 * sd) / Math.sqrt(n)\n\n const scaleAssumed = composites.every((v) => v >= -0.001 && v <= 1.5)\n const headroom = Math.max(0, 1 - mean)\n const underpowered = scaleAssumed && mde > headroom\n\n const sharedChannelCaveat = opts.sharedScorerChannel\n ? 'Holdout and gate share one scoring channel: raising n/reps reduces only idiosyncratic noise — systematic judge bias remains and this MDE is a lower bound. Full debiasing needs an independent second scoring channel (different judge/benchmark family).'\n : undefined\n\n const recommendation = underpowered\n ? `UNDERPOWERED: minimum detectable lift ${mde.toFixed(3)} exceeds the ${headroom.toFixed(3)} headroom above the baseline (${mean.toFixed(3)}) — no achievable effect can ship at this budget. Raise paired n (scenarios x reps) to ~${Math.ceil(((z * Math.SQRT2 * sd) / Math.max(headroom - deltaThreshold, 0.01)) ** 2)} or reduce worker variance before searching.`\n : `Minimum detectable lift at n=${n}: ${mde.toFixed(3)} (baseline sd ${sd.toFixed(3)}). Effects smaller than this cannot clear the gate; budget the search for effects you believe exceed it.`\n\n return {\n n,\n sd,\n mde,\n baselineMean: mean,\n headroom,\n underpowered,\n scaleAssumed,\n deltaThreshold,\n confidence,\n ...(sharedChannelCaveat ? { sharedChannelCaveat } : {}),\n recommendation: sharedChannelCaveat\n ? `${recommendation} ${sharedChannelCaveat}`\n : recommendation,\n }\n}\n"],"mappings":";;;;AAgCA,SA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