@tangle-network/agent-eval 0.197.0 → 0.198.1
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 +55 -0
- package/README.md +3 -1
- package/dist/active-curriculum-B_Lc9kfO.js +61 -0
- package/dist/active-curriculum-B_Lc9kfO.js.map +1 -0
- package/dist/adapters/http.d.ts +2 -2
- package/dist/analyst/index.d.ts +5 -5
- package/dist/analyst/index.js +3 -3
- package/dist/{analyze-runs-B6gv7vAT.js → analyze-runs-DFbp2gB8.js} +5 -5
- package/dist/{analyze-runs-B6gv7vAT.js.map → analyze-runs-DFbp2gB8.js.map} +1 -1
- package/dist/{benchmark-command-DB7pxlks.js → benchmark-command-DKQuLrrD.js} +6 -5
- package/dist/{benchmark-command-DB7pxlks.js.map → benchmark-command-DKQuLrrD.js.map} +1 -1
- package/dist/benchmarks/index.d.ts +4 -3
- package/dist/benchmarks/index.d.ts.map +1 -1
- package/dist/benchmarks/index.js +3 -3
- package/dist/campaign/index.d.ts +5 -4
- package/dist/campaign/index.js +13 -11
- package/dist/{campaign-BUFSOI36.js → campaign-DRdKwxm-.js} +13 -12
- package/dist/{campaign-BUFSOI36.js.map → campaign-DRdKwxm-.js.map} +1 -1
- package/dist/{campaign-evidence-DJc60F9C.js → campaign-evidence-jL_U7Ikv.js} +2 -2
- package/dist/{campaign-evidence-DJc60F9C.js.map → campaign-evidence-jL_U7Ikv.js.map} +1 -1
- package/dist/cli.js +247 -13
- package/dist/cli.js.map +1 -1
- package/dist/contract/index.d.ts +7 -6
- package/dist/contract/index.js +9 -9
- package/dist/{default-registry-D2csUBBQ.d.ts → default-registry-oK9hHfX_.d.ts} +3 -3
- package/dist/{default-registry-D2csUBBQ.d.ts.map → default-registry-oK9hHfX_.d.ts.map} +1 -1
- package/dist/{define-agent-eval-ulRlLvse.d.ts → define-agent-eval-9JYoCkDI.d.ts} +5 -4
- package/dist/define-agent-eval-9JYoCkDI.d.ts.map +1 -0
- package/dist/{define-agent-eval-4J02MdF7.js → define-agent-eval-DkfcqaCF.js} +6 -6
- package/dist/{define-agent-eval-4J02MdF7.js.map → define-agent-eval-DkfcqaCF.js.map} +1 -1
- package/dist/diagnosis/index.js +1 -1
- package/dist/{dspy-rlm-engine-k_QdEBZo.js → dspy-rlm-engine-B5T43BkZ.js} +2 -2
- package/dist/{dspy-rlm-engine-k_QdEBZo.js.map → dspy-rlm-engine-B5T43BkZ.js.map} +1 -1
- package/dist/{engine-De2hfuiQ.d.ts → engine-Dc996kAg.d.ts} +2 -2
- package/dist/{engine-De2hfuiQ.d.ts.map → engine-Dc996kAg.d.ts.map} +1 -1
- package/dist/{eval-campaign-CXT2WYUe.js → eval-campaign-GapmPHIA.js} +2 -2
- package/dist/{eval-campaign-CXT2WYUe.js.map → eval-campaign-GapmPHIA.js.map} +1 -1
- package/dist/evaluation.d.ts +1 -1
- package/dist/experiment/index.d.ts +1 -1
- package/dist/experiment/index.js +8 -6
- package/dist/experiment/index.js.map +1 -1
- package/dist/{external-optimizer-process-_YIECYJ7.js → external-optimizer-process-CEXcCKqd.js} +2 -2
- package/dist/{external-optimizer-process-_YIECYJ7.js.map → external-optimizer-process-CEXcCKqd.js.map} +1 -1
- package/dist/{external-optimizer-subprocess-BrghTvEp.js → external-optimizer-subprocess-laM1-UDV.js} +2 -61
- package/dist/external-optimizer-subprocess-laM1-UDV.js.map +1 -0
- package/dist/fuzz.d.ts.map +1 -1
- package/dist/fuzz.js +2 -3
- package/dist/fuzz.js.map +1 -1
- package/dist/hosted/index.js +1 -1
- package/dist/{index-DJKZEldg.d.ts → index-BXJHJ_jE.d.ts} +12 -947
- package/dist/index-BXJHJ_jE.d.ts.map +1 -0
- package/dist/{index-CRsmcAGl.d.ts → index-DzQ6T34s.d.ts} +6 -6
- package/dist/{index-CRsmcAGl.d.ts.map → index-DzQ6T34s.d.ts.map} +1 -1
- package/dist/{index-kKECJfib.d.ts → index-lbwvO9vJ.d.ts} +3 -3
- package/dist/{index-kKECJfib.d.ts.map → index-lbwvO9vJ.d.ts.map} +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.js +15 -13
- package/dist/index.js.map +1 -1
- package/dist/jev.d.ts +1 -1
- package/dist/{llm-judge-fhkFQL1N.js → llm-judge-3ncNcWNT.js} +415 -1981
- package/dist/llm-judge-3ncNcWNT.js.map +1 -0
- package/dist/{matrix-C1X-fIVX.d.ts → matrix-BnksRaDD.d.ts} +2 -2
- package/dist/{matrix-C1X-fIVX.d.ts.map → matrix-BnksRaDD.d.ts.map} +1 -1
- package/dist/multiplicity-D9cjmStq.js +101 -0
- package/dist/multiplicity-D9cjmStq.js.map +1 -0
- package/dist/multishot/golden/index.d.ts +1 -1
- package/dist/multishot/golden/index.js +1 -1
- package/dist/multishot/index.d.ts +2 -2
- package/dist/multishot/index.js +1 -1
- package/dist/openapi.json +1 -1
- package/dist/{paired-arms-JSDcs2zx.js → paired-arms-DKZFVPt8.js} +4 -398
- package/dist/paired-arms-DKZFVPt8.js.map +1 -0
- package/dist/paired-binary-fzkwENI4.js +399 -0
- package/dist/paired-binary-fzkwENI4.js.map +1 -0
- package/dist/{paired-promotion-decision-DTKl6-G8.js → paired-promotion-decision-D5B1Cxc2.js} +78 -5
- package/dist/paired-promotion-decision-D5B1Cxc2.js.map +1 -0
- package/dist/{power-and-mde-BJOpt6pq.js → power-and-mde-K_CmO3dc.js} +3 -101
- package/dist/power-and-mde-K_CmO3dc.js.map +1 -0
- package/dist/{produced-state-1RnbLrSa.js → produced-state-qIhqN3V5.js} +3 -3
- package/dist/{produced-state-1RnbLrSa.js.map → produced-state-qIhqN3V5.js.map} +1 -1
- package/dist/{promotion-policy-Cy5OV8BV.js → promotion-policy-C6FAJvmZ.js} +3 -3
- package/dist/{promotion-policy-Cy5OV8BV.js.map → promotion-policy-C6FAJvmZ.js.map} +1 -1
- package/dist/reporting.js +3 -3
- package/dist/rl.d.ts +17 -39
- package/dist/rl.d.ts.map +1 -1
- package/dist/rl.js +5 -5
- package/dist/search/index.d.ts +1187 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +187 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search-kernel-CumYAjA3.js +2427 -0
- package/dist/search-kernel-CumYAjA3.js.map +1 -0
- package/dist/search-kernel-TLoiMMcq.d.ts +1185 -0
- package/dist/search-kernel-TLoiMMcq.d.ts.map +1 -0
- package/dist/{search-ledger-9W0g5FP6.js → search-ledger-BnUytR8X.js} +3 -1
- package/dist/search-ledger-BnUytR8X.js.map +1 -0
- package/dist/{search-shipper-CYbmJQx8.js → search-shipper-Cn8cxcyp.js} +2 -2
- package/dist/{search-shipper-CYbmJQx8.js.map → search-shipper-Cn8cxcyp.js.map} +1 -1
- package/dist/search-summary-dJOaZ3Dw.js +133 -0
- package/dist/search-summary-dJOaZ3Dw.js.map +1 -0
- package/dist/{semantic-concept-judge-Bh5lvKGg.js → semantic-concept-judge-2SE_kXGF.js} +2 -2
- package/dist/{semantic-concept-judge-Bh5lvKGg.js.map → semantic-concept-judge-2SE_kXGF.js.map} +1 -1
- package/dist/{sequential-C21_PP7F.js → sequential-Yz3OSskl.js} +2 -2
- package/dist/{sequential-C21_PP7F.js.map → sequential-Yz3OSskl.js.map} +1 -1
- package/dist/single-run-lock-fVu3MZWH.js +62 -0
- package/dist/single-run-lock-fVu3MZWH.js.map +1 -0
- package/dist/{skillopt-optimization-method-CHUcZ8w6.js → skillopt-optimization-method-BL_j6mX8.js} +8 -7
- package/dist/{skillopt-optimization-method-CHUcZ8w6.js.map → skillopt-optimization-method-BL_j6mX8.js.map} +1 -1
- package/dist/{statistical-heldout-DANVmyug.js → statistical-heldout-BAFDCo07.js} +2 -2
- package/dist/{statistical-heldout-DANVmyug.js.map → statistical-heldout-BAFDCo07.js.map} +1 -1
- package/dist/{statistical-heldout-BedVSZb2.d.ts → statistical-heldout-CMpxMjlQ.d.ts} +2 -2
- package/dist/{statistical-heldout-BedVSZb2.d.ts.map → statistical-heldout-CMpxMjlQ.d.ts.map} +1 -1
- package/dist/{store-tool-spans-CawP-WxM.d.ts → store-tool-spans-CUwWSXoj.d.ts} +3 -3
- package/dist/{store-tool-spans-CawP-WxM.d.ts.map → store-tool-spans-CUwWSXoj.d.ts.map} +1 -1
- package/dist/{summary-report-BMvou2oZ.js → summary-report-BeYnvddy.js} +4 -3
- package/dist/{summary-report-BMvou2oZ.js.map → summary-report-BeYnvddy.js.map} +1 -1
- package/dist/{tool-groups-B4JVrH3g.d.ts → tool-groups-DVJAR1GE.d.ts} +2 -2
- package/dist/tool-groups-DVJAR1GE.d.ts.map +1 -0
- package/dist/trace-repair/index.d.ts +1 -1
- package/dist/traces.d.ts +2 -2
- package/dist/tree-DxGfhISA.js +4100 -0
- package/dist/tree-DxGfhISA.js.map +1 -0
- package/dist/{types-B3jzCp0p.js → types-B3jzCp0p2.js} +1 -1
- package/dist/types-B3jzCp0p2.js.map +1 -0
- package/dist/{types-CjFDKMDe.d.ts → types-D94EanDL.d.ts} +2 -2
- package/dist/{types-CjFDKMDe.d.ts.map → types-D94EanDL.d.ts.map} +1 -1
- package/dist/{types-B2673PBj.d.ts → types-EBUav9Bu.d.ts} +8 -4
- package/dist/types-EBUav9Bu.d.ts.map +1 -0
- package/docs/campaign-proposers.md +2 -0
- package/docs/design/statistics-decisions.md +1 -1
- package/docs/search-ledger.md +145 -8
- package/docs/trace-contracts.md +1 -3
- package/package.json +6 -1
- package/dist/active-curriculum-OjIWgrUJ.js +0 -204
- package/dist/active-curriculum-OjIWgrUJ.js.map +0 -1
- package/dist/define-agent-eval-ulRlLvse.d.ts.map +0 -1
- package/dist/external-optimizer-subprocess-BrghTvEp.js.map +0 -1
- package/dist/index-DJKZEldg.d.ts.map +0 -1
- package/dist/llm-judge-fhkFQL1N.js.map +0 -1
- package/dist/paired-arms-JSDcs2zx.js.map +0 -1
- package/dist/paired-delta-test-BF-FEP8V.js +0 -78
- package/dist/paired-delta-test-BF-FEP8V.js.map +0 -1
- package/dist/paired-promotion-decision-DTKl6-G8.js.map +0 -1
- package/dist/power-and-mde-BJOpt6pq.js.map +0 -1
- package/dist/search-ledger-9W0g5FP6.js.map +0 -1
- package/dist/search-summary-CcavvYLe.js +0 -378
- package/dist/search-summary-CcavvYLe.js.map +0 -1
- package/dist/tool-groups-B4JVrH3g.d.ts.map +0 -1
- package/dist/types-B2673PBj.d.ts.map +0 -1
- package/dist/types-B3jzCp0p.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { p as CostProvenance } from "./cost-ledger-DbQdN3nO.js";
|
|
2
|
-
import { w as JudgeScore } from "./types-
|
|
2
|
+
import { w as JudgeScore } from "./types-EBUav9Bu.js";
|
|
3
3
|
import { o as MatrixResult } from "./index-DNgf5gyG.js";
|
|
4
4
|
import { AgentProfile } from "@tangle-network/agent-interface";
|
|
5
5
|
//#region src/multishot/types.d.ts
|
|
@@ -398,4 +398,4 @@ interface RunMultishotMatrixResult {
|
|
|
398
398
|
declare function runMultishotMatrix<TPersona extends MultishotPersona>(opts: RunMultishotMatrixOptions<TPersona>): Promise<RunMultishotMatrixResult>;
|
|
399
399
|
//#endregion
|
|
400
400
|
export { MultishotToolExecutor as A, MultishotFatalToolError as C, MultishotShape as D, MultishotResult as E, assertMultishotShotResult as F, MultishotTransportRequest as M, MultishotTransportResponse as N, MultishotShotResultError as O, MultishotTransportToolCall as P, MultishotDriverEmptyError as S, MultishotPersona as T, JudgeRunResult as _, MultishotCellOutput as a, runJudge as b, RunMultishotMatrixResult as c, MultishotShot as d, RunMultishotOptions as f, JudgeDimension as g, JudgeConfig as h, ConversationJudgeInput as i, MultishotTransport as j, MultishotToolDefinition as k, computeCellComposite as l, DEFAULT_JUDGE_MODEL as m, CellCompositeInput as n, MultishotJudges as o, runMultishot as p, CellCompositeScore as r, RunMultishotMatrixOptions as s, ArtifactJudgeInput as t, runMultishotMatrix as u, renderDimensions as v, MultishotMessage as w, MultishotArtifact as x, renderJsonFooter as y };
|
|
401
|
-
//# sourceMappingURL=matrix-
|
|
401
|
+
//# sourceMappingURL=matrix-BnksRaDD.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matrix-
|
|
1
|
+
{"version":3,"file":"matrix-BnksRaDD.d.ts","names":[],"sources":["../src/multishot/types.ts","../src/multishot/judges.ts","../src/multishot/multishot.ts","../src/multishot/matrix.ts"],"mappings":";;;;;UAIiB;EACf;EACA;EACA;EACA,YAAY;IAAQ;IAAY;IAAc,MAAM;;;UAGrC;EACf;EACA;EACA;IAAc;IAAc,MAAM;;EAClC;;UAGe;EACf,YAAY;EACZ,WAAW;EACX;EACA;;;EAGA;;;;;;;;EAQA,iBAAiB;;UAGF;EACf;EACA;IACE;IACA;IACA,YAAY;;;;;;UAOC;EACf;EACA,UAAU,MAAM;EAChB,QAAQ;EACR;EACA;EACA,SAAS;;UAGM;EACf;EACA;EACA;IAAY;IAAc;;;UAGX;EACf;IAAW;IAAyB,aAAa;;EACjD;IAAU;IAAwB;;;;EAGlC;;;;EAIA;;;;;;;;KASU,sBACV,KAAK,8BACF,QAAQ;KAED,yBACV,MAAM,yBACN;;EAEE,WAAW;EACX,SAAS;MAER;EAAU;EAAiB;;UAEf;;EAEf;;GAEC;;;;;;;;UASc,eAAe,iBAAiB;;EAE/C,eAAe,SAAS;;;EAGxB,2BAA2B,SAAS;;cAGzB,kCAAkC;WACjB;EAA5B,YAA4B;;cAMjB,gCAAgC;EAC3C,YAAY;;cAMD,iCAAiC;EAC5C,YAAY;;;;;;;;;;;;;;;;;;;iBAyBE,0BAA0B,yBAAyB,SAAS;;;cCvI/D;UAEI;;EAEf;;EAEA;;UAGe,YAAY;;EAE3B;;;EAGA,WAAW;;EAEX;;EAEA,YAAY;;EAEZ;;;EAGA,cAAc,OAAO;;EAErB;;UAGe;;EAEf,OAAO;;EAEP,MAAM;;iBAGc,SAAS,QAC7B,OAAO,YAAY,SACnB,OAAO,SACN,QAAQ;;;iBAsIK,iBAAiB,eAAe;;iBAKhC,iBAAiB,eAAe;;;UCxK/B,oBAAoB,iBAAiB;EACpD,SAAS;EACT,SAAS;;;EAGT,QAAQ,eAAe;;EAEvB,QAAQ;;EAER,gBAAgB,eAAe;;;;EAI/B,mBAAmB;EACnB;EACA;EACA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;EAGA,gBAAgB;;;;EAIhB,iBAAiB;;;EAGjB,gBAAgB;EAChB,SAAS;;;;;;;;;;;KAYC,cAAc,iBAAiB,qBACzC,MAAM,oBAAoB,cACvB,QAAQ;;;;;;;;;;;;;;;;;iBA2BS,aAAa,iBAAiB,kBAClD,MAAM,oBAAoB,YACzB,QAAQ;;;UClFM,uBAAuB,iBAAiB;EACvD,YAAY;EACZ,SAAS;;UAGM,mBAAmB,iBAAiB;EACnD,UAAU;EACV,SAAS;;UAGM,gBAAgB,iBAAiB;;EAEhD,cAAc,YAAY,uBAAuB;;EAEjD,aAAa,YAAY,mBAAmB;;EAE5C,iBAAiB,YAAY,mBAAmB;;EAEhD;;EAEA;;UAGe;EACf;EACA,cAAc;EACd;IACE,aAAa,MAAM;MAAe;MAAc;;IAChD;;EAEF;IACE,aAAa,MAAM;MAAe;MAAc;;IAChD;;;UAIa,0BAA0B,iBAAiB;;EAE1D,UAAU;IAAQ;IAAY,OAAO;;;EAErC,UAAU;;;EAGV,QAAQ,eAAe;;EAEvB,QAAQ,gBAAgB;;EAExB,QAAQ;;EAER,gBAAgB,eAAe;;EAE/B,mBAAmB;;EAEnB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;EAIA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;EAIA,gBAAgB;;EAEhB,iBAAiB;;;EAGjB,gBAAgB;;;;;;;;;;;;;;;EAehB,UAAU,cAAc;;;;;UAMT;EACf;EACA;EACA;;UAoBe;EACf,cAAc;;EAEd,cAAc,cAAc;;EAE5B,iBAAiB,cAAc;;;;;;;iBAQjB,qBAAqB,OAAO;EAC1C;EACA;EACA;EACA;;UAuBe;EACf,QAAQ,aAAa;;iBAGD,mBAAmB,iBAAiB,kBACxD,MAAM,0BAA0B,YAC/B,QAAQ"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { s as ValidationError } from "./errors-Dngq5h35.js";
|
|
2
|
+
//#region src/statistics/multiplicity.ts
|
|
3
|
+
/**
|
|
4
|
+
* Multiple-comparison corrections: family-wise error (Bonferroni, Holm) and
|
|
5
|
+
* false discovery rate (Benjamini-Hochberg), with inclusive rejection
|
|
6
|
+
* boundaries throughout.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Bonferroni adjustment: multiply every p-value by the test count, clamp at 1.
|
|
10
|
+
*
|
|
11
|
+
* Rejects at `p_adjusted ≤ alpha` — the boundary is inclusive, matching
|
|
12
|
+
* {@link holm}, which uniformly dominates this correction and must therefore
|
|
13
|
+
* never reject less. Validates its inputs on the same terms.
|
|
14
|
+
*/
|
|
15
|
+
function bonferroni(pValues, alpha = .05) {
|
|
16
|
+
assertAlpha("bonferroni", "alpha", alpha);
|
|
17
|
+
assertPValues("bonferroni", pValues);
|
|
18
|
+
const k = pValues.length;
|
|
19
|
+
const adjusted = pValues.map((p) => Math.min(1, p * k));
|
|
20
|
+
return {
|
|
21
|
+
adjusted,
|
|
22
|
+
significant: adjusted.map((p) => p <= alpha)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Holm step-down family-wise error adjustment.
|
|
27
|
+
*
|
|
28
|
+
* P-values are sorted from smallest to largest, multiplied by their remaining
|
|
29
|
+
* hypothesis count, and made monotonically non-decreasing before being mapped
|
|
30
|
+
* back to input order. This uniformly dominates plain Bonferroni while keeping
|
|
31
|
+
* strong family-wise error control under arbitrary dependence.
|
|
32
|
+
*/
|
|
33
|
+
function holm(pValues, alpha = .05) {
|
|
34
|
+
assertAlpha("holm", "alpha", alpha);
|
|
35
|
+
assertPValues("holm", pValues);
|
|
36
|
+
const count = pValues.length;
|
|
37
|
+
if (count === 0) return {
|
|
38
|
+
adjusted: [],
|
|
39
|
+
significant: []
|
|
40
|
+
};
|
|
41
|
+
const ordered = pValues.map((pValue, index) => ({
|
|
42
|
+
pValue,
|
|
43
|
+
index
|
|
44
|
+
})).sort((a, b) => a.pValue - b.pValue || a.index - b.index);
|
|
45
|
+
const adjusted = new Array(count);
|
|
46
|
+
let previous = 0;
|
|
47
|
+
for (let rank = 0; rank < count; rank++) {
|
|
48
|
+
const entry = ordered[rank];
|
|
49
|
+
const stepAdjusted = Math.min(1, entry.pValue * (count - rank));
|
|
50
|
+
previous = Math.max(previous, stepAdjusted);
|
|
51
|
+
adjusted[entry.index] = previous;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
adjusted,
|
|
55
|
+
significant: adjusted.map((pValue) => pValue <= alpha)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Benjamini–Hochberg false discovery rate. Returns adjusted q-values and
|
|
60
|
+
* significance at the target FDR; handles ties and preserves q monotonicity.
|
|
61
|
+
*
|
|
62
|
+
* Rejects at `q ≤ fdr` — the BH rule is inclusive at the boundary, so an
|
|
63
|
+
* exactly-`fdr` q-value is a discovery.
|
|
64
|
+
*/
|
|
65
|
+
function benjaminiHochberg(pValues, fdr = .05) {
|
|
66
|
+
assertAlpha("benjaminiHochberg", "fdr", fdr);
|
|
67
|
+
assertPValues("benjaminiHochberg", pValues);
|
|
68
|
+
const n = pValues.length;
|
|
69
|
+
if (n === 0) return {
|
|
70
|
+
qValues: [],
|
|
71
|
+
significant: []
|
|
72
|
+
};
|
|
73
|
+
const indexed = pValues.map((p, i) => ({
|
|
74
|
+
p,
|
|
75
|
+
i
|
|
76
|
+
})).sort((a, b) => a.p - b.p);
|
|
77
|
+
const q = new Array(n);
|
|
78
|
+
let minRight = 1;
|
|
79
|
+
for (let k = n - 1; k >= 0; k--) {
|
|
80
|
+
const rank = k + 1;
|
|
81
|
+
const entry = indexed[k];
|
|
82
|
+
const raw = n / rank * entry.p;
|
|
83
|
+
const bounded = Math.min(minRight, raw);
|
|
84
|
+
minRight = bounded;
|
|
85
|
+
q[entry.i] = Math.min(1, bounded);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
qValues: q,
|
|
89
|
+
significant: q.map((v) => v <= fdr)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function assertAlpha(fn, label, value) {
|
|
93
|
+
if (!Number.isFinite(value) || value <= 0 || value >= 1) throw new ValidationError(`${fn}: ${label} must be in (0,1), got ${value}`);
|
|
94
|
+
}
|
|
95
|
+
function assertPValues(fn, pValues) {
|
|
96
|
+
for (const [index, pValue] of pValues.entries()) if (!Number.isFinite(pValue) || pValue < 0 || pValue > 1) throw new ValidationError(`${fn}: pValues[${index}] must be in [0,1], got ${pValue}`);
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
export { bonferroni as n, holm as r, benjaminiHochberg as t };
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=multiplicity-D9cjmStq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiplicity-D9cjmStq.js","names":[],"sources":["../src/statistics/multiplicity.ts"],"sourcesContent":["/**\n * Multiple-comparison corrections: family-wise error (Bonferroni, Holm) and\n * false discovery rate (Benjamini-Hochberg), with inclusive rejection\n * boundaries throughout.\n */\n\nimport { ValidationError } from '../errors'\n\n/**\n * Bonferroni adjustment: multiply every p-value by the test count, clamp at 1.\n *\n * Rejects at `p_adjusted ≤ alpha` — the boundary is inclusive, matching\n * {@link holm}, which uniformly dominates this correction and must therefore\n * never reject less. Validates its inputs on the same terms.\n */\nexport function bonferroni(\n pValues: readonly number[],\n alpha = 0.05,\n): { adjusted: number[]; significant: boolean[] } {\n assertAlpha('bonferroni', 'alpha', alpha)\n assertPValues('bonferroni', pValues)\n const k = pValues.length\n const adjusted = pValues.map((p) => Math.min(1, p * k))\n return { adjusted, significant: adjusted.map((p) => p <= alpha) }\n}\n\n/**\n * Holm step-down family-wise error adjustment.\n *\n * P-values are sorted from smallest to largest, multiplied by their remaining\n * hypothesis count, and made monotonically non-decreasing before being mapped\n * back to input order. This uniformly dominates plain Bonferroni while keeping\n * strong family-wise error control under arbitrary dependence.\n */\nexport function holm(\n pValues: readonly number[],\n alpha = 0.05,\n): { adjusted: number[]; significant: boolean[] } {\n assertAlpha('holm', 'alpha', alpha)\n assertPValues('holm', pValues)\n const count = pValues.length\n if (count === 0) return { adjusted: [], significant: [] }\n\n const ordered = pValues\n .map((pValue, index) => ({ pValue, index }))\n .sort((a, b) => a.pValue - b.pValue || a.index - b.index)\n const adjusted = new Array<number>(count)\n let previous = 0\n for (let rank = 0; rank < count; rank++) {\n const entry = ordered[rank]!\n const stepAdjusted = Math.min(1, entry.pValue * (count - rank))\n previous = Math.max(previous, stepAdjusted)\n adjusted[entry.index] = previous\n }\n // Holm's rejection rule is inclusive at the adjusted alpha boundary.\n return { adjusted, significant: adjusted.map((pValue) => pValue <= alpha) }\n}\n\n/**\n * Benjamini–Hochberg false discovery rate. Returns adjusted q-values and\n * significance at the target FDR; handles ties and preserves q monotonicity.\n *\n * Rejects at `q ≤ fdr` — the BH rule is inclusive at the boundary, so an\n * exactly-`fdr` q-value is a discovery.\n */\nexport function benjaminiHochberg(\n pValues: readonly number[],\n fdr = 0.05,\n): { qValues: number[]; significant: boolean[] } {\n assertAlpha('benjaminiHochberg', 'fdr', fdr)\n assertPValues('benjaminiHochberg', pValues)\n const n = pValues.length\n if (n === 0) return { qValues: [], significant: [] }\n const indexed = pValues.map((p, i) => ({ p, i })).sort((a, b) => a.p - b.p)\n const q = new Array<number>(n)\n let minRight = 1\n for (let k = n - 1; k >= 0; k--) {\n const rank = k + 1\n const entry = indexed[k]!\n // (n/rank)·p, not (p·n)/rank: the latter lands one ULP above `fdr` at an\n // exact boundary (p = 0.05, n = 3, rank = 3 gives 0.05000000000000001),\n // which silently turns a discovery into a non-discovery. This is R's\n // `p.adjust(method = \"BH\")` formulation.\n const raw = (n / rank) * entry.p\n const bounded = Math.min(minRight, raw)\n minRight = bounded\n q[entry.i] = Math.min(1, bounded)\n }\n return { qValues: q, significant: q.map((v) => v <= fdr) }\n}\n\nfunction assertAlpha(fn: string, label: string, value: number): void {\n if (!Number.isFinite(value) || value <= 0 || value >= 1) {\n throw new ValidationError(`${fn}: ${label} must be in (0,1), got ${value}`)\n }\n}\n\nfunction assertPValues(fn: string, pValues: readonly number[]): void {\n for (const [index, pValue] of pValues.entries()) {\n if (!Number.isFinite(pValue) || pValue < 0 || pValue > 1) {\n throw new ValidationError(`${fn}: pValues[${index}] must be in [0,1], got ${pValue}`)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,WACd,SACA,QAAQ,KACwC;CAChD,YAAY,cAAc,SAAS,KAAK;CACxC,cAAc,cAAc,OAAO;CACnC,MAAM,IAAI,QAAQ;CAClB,MAAM,WAAW,QAAQ,KAAK,MAAM,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC;CACtD,OAAO;EAAE;EAAU,aAAa,SAAS,KAAK,MAAM,KAAK,KAAK;CAAE;AAClE;;;;;;;;;AAUA,SAAgB,KACd,SACA,QAAQ,KACwC;CAChD,YAAY,QAAQ,SAAS,KAAK;CAClC,cAAc,QAAQ,OAAO;CAC7B,MAAM,QAAQ,QAAQ;CACtB,IAAI,UAAU,GAAG,OAAO;EAAE,UAAU,CAAC;EAAG,aAAa,CAAC;CAAE;CAExD,MAAM,UAAU,QACb,KAAK,QAAQ,WAAW;EAAE;EAAQ;CAAM,EAAE,CAAC,CAC3C,MAAM,GAAG,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK;CAC1D,MAAM,WAAW,IAAI,MAAc,KAAK;CACxC,IAAI,WAAW;CACf,KAAK,IAAI,OAAO,GAAG,OAAO,OAAO,QAAQ;EACvC,MAAM,QAAQ,QAAQ;EACtB,MAAM,eAAe,KAAK,IAAI,GAAG,MAAM,UAAU,QAAQ,KAAK;EAC9D,WAAW,KAAK,IAAI,UAAU,YAAY;EAC1C,SAAS,MAAM,SAAS;CAC1B;CAEA,OAAO;EAAE;EAAU,aAAa,SAAS,KAAK,WAAW,UAAU,KAAK;CAAE;AAC5E;;;;;;;;AASA,SAAgB,kBACd,SACA,MAAM,KACyC;CAC/C,YAAY,qBAAqB,OAAO,GAAG;CAC3C,cAAc,qBAAqB,OAAO;CAC1C,MAAM,IAAI,QAAQ;CAClB,IAAI,MAAM,GAAG,OAAO;EAAE,SAAS,CAAC;EAAG,aAAa,CAAC;CAAE;CACnD,MAAM,UAAU,QAAQ,KAAK,GAAG,OAAO;EAAE;EAAG;CAAE,EAAE,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC;CAC1E,MAAM,IAAI,IAAI,MAAc,CAAC;CAC7B,IAAI,WAAW;CACf,KAAK,IAAI,IAAI,IAAI,GAAG,KAAK,GAAG,KAAK;EAC/B,MAAM,OAAO,IAAI;EACjB,MAAM,QAAQ,QAAQ;EAKtB,MAAM,MAAO,IAAI,OAAQ,MAAM;EAC/B,MAAM,UAAU,KAAK,IAAI,UAAU,GAAG;EACtC,WAAW;EACX,EAAE,MAAM,KAAK,KAAK,IAAI,GAAG,OAAO;CAClC;CACA,OAAO;EAAE,SAAS;EAAG,aAAa,EAAE,KAAK,MAAM,KAAK,GAAG;CAAE;AAC3D;AAEA,SAAS,YAAY,IAAY,OAAe,OAAqB;CACnE,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,SAAS,KAAK,SAAS,GACpD,MAAM,IAAI,gBAAgB,GAAG,GAAG,IAAI,MAAM,yBAAyB,OAAO;AAE9E;AAEA,SAAS,cAAc,IAAY,SAAkC;CACnE,KAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,QAAQ,GAC5C,IAAI,CAAC,OAAO,SAAS,MAAM,KAAK,SAAS,KAAK,SAAS,GACrD,MAAM,IAAI,gBAAgB,GAAG,GAAG,YAAY,MAAM,0BAA0B,QAAQ;AAG1F"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as MultishotResult, M as MultishotTransportRequest, T as MultishotPersona, c as RunMultishotMatrixResult, f as RunMultishotOptions, k as MultishotToolDefinition, s as RunMultishotMatrixOptions } from "../../matrix-
|
|
1
|
+
import { E as MultishotResult, M as MultishotTransportRequest, T as MultishotPersona, c as RunMultishotMatrixResult, f as RunMultishotOptions, k as MultishotToolDefinition, s as RunMultishotMatrixOptions } from "../../matrix-BnksRaDD.js";
|
|
2
2
|
//#region src/multishot/golden/compare.d.ts
|
|
3
3
|
interface CompareOptions {
|
|
4
4
|
/** Stop after this many mismatches. A structural divergence high in the
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as readCellSpend } from "../../matrix-pWinRMPl.js";
|
|
2
|
-
import { n as MultishotFatalToolError } from "../../types-
|
|
2
|
+
import { n as MultishotFatalToolError } from "../../types-B3jzCp0p2.js";
|
|
3
3
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
4
4
|
import { join, posix, relative, sep } from "node:path";
|
|
5
5
|
//#region src/multishot/golden/compare.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { w as JudgeScore } from "../types-
|
|
2
|
-
import { A as MultishotToolExecutor, C as MultishotFatalToolError, D as MultishotShape, E as MultishotResult, F as assertMultishotShotResult, M as MultishotTransportRequest, N as MultishotTransportResponse, O as MultishotShotResultError, P as MultishotTransportToolCall, S as MultishotDriverEmptyError, T as MultishotPersona, _ as JudgeRunResult, a as MultishotCellOutput, b as runJudge, c as RunMultishotMatrixResult, d as MultishotShot, f as RunMultishotOptions, g as JudgeDimension, h as JudgeConfig, i as ConversationJudgeInput, j as MultishotTransport, k as MultishotToolDefinition, l as computeCellComposite, m as DEFAULT_JUDGE_MODEL, n as CellCompositeInput, o as MultishotJudges, p as runMultishot, r as CellCompositeScore, s as RunMultishotMatrixOptions, t as ArtifactJudgeInput, u as runMultishotMatrix, v as renderDimensions, w as MultishotMessage, x as MultishotArtifact, y as renderJsonFooter } from "../matrix-
|
|
1
|
+
import { w as JudgeScore } from "../types-EBUav9Bu.js";
|
|
2
|
+
import { A as MultishotToolExecutor, C as MultishotFatalToolError, D as MultishotShape, E as MultishotResult, F as assertMultishotShotResult, M as MultishotTransportRequest, N as MultishotTransportResponse, O as MultishotShotResultError, P as MultishotTransportToolCall, S as MultishotDriverEmptyError, T as MultishotPersona, _ as JudgeRunResult, a as MultishotCellOutput, b as runJudge, c as RunMultishotMatrixResult, d as MultishotShot, f as RunMultishotOptions, g as JudgeDimension, h as JudgeConfig, i as ConversationJudgeInput, j as MultishotTransport, k as MultishotToolDefinition, l as computeCellComposite, m as DEFAULT_JUDGE_MODEL, n as CellCompositeInput, o as MultishotJudges, p as runMultishot, r as CellCompositeScore, s as RunMultishotMatrixOptions, t as ArtifactJudgeInput, u as runMultishotMatrix, v as renderDimensions, w as MultishotMessage, x as MultishotArtifact, y as renderJsonFooter } from "../matrix-BnksRaDD.js";
|
|
3
3
|
import { AgentProfile } from "@tangle-network/agent-interface";
|
|
4
4
|
//#region src/multishot/cost.d.ts
|
|
5
5
|
/**
|
package/dist/multishot/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as isModelPriced, n as estimateCost } from "../metrics-DOMpkoeb.js";
|
|
2
2
|
import { r as withCellSpend, t as runAgentMatrix } from "../matrix-pWinRMPl.js";
|
|
3
|
-
import { i as assertMultishotShotResult, n as MultishotFatalToolError, r as MultishotShotResultError, t as MultishotDriverEmptyError } from "../types-
|
|
3
|
+
import { i as assertMultishotShotResult, n as MultishotFatalToolError, r as MultishotShotResultError, t as MultishotDriverEmptyError } from "../types-B3jzCp0p2.js";
|
|
4
4
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
//#region src/multishot/cost.ts
|
package/dist/openapi.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"openapi": "3.1.0",
|
|
3
3
|
"info": {
|
|
4
4
|
"title": "@tangle-network/agent-eval — wire protocol",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.198.1",
|
|
6
6
|
"description": "HTTP and stdio RPC interface to agent-eval. The TypeScript runtime is the source of truth; this spec is the contract that cross-language clients (Python, Rust, Go) generate from.\n\nWire-protocol version: 1.1.0. Bumps on breaking changes to request/response schemas.",
|
|
7
7
|
"contact": {
|
|
8
8
|
"name": "Tangle Network",
|
|
@@ -1,401 +1,7 @@
|
|
|
1
1
|
import { s as ValidationError } from "./errors-Dngq5h35.js";
|
|
2
|
-
import { c as lnGamma, i as makeRng,
|
|
2
|
+
import { c as lnGamma, i as makeRng, o as symmetricTwoSampleSeed, r as binomialSignTwoSided, t as assertFiniteSample } from "./internal-BMFSR8Ns.js";
|
|
3
|
+
import { i as pairedRiskDifference, n as mcnemar } from "./paired-binary-fzkwENI4.js";
|
|
3
4
|
import { r as pairedBootstrap } from "./paired-tests-C8iCsioC.js";
|
|
4
|
-
//#region src/statistics/paired-binary.ts
|
|
5
|
-
/**
|
|
6
|
-
* Wilson score interval for a binomial proportion. Correct at small n and near
|
|
7
|
-
* 0/1, where the normal (Wald) approximation produces bounds outside [0, 1] and
|
|
8
|
-
* understates coverage. Use this for any pass-rate / hit-rate / realness-rate
|
|
9
|
-
* CI — the continuous `confidenceInterval` assumes the wrong distribution for a
|
|
10
|
-
* proportion. `n = 0 ⇒ {0, 0, 0}`.
|
|
11
|
-
*/
|
|
12
|
-
function wilson(successes, n, confidence = .95) {
|
|
13
|
-
if (n <= 0) return {
|
|
14
|
-
estimate: 0,
|
|
15
|
-
lower: 0,
|
|
16
|
-
upper: 0
|
|
17
|
-
};
|
|
18
|
-
if (successes < 0 || successes > n) throw new Error(`wilson: successes (${successes}) must be in [0, ${n}]`);
|
|
19
|
-
const z = zQuantile(1 - (1 - confidence) / 2);
|
|
20
|
-
const p = successes / n;
|
|
21
|
-
const z2 = z * z;
|
|
22
|
-
const denom = 1 + z2 / n;
|
|
23
|
-
const center = (p + z2 / (2 * n)) / denom;
|
|
24
|
-
const half = z * Math.sqrt((p * (1 - p) + z2 / (4 * n)) / n) / denom;
|
|
25
|
-
return {
|
|
26
|
-
estimate: p,
|
|
27
|
-
lower: Math.max(0, center - half),
|
|
28
|
-
upper: Math.min(1, center + half)
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Are these per-item outcomes binary (every value exactly 0 or 1)?
|
|
33
|
-
*
|
|
34
|
-
* The discriminator a promotion gate needs before choosing a paired statistic.
|
|
35
|
-
* On binary outcomes the paired delta vector lives in {-1, 0, +1} and is
|
|
36
|
-
* normally dominated by zeros (both arms solve, or both arms miss, most items),
|
|
37
|
-
* so its MEDIAN is pinned at exactly 0 no matter how large the real shift in
|
|
38
|
-
* success rate is — and a bootstrap CI on that median collapses to [0, 0].
|
|
39
|
-
* A gate keying on `ci.low > threshold` is then structurally unable to see
|
|
40
|
-
* either a gain or a regression. Detect this shape and switch to the
|
|
41
|
-
* paired-binary estimators ({@link mcnemar}, {@link pairedRiskDifference})
|
|
42
|
-
* instead of silently answering "no" forever.
|
|
43
|
-
*
|
|
44
|
-
* Empty input is NOT binary: there is no evidence of the outcome's shape, and
|
|
45
|
-
* defaulting an empty vector into the binary branch would pick a statistic on
|
|
46
|
-
* no data at all.
|
|
47
|
-
*
|
|
48
|
-
* NOT the right discriminator for a gate. It recognises the literal {0, 1}
|
|
49
|
-
* encoding and nothing else, so a pass/fail dimension emitted on 0-100 — which
|
|
50
|
-
* judges in this codebase do routinely — reads as non-binary, and a single
|
|
51
|
-
* partial-credit score in an otherwise pass/fail vector flips it to false while
|
|
52
|
-
* leaving the median just as blind. Gates want {@link pairedBinaryScale} (any
|
|
53
|
-
* two-point encoding). This predicate remains for callers that specifically
|
|
54
|
-
* mean "literally 0/1".
|
|
55
|
-
*/
|
|
56
|
-
function isBinaryOutcomeVector(values) {
|
|
57
|
-
if (values.length === 0) return false;
|
|
58
|
-
for (let i = 0; i < values.length; i++) {
|
|
59
|
-
const v = values[i];
|
|
60
|
-
if (v !== 0 && v !== 1) return false;
|
|
61
|
-
}
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* McNemar's test for paired binary outcomes — the correct significance test for
|
|
66
|
-
* "does treatment change the success rate vs control on the SAME items". Only
|
|
67
|
-
* discordant pairs (one arm right, the other wrong) carry information; concordant
|
|
68
|
-
* pairs are uninformative, so a paired t-test / two-proportion z-test on the raw
|
|
69
|
-
* rates is wrong here. The p-value is exact: under H0 the b "treatment-wins" are
|
|
70
|
-
* Binomial(b + c, 0.5), so the two-sided p is the doubled binomial tail — correct
|
|
71
|
-
* at the small discordant counts typical of eval runs (no continuity-corrected
|
|
72
|
-
* chi-square approximation needed, though it is returned as `statistic` for
|
|
73
|
-
* reference). Inputs are paired 0/1 (or boolean) arrays, control first to match
|
|
74
|
-
* the module's (before, after) convention. Throws on unequal lengths.
|
|
75
|
-
*/
|
|
76
|
-
function mcnemar(control, treatment) {
|
|
77
|
-
if (control.length !== treatment.length) throw new Error(`mcnemar: unequal sample sizes (${control.length} vs ${treatment.length})`);
|
|
78
|
-
const n = control.length;
|
|
79
|
-
let b = 0;
|
|
80
|
-
let c = 0;
|
|
81
|
-
for (let i = 0; i < n; i++) {
|
|
82
|
-
const ctrl = control[i] ? 1 : 0;
|
|
83
|
-
const treat = treatment[i] ? 1 : 0;
|
|
84
|
-
if (treat === 1 && ctrl === 0) b++;
|
|
85
|
-
else if (treat === 0 && ctrl === 1) c++;
|
|
86
|
-
}
|
|
87
|
-
const nDiscordant = b + c;
|
|
88
|
-
const statistic = nDiscordant === 0 ? 0 : (Math.abs(b - c) - 1) ** 2 / nDiscordant;
|
|
89
|
-
return {
|
|
90
|
-
n,
|
|
91
|
-
nDiscordant,
|
|
92
|
-
b,
|
|
93
|
-
c,
|
|
94
|
-
statistic,
|
|
95
|
-
pValue: binomialSignTwoSided(b, c)
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Paired risk difference (the effect-size companion to {@link mcnemar}): the
|
|
100
|
-
* change in success rate p(treatment) − p(control) on matched items, which for
|
|
101
|
-
* paired binary data equals (b − c) / n. The CI uses the paired variance from
|
|
102
|
-
* the discordant counts, not the independent-samples formula (which overstates
|
|
103
|
-
* the interval by ignoring the pairing). Inputs are paired 0/1 (or boolean)
|
|
104
|
-
* arrays, control first. Throws on unequal lengths.
|
|
105
|
-
*
|
|
106
|
-
* REPORTING ONLY — do NOT decide a promotion on this interval. The CI is a Wald
|
|
107
|
-
* normal approximation, which badly UNDERCOVERS when only a handful of pairs are
|
|
108
|
-
* discordant: at n = 3 with b = 2, c = 0 it returns [0.133, 1.000], excluding 0,
|
|
109
|
-
* while McNemar's exact test on the same data gives p = 0.50. A gate keying on
|
|
110
|
-
* `lower > 0` would promote noise. Use {@link pairedRiskDifferenceExact}, whose
|
|
111
|
-
* interval is dual to the exact test by construction, for any decision.
|
|
112
|
-
*/
|
|
113
|
-
function pairedRiskDifference(control, treatment, confidence = .95) {
|
|
114
|
-
if (control.length !== treatment.length) throw new Error(`pairedRiskDifference: unequal sample sizes (${control.length} vs ${treatment.length})`);
|
|
115
|
-
const n = control.length;
|
|
116
|
-
if (n === 0) return {
|
|
117
|
-
n: 0,
|
|
118
|
-
b: 0,
|
|
119
|
-
c: 0,
|
|
120
|
-
riskDifference: 0,
|
|
121
|
-
lower: 0,
|
|
122
|
-
upper: 0,
|
|
123
|
-
confidence
|
|
124
|
-
};
|
|
125
|
-
let b = 0;
|
|
126
|
-
let c = 0;
|
|
127
|
-
for (let i = 0; i < n; i++) {
|
|
128
|
-
const ctrl = control[i] ? 1 : 0;
|
|
129
|
-
const treat = treatment[i] ? 1 : 0;
|
|
130
|
-
if (treat === 1 && ctrl === 0) b++;
|
|
131
|
-
else if (treat === 0 && ctrl === 1) c++;
|
|
132
|
-
}
|
|
133
|
-
const rd = (b - c) / n;
|
|
134
|
-
const variance = (b + c - (b - c) ** 2 / n) / (n * n);
|
|
135
|
-
const half = zQuantile(1 - (1 - confidence) / 2) * Math.sqrt(Math.max(0, variance));
|
|
136
|
-
return {
|
|
137
|
-
n,
|
|
138
|
-
b,
|
|
139
|
-
c,
|
|
140
|
-
riskDifference: rd,
|
|
141
|
-
lower: Math.max(-1, rd - half),
|
|
142
|
-
upper: Math.min(1, rd + half),
|
|
143
|
-
confidence
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Paired risk difference with the EXACT CONDITIONAL interval — the estimator a
|
|
148
|
-
* promotion gate may decide on.
|
|
149
|
-
*
|
|
150
|
-
* Conditional on the number of discordant pairs m = b + c, the treatment-win
|
|
151
|
-
* count b is Binomial(m, π) with π = P(treatment wins | discordant), and the
|
|
152
|
-
* risk difference is an exact reparameterisation: RD = (2π − 1)·m/n. So a
|
|
153
|
-
* Clopper-Pearson exact interval for π maps straight onto RD. This buys the
|
|
154
|
-
* property the Wald interval in {@link pairedRiskDifference} does not have:
|
|
155
|
-
*
|
|
156
|
-
* **`lower > 0` ⟺ McNemar's exact test rejects at α = 1 − confidence.**
|
|
157
|
-
*
|
|
158
|
-
* Clopper-Pearson excludes π = 0.5 exactly when the two-sided exact binomial
|
|
159
|
-
* test of π = 0.5 rejects, and that test IS {@link mcnemar}'s p-value — so the
|
|
160
|
-
* interval and the test can never disagree, and a gate keyed on `lower` cannot
|
|
161
|
-
* promote what the exact test refuses. The exact p is returned in the same
|
|
162
|
-
* object so the two are impossible to compute apart.
|
|
163
|
-
*
|
|
164
|
-
* The interval is conservative (exact intervals over-cover; conditioning on m
|
|
165
|
-
* discards the concordant pairs' information about m itself). That is the
|
|
166
|
-
* correct direction for a promotion gate: it refuses more often, never less.
|
|
167
|
-
*
|
|
168
|
-
* With m = 0 there are no discordant pairs and π is not identified: the result
|
|
169
|
-
* is the degenerate [0, 0] with p = 1. That is NOT evidence of equivalence —
|
|
170
|
-
* callers must treat a zero-width interval as "cannot decide", not as "no
|
|
171
|
-
* difference". Inputs are paired 0/1 (or boolean) arrays, control first.
|
|
172
|
-
* Throws on unequal lengths.
|
|
173
|
-
*/
|
|
174
|
-
function pairedRiskDifferenceExact(control, treatment, confidence = .95) {
|
|
175
|
-
if (control.length !== treatment.length) throw new Error(`pairedRiskDifferenceExact: unequal sample sizes (${control.length} vs ${treatment.length})`);
|
|
176
|
-
if (confidence <= 0 || confidence >= 1) throw new Error(`pairedRiskDifferenceExact: confidence must be in (0,1), got ${confidence}`);
|
|
177
|
-
const n = control.length;
|
|
178
|
-
if (n === 0) return {
|
|
179
|
-
n: 0,
|
|
180
|
-
b: 0,
|
|
181
|
-
c: 0,
|
|
182
|
-
nDiscordant: 0,
|
|
183
|
-
riskDifference: 0,
|
|
184
|
-
lower: 0,
|
|
185
|
-
upper: 0,
|
|
186
|
-
confidence,
|
|
187
|
-
pValue: 1
|
|
188
|
-
};
|
|
189
|
-
let b = 0;
|
|
190
|
-
let c = 0;
|
|
191
|
-
for (let i = 0; i < n; i++) {
|
|
192
|
-
const ctrl = control[i] ? 1 : 0;
|
|
193
|
-
const treat = treatment[i] ? 1 : 0;
|
|
194
|
-
if (treat === 1 && ctrl === 0) b++;
|
|
195
|
-
else if (treat === 0 && ctrl === 1) c++;
|
|
196
|
-
}
|
|
197
|
-
const m = b + c;
|
|
198
|
-
const riskDifference = (b - c) / n;
|
|
199
|
-
const pValue = binomialSignTwoSided(b, c);
|
|
200
|
-
if (m === 0) return {
|
|
201
|
-
n,
|
|
202
|
-
b,
|
|
203
|
-
c,
|
|
204
|
-
nDiscordant: 0,
|
|
205
|
-
riskDifference: 0,
|
|
206
|
-
lower: 0,
|
|
207
|
-
upper: 0,
|
|
208
|
-
confidence,
|
|
209
|
-
pValue
|
|
210
|
-
};
|
|
211
|
-
const alpha = 1 - confidence;
|
|
212
|
-
const piLow = b === 0 ? 0 : betaQuantile(alpha / 2, b, m - b + 1);
|
|
213
|
-
const piHigh = b === m ? 1 : betaQuantile(1 - alpha / 2, b + 1, m - b);
|
|
214
|
-
const scale = m / n;
|
|
215
|
-
return {
|
|
216
|
-
n,
|
|
217
|
-
b,
|
|
218
|
-
c,
|
|
219
|
-
nDiscordant: m,
|
|
220
|
-
riskDifference,
|
|
221
|
-
lower: Math.max(-1, (2 * piLow - 1) * scale),
|
|
222
|
-
upper: Math.min(1, (2 * piHigh - 1) * scale),
|
|
223
|
-
confidence,
|
|
224
|
-
pValue
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
/** Inverse regularized incomplete beta by bisection on
|
|
228
|
-
* {@link regularizedIncompleteBeta}, which is monotone increasing in x. 80
|
|
229
|
-
* halvings of [0,1] resolve to ~8e-25, far past the continued fraction's own
|
|
230
|
-
* 3e-15 tolerance, so the quantile is as exact as the CDF it inverts. */
|
|
231
|
-
function betaQuantile(p, a, b) {
|
|
232
|
-
if (p <= 0) return 0;
|
|
233
|
-
if (p >= 1) return 1;
|
|
234
|
-
let lo = 0;
|
|
235
|
-
let hi = 1;
|
|
236
|
-
for (let i = 0; i < 80; i++) {
|
|
237
|
-
const mid = (lo + hi) / 2;
|
|
238
|
-
if (regularizedIncompleteBeta(mid, a, b) < p) lo = mid;
|
|
239
|
-
else hi = mid;
|
|
240
|
-
}
|
|
241
|
-
return (lo + hi) / 2;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Constrained MLE of q = P(treatment loses) under the hypothesis RD = `delta`.
|
|
245
|
-
*
|
|
246
|
-
* Profiling the two concordant cells out of the multinomial leaves
|
|
247
|
-
* `L(q) = b·log(q+delta) + c·log(q) + e·log(1 − 2q − delta)` with `e = n − b − c`,
|
|
248
|
-
* whose stationary point is the positive root of
|
|
249
|
-
* `2n·q² − [(b + c) − delta·(b + 3c + 2e)]·q − c·delta·(1 − delta) = 0`.
|
|
250
|
-
* At `delta = 0` this returns `(b + c) / 2n`, the familiar null.
|
|
251
|
-
*/
|
|
252
|
-
function constrainedLossRate(b, c, n, delta) {
|
|
253
|
-
const e = n - b - c;
|
|
254
|
-
const quadratic = 2 * n;
|
|
255
|
-
const linear = -(b + c - delta * (b + 3 * c + 2 * e));
|
|
256
|
-
const constant = -c * delta * (1 - delta);
|
|
257
|
-
const discriminant = linear * linear - 4 * quadratic * constant;
|
|
258
|
-
const root = discriminant > 0 ? Math.sqrt(discriminant) : 0;
|
|
259
|
-
const q = (-linear + root) / (2 * quadratic);
|
|
260
|
-
return Math.min(Math.max(q, Math.max(0, -delta)), Math.max(0, (1 - delta) / 2));
|
|
261
|
-
}
|
|
262
|
-
/** Tango's score statistic for H0: RD = `delta`. `Var(b − c) = n·(2q + delta −
|
|
263
|
-
* delta²)` under that hypothesis, evaluated at the constrained MLE of q. */
|
|
264
|
-
function tangoScore(b, c, n, delta) {
|
|
265
|
-
const numerator = b - c - n * delta;
|
|
266
|
-
const variance = n * (2 * constrainedLossRate(b, c, n, delta) + delta * (1 - delta));
|
|
267
|
-
if (!(variance > 0)) {
|
|
268
|
-
if (numerator === 0) return 0;
|
|
269
|
-
return numerator > 0 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
270
|
-
}
|
|
271
|
-
return numerator / Math.sqrt(variance);
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Paired risk difference with TANGO'S (1998) SCORE INTERVAL — the estimator a
|
|
275
|
-
* promotion gate may decide on **at a nonzero margin**.
|
|
276
|
-
*
|
|
277
|
-
* {@link pairedRiskDifferenceExact} conditions on the observed discordant count
|
|
278
|
-
* `m = b + c`, builds a Clopper-Pearson interval for the win share among those
|
|
279
|
-
* `m` pairs, and multiplies by the observed `m/n`. That is exact for testing
|
|
280
|
-
* RD = 0 — it is dual to McNemar — but it is NOT a confidence interval for the
|
|
281
|
-
* population risk difference at a nonzero margin, because the sampling
|
|
282
|
-
* variability of `m/n` itself is discarded. The gap is not academic: with the
|
|
283
|
-
* production caller's `pairedDeltaThreshold: -0.05`, a process whose true risk
|
|
284
|
-
* difference sits exactly on that margin clears a nominal-95 % `lower > margin`
|
|
285
|
-
* check 24.75 % of the time at n = 40 and 43.95 % at n = 76 (2000 replicates
|
|
286
|
-
* each) when the conditional interval decides.
|
|
287
|
-
*
|
|
288
|
-
* Tango's interval inverts the score test of RD = delta, which estimates the
|
|
289
|
-
* nuisance loss rate under each hypothesised delta instead of fixing it at the
|
|
290
|
-
* observed value, so `m` contributes its own uncertainty. It is the method
|
|
291
|
-
* `ratesci::scorepairci` uses for paired risk-difference noninferiority, and it
|
|
292
|
-
* is not conditional, so it stays valid as the margin moves away from zero.
|
|
293
|
-
*
|
|
294
|
-
* The bounds are found by bisecting `tangoScore(delta) = ±z` — the score is
|
|
295
|
-
* monotone decreasing in delta, so each crossing is unique. Inputs are paired
|
|
296
|
-
* 0/1 (or boolean) arrays, control first. Throws on unequal lengths.
|
|
297
|
-
*/
|
|
298
|
-
function pairedRiskDifferenceScore(control, treatment, confidence = .95) {
|
|
299
|
-
if (control.length !== treatment.length) throw new Error(`pairedRiskDifferenceScore: unequal sample sizes (${control.length} vs ${treatment.length})`);
|
|
300
|
-
if (confidence <= 0 || confidence >= 1) throw new Error(`pairedRiskDifferenceScore: confidence must be in (0,1), got ${confidence}`);
|
|
301
|
-
const n = control.length;
|
|
302
|
-
if (n === 0) return {
|
|
303
|
-
n: 0,
|
|
304
|
-
b: 0,
|
|
305
|
-
c: 0,
|
|
306
|
-
nDiscordant: 0,
|
|
307
|
-
riskDifference: 0,
|
|
308
|
-
lower: -1,
|
|
309
|
-
upper: 1,
|
|
310
|
-
confidence
|
|
311
|
-
};
|
|
312
|
-
let b = 0;
|
|
313
|
-
let c = 0;
|
|
314
|
-
for (let i = 0; i < n; i++) {
|
|
315
|
-
const ctrl = control[i] ? 1 : 0;
|
|
316
|
-
const treat = treatment[i] ? 1 : 0;
|
|
317
|
-
if (treat === 1 && ctrl === 0) b++;
|
|
318
|
-
else if (treat === 0 && ctrl === 1) c++;
|
|
319
|
-
}
|
|
320
|
-
const riskDifference = (b - c) / n;
|
|
321
|
-
const z = zQuantile(1 - (1 - confidence) / 2);
|
|
322
|
-
let lo = -1;
|
|
323
|
-
let hi = riskDifference;
|
|
324
|
-
for (let i = 0; i < 64; i++) {
|
|
325
|
-
const mid = (lo + hi) / 2;
|
|
326
|
-
if (tangoScore(b, c, n, mid) > z) lo = mid;
|
|
327
|
-
else hi = mid;
|
|
328
|
-
}
|
|
329
|
-
const lower = (lo + hi) / 2;
|
|
330
|
-
let ulo = riskDifference;
|
|
331
|
-
let uhi = 1;
|
|
332
|
-
for (let i = 0; i < 64; i++) {
|
|
333
|
-
const mid = (ulo + uhi) / 2;
|
|
334
|
-
if (tangoScore(b, c, n, mid) > -z) ulo = mid;
|
|
335
|
-
else uhi = mid;
|
|
336
|
-
}
|
|
337
|
-
const upper = (ulo + uhi) / 2;
|
|
338
|
-
return {
|
|
339
|
-
n,
|
|
340
|
-
b,
|
|
341
|
-
c,
|
|
342
|
-
nDiscordant: b + c,
|
|
343
|
-
riskDifference,
|
|
344
|
-
lower: Math.max(-1, lower),
|
|
345
|
-
upper: Math.min(1, upper),
|
|
346
|
-
confidence
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* The common positive level `s` such that EVERY value across both paired arms is
|
|
351
|
-
* exactly 0 or `s` — i.e. the outcome is pass/fail, whatever encoding it arrived
|
|
352
|
-
* in. Returns null when the outcomes are not two-point, when the two arms use
|
|
353
|
-
* different levels, or when no positive value was observed at all (all-zero
|
|
354
|
-
* arms: the level is not identified, and there is nothing to decide anyway).
|
|
355
|
-
*
|
|
356
|
-
* This is the scale-aware successor to {@link isBinaryOutcomeVector}, which only
|
|
357
|
-
* recognises literal {0, 1}. Judges in this codebase emit dimensions on 0-100 as
|
|
358
|
-
* well as [0,1] (see `detectScale` in `campaign/gates/statistical-heldout.ts`),
|
|
359
|
-
* so a pass/fail dimension routinely arrives as {0, 100} and a {0,1}-only test
|
|
360
|
-
* silently sends it down the median path that cannot see it. Any positive level
|
|
361
|
-
* is accepted, not just 1 and 100: for a two-point {0, s} outcome the mean paired
|
|
362
|
-
* delta is exactly s·(b − c)/n, so the binary estimators apply after dividing by
|
|
363
|
-
* s and rescaling the result back into the caller's native units.
|
|
364
|
-
*
|
|
365
|
-
* Non-finite values ⇒ null: an unusable outcome must not be classified as a
|
|
366
|
-
* clean pass/fail shape.
|
|
367
|
-
*/
|
|
368
|
-
function pairedBinaryScale(before, after) {
|
|
369
|
-
let level = null;
|
|
370
|
-
for (const arm of [before, after]) for (let i = 0; i < arm.length; i++) {
|
|
371
|
-
const v = arm[i];
|
|
372
|
-
if (!Number.isFinite(v)) return null;
|
|
373
|
-
if (v === 0) continue;
|
|
374
|
-
if (v < 0) return null;
|
|
375
|
-
if (level === null) level = v;
|
|
376
|
-
else if (v !== level) return null;
|
|
377
|
-
}
|
|
378
|
-
return level;
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Unbiased pass@k for code generation (Chen et al. 2021, "Evaluating Large
|
|
382
|
-
* Language Models Trained on Code"). Given `n` independent samples for one
|
|
383
|
-
* problem of which `c` pass, the probability that at least one of a random k of
|
|
384
|
-
* them passes is 1 − C(n−c, k) / C(n, k). Estimating pass@k as "did any of the
|
|
385
|
-
* first k pass" is biased high at small n; this is the variance-reduced estimator
|
|
386
|
-
* averaged implicitly over all k-subsets. Average the per-problem values across
|
|
387
|
-
* the suite for the corpus pass@k. Computed in the numerically stable product
|
|
388
|
-
* form. Requires 1 ≤ k ≤ n and 0 ≤ c ≤ n.
|
|
389
|
-
*/
|
|
390
|
-
function passAtK(n, c, k) {
|
|
391
|
-
if (!Number.isInteger(n) || !Number.isInteger(c) || !Number.isInteger(k)) throw new Error(`passAtK: n, c, k must be integers (got n=${n}, c=${c}, k=${k})`);
|
|
392
|
-
if (k < 1 || k > n || c < 0 || c > n) throw new Error(`passAtK: require 1 ≤ k ≤ n and 0 ≤ c ≤ n (got n=${n}, c=${c}, k=${k})`);
|
|
393
|
-
if (n - c < k) return 1;
|
|
394
|
-
let prob = 1;
|
|
395
|
-
for (let i = n - c + 1; i <= n; i++) prob *= 1 - k / i;
|
|
396
|
-
return 1 - prob;
|
|
397
|
-
}
|
|
398
|
-
//#endregion
|
|
399
5
|
//#region src/math/normal.ts
|
|
400
6
|
/**
|
|
401
7
|
* Standard normal cumulative distribution using Abramowitz and Stegun 7.1.26.
|
|
@@ -1053,6 +659,6 @@ function metricValue(row, name) {
|
|
|
1053
659
|
return v;
|
|
1054
660
|
}
|
|
1055
661
|
//#endregion
|
|
1056
|
-
export {
|
|
662
|
+
export { MANN_WHITNEY_EXACT_MAX_STATES as a, mannWhitneyU as c, DEFAULT_PERMUTATIONS as i, wilcoxonSignedRank as l, pairArms as n, MANN_WHITNEY_EXACT_MAX_WORK as o, pairRunRecords as r, WILCOXON_EXACT_MAX_N as s, comparePairedArms as t, normalCdf as u };
|
|
1057
663
|
|
|
1058
|
-
//# sourceMappingURL=paired-arms-
|
|
664
|
+
//# sourceMappingURL=paired-arms-DKZFVPt8.js.map
|