@tangle-network/agent-eval 1.0.29 → 1.0.31
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 +46 -0
- package/README.md +1 -0
- package/dist/adapters/http.d.ts +2 -2
- package/dist/{agent-profile-BF1WLMco.d.ts → agent-profile-BpLyM2kL.d.ts} +2 -2
- package/dist/{agent-profile-BF1WLMco.d.ts.map → agent-profile-BpLyM2kL.d.ts.map} +1 -1
- package/dist/{agent-profile-cell-3kYxUsK2.d.ts → agent-profile-cell-BTsrta0H.d.ts} +2 -9
- package/dist/agent-profile-cell-BTsrta0H.d.ts.map +1 -0
- package/dist/agent-profile-cell-CT5JYueM.js.map +1 -1
- package/dist/analyst/index.d.ts +13 -13
- package/dist/analyst/index.js +11 -11
- package/dist/{analyze-runs-BaziIw93.d.ts → analyze-runs-DfUDLaCk.d.ts} +6 -16
- package/dist/analyze-runs-DfUDLaCk.d.ts.map +1 -0
- package/dist/{analyze-runs-BCSHzqna.js → analyze-runs-YagfYgfx.js} +5 -5
- package/dist/{analyze-runs-BCSHzqna.js.map → analyze-runs-YagfYgfx.js.map} +1 -1
- package/dist/app-grade/index.d.ts +3 -5
- package/dist/app-grade/index.d.ts.map +1 -1
- package/dist/app-grade/index.js +2 -6
- package/dist/app-grade/index.js.map +1 -1
- package/dist/{benchmark-command-DRAHkn4D.js → benchmark-command-wpWa71ul.js} +11 -10
- package/dist/benchmark-command-wpWa71ul.js.map +1 -0
- package/dist/benchmarks/index.d.ts +7 -6
- package/dist/benchmarks/index.d.ts.map +1 -1
- package/dist/benchmarks/index.js +13 -5
- package/dist/benchmarks/index.js.map +1 -1
- package/dist/builder-eval/index.js +1 -1
- package/dist/{calibration-Cf-wpqqO.js → calibration-DE2WQmlX.js} +2 -2
- package/dist/{calibration-Cf-wpqqO.js.map → calibration-DE2WQmlX.js.map} +1 -1
- package/dist/campaign/index.d.ts +8 -8
- package/dist/campaign/index.js +14 -14
- package/dist/{campaign-Cqz2vk2p.js → campaign-CtdTo5em.js} +15 -15
- package/dist/{campaign-Cqz2vk2p.js.map → campaign-CtdTo5em.js.map} +1 -1
- package/dist/{campaign-evidence-CVNKiK0q.js → campaign-evidence-BS2-OSFN.js} +4 -4
- package/dist/{campaign-evidence-CVNKiK0q.js.map → campaign-evidence-BS2-OSFN.js.map} +1 -1
- package/dist/cli.js +9 -8
- package/dist/cli.js.map +1 -1
- package/dist/{cluster-bootstrap-B0MTOBRU.js → cluster-bootstrap-ClPYIWoX.js} +2 -2
- package/dist/{cluster-bootstrap-B0MTOBRU.js.map → cluster-bootstrap-ClPYIWoX.js.map} +1 -1
- package/dist/contract/index.d.ts +12 -11
- package/dist/contract/index.js +56 -34
- package/dist/contract/index.js.map +1 -1
- package/dist/{decision-point-CQOczIIH.js → decision-point-DvX1Z4Ue.js} +3 -3
- package/dist/{decision-point-CQOczIIH.js.map → decision-point-DvX1Z4Ue.js.map} +1 -1
- package/dist/{default-registry-DoIBhuS-.d.ts → default-registry-2Ziw-0sL.d.ts} +7 -7
- package/dist/{default-registry-DoIBhuS-.d.ts.map → default-registry-2Ziw-0sL.d.ts.map} +1 -1
- package/dist/{default-registry-D-xd7KxV.js → default-registry-DeiYGNKW.js} +3 -3
- package/dist/{default-registry-D-xd7KxV.js.map → default-registry-DeiYGNKW.js.map} +1 -1
- package/dist/{define-agent-eval-Be2Ser8j.d.ts → define-agent-eval-DmCV1TZo.d.ts} +7 -7
- package/dist/{define-agent-eval-Be2Ser8j.d.ts.map → define-agent-eval-DmCV1TZo.d.ts.map} +1 -1
- package/dist/{define-agent-eval-BLVewqJm.js → define-agent-eval-GgvRcpNL.js} +7 -7
- package/dist/{define-agent-eval-BLVewqJm.js.map → define-agent-eval-GgvRcpNL.js.map} +1 -1
- package/dist/diagnosis/index.d.ts +4 -3
- package/dist/diagnosis/index.d.ts.map +1 -1
- package/dist/diagnosis/index.js +1 -1
- package/dist/{dspy-rlm-engine-BS_jxE0P.js → dspy-rlm-engine-DJ_4E-PM.js} +3 -3
- package/dist/{dspy-rlm-engine-BS_jxE0P.js.map → dspy-rlm-engine-DJ_4E-PM.js.map} +1 -1
- package/dist/{engine-CPBhCLJR.d.ts → engine-yaSDTpEa.d.ts} +2 -2
- package/dist/{engine-CPBhCLJR.d.ts.map → engine-yaSDTpEa.d.ts.map} +1 -1
- package/dist/{eval-campaign-DpkToY_w.js → eval-campaign-bpSlwr6t.js} +2 -2
- package/dist/{eval-campaign-DpkToY_w.js.map → eval-campaign-bpSlwr6t.js.map} +1 -1
- package/dist/{evaluation-BjRgUyst.d.ts → evaluation-BQQ2ga5W.d.ts} +4 -4
- package/dist/{evaluation-BjRgUyst.d.ts.map → evaluation-BQQ2ga5W.d.ts.map} +1 -1
- package/dist/evaluation.d.ts +1 -1
- package/dist/{exact-types-DEnrf7NX.d.ts → exact-types-xrjBO9sb.d.ts} +2 -2
- package/dist/{exact-types-DEnrf7NX.d.ts.map → exact-types-xrjBO9sb.d.ts.map} +1 -1
- package/dist/execution-insight-B-My58JW.d.ts +14 -0
- package/dist/execution-insight-B-My58JW.d.ts.map +1 -0
- package/dist/experiment/index.d.ts +3 -3
- package/dist/experiment/index.js +7 -7
- package/dist/{exporters-BKZLt1Px.js → exporters-CfKvJlti.js} +70 -43
- package/dist/exporters-CfKvJlti.js.map +1 -0
- package/dist/{external-optimizer-process-m9xln7zN.js → external-optimizer-process-jiq4CZD0.js} +2 -2
- package/dist/{external-optimizer-process-m9xln7zN.js.map → external-optimizer-process-jiq4CZD0.js.map} +1 -1
- package/dist/{external-optimizer-subprocess-GO6s84Ov.js → external-optimizer-subprocess-DUOcOqly.js} +2 -2
- package/dist/{external-optimizer-subprocess-GO6s84Ov.js.map → external-optimizer-subprocess-DUOcOqly.js.map} +1 -1
- package/dist/failure-cluster-OvKQ0BTq.d.ts +32 -0
- package/dist/failure-cluster-OvKQ0BTq.d.ts.map +1 -0
- package/dist/{failure-cluster-DOoa7CBg.d.ts → failure-taxonomy-C_SQZ_SJ.d.ts} +2 -30
- package/dist/failure-taxonomy-C_SQZ_SJ.d.ts.map +1 -0
- package/dist/{feedback-trajectory-DxkG5EPi.d.ts → feedback-trajectory-BbwTH49m.d.ts} +3 -3
- package/dist/{feedback-trajectory-DxkG5EPi.d.ts.map → feedback-trajectory-BbwTH49m.d.ts.map} +1 -1
- package/dist/{findings-store-CTy71Lnr.js → findings-store-B7JpmgJx.js} +3 -3
- package/dist/{findings-store-CTy71Lnr.js.map → findings-store-B7JpmgJx.js.map} +1 -1
- package/dist/fuzz.js +1 -1
- package/dist/harness-session-lines-hAxOvmtP.js +205 -0
- package/dist/harness-session-lines-hAxOvmtP.js.map +1 -0
- package/dist/{hf-dataset-Bv114tzB.js → hf-dataset-Cc81I0vQ.js} +65 -141
- package/dist/hf-dataset-Cc81I0vQ.js.map +1 -0
- package/dist/hosted/index.js +1 -1
- package/dist/{index-BI9ecONy.d.ts → index-8hbrQwdR.d.ts} +26 -11
- package/dist/index-8hbrQwdR.d.ts.map +1 -0
- package/dist/{index-AjfEHHA8.d.ts → index-BFpDeCuS.d.ts} +7 -7
- package/dist/{index-AjfEHHA8.d.ts.map → index-BFpDeCuS.d.ts.map} +1 -1
- package/dist/{index-DHWFYUVW.d.ts → index-Bcy00QoN.d.ts} +87 -144
- package/dist/index-Bcy00QoN.d.ts.map +1 -0
- package/dist/{index-BriU7rfL.d.ts → index-BfxYoHGF.d.ts} +226 -6
- package/dist/index-BfxYoHGF.d.ts.map +1 -0
- package/dist/{index-D-0mg-eu.d.ts → index-BnqugnsM.d.ts} +31 -11
- package/dist/index-BnqugnsM.d.ts.map +1 -0
- package/dist/{index-C8a9Dyan.d.ts → index-BwJtNdaj.d.ts} +21 -24
- package/dist/index-BwJtNdaj.d.ts.map +1 -0
- package/dist/{index-VSN1IZQp.d.ts → index-Yec_iihg.d.ts} +4 -3
- package/dist/index-Yec_iihg.d.ts.map +1 -0
- package/dist/index.d.ts +34 -31
- package/dist/index.js +21 -21
- package/dist/{integrity-BHM4voOx.js → integrity-BSs9dgKW.js} +3 -3
- package/dist/{integrity-BHM4voOx.js.map → integrity-BSs9dgKW.js.map} +1 -1
- package/dist/{journal-CTX5uK-n.js → journal-F3msN9OD.js} +5 -399
- package/dist/journal-F3msN9OD.js.map +1 -0
- package/dist/journal-file-AekB57Er.js +400 -0
- package/dist/journal-file-AekB57Er.js.map +1 -0
- package/dist/judge-calibration-DnrbQaXI.d.ts +144 -0
- package/dist/judge-calibration-DnrbQaXI.d.ts.map +1 -0
- package/dist/{judge-gate-DsoI5tx7.js → judge-gate-MP1rHOB4.js} +2 -2
- package/dist/{judge-gate-DsoI5tx7.js.map → judge-gate-MP1rHOB4.js.map} +1 -1
- package/dist/ledger-core/index.js +3 -2
- package/dist/{ledger-core-24IxvmVY.js → ledger-core-COxrkkZi.js} +2 -2
- package/dist/{ledger-core-24IxvmVY.js.map → ledger-core-COxrkkZi.js.map} +1 -1
- package/dist/{llm-judge-DzAT7Wka.js → llm-judge-Cc33WVHX.js} +102 -27
- package/dist/llm-judge-Cc33WVHX.js.map +1 -0
- package/dist/{matrix-DdniPG_M.d.ts → matrix-D0fEU0fq.d.ts} +2 -2
- package/dist/{matrix-DdniPG_M.d.ts.map → matrix-D0fEU0fq.d.ts.map} +1 -1
- package/dist/meta-eval/index.d.ts +3 -3
- package/dist/meta-eval/index.js +6 -6
- package/dist/{mint-Ck92efNo.js → mint-g8elU5yW.js} +11 -35
- package/dist/mint-g8elU5yW.js.map +1 -0
- package/dist/multishot/golden/index.d.ts +1 -1
- package/dist/multishot/index.d.ts +2 -2
- package/dist/openapi.json +1 -1
- package/dist/{outcome-observations-DPkH-LHQ.js → outcome-observations-YFFmdGGW.js} +2 -2
- package/dist/{outcome-observations-DPkH-LHQ.js.map → outcome-observations-YFFmdGGW.js.map} +1 -1
- package/dist/{paired-arms-DjMEtYI9.js → paired-arms-CMSTbLqX.js} +2 -2
- package/dist/{paired-arms-DjMEtYI9.js.map → paired-arms-CMSTbLqX.js.map} +1 -1
- package/dist/{paired-promotion-decision-DawN2o0G.d.ts → paired-promotion-decision-BBSxTo-h.d.ts} +2 -2
- package/dist/{paired-promotion-decision-DawN2o0G.d.ts.map → paired-promotion-decision-BBSxTo-h.d.ts.map} +1 -1
- package/dist/{paired-promotion-decision-Bi9__RQS.js → paired-promotion-decision-BoWHWL1i.js} +2 -2
- package/dist/{paired-promotion-decision-Bi9__RQS.js.map → paired-promotion-decision-BoWHWL1i.js.map} +1 -1
- package/dist/{paired-promotion-power-D03cUj9E.js → paired-promotion-power-BXH3gzvs.js} +3 -3
- package/dist/{paired-promotion-power-D03cUj9E.js.map → paired-promotion-power-BXH3gzvs.js.map} +1 -1
- package/dist/{pareto-UzjB3ZBk.js → pareto-B226QGVD.js} +54 -47
- package/dist/pareto-B226QGVD.js.map +1 -0
- package/dist/pipelines/index.d.ts +1 -1
- package/dist/pipelines/index.js +1 -1
- package/dist/{prime-protocol-RUPtoYiI.d.ts → prime-protocol-3aHqoxSH.d.ts} +2 -2
- package/dist/{prime-protocol-RUPtoYiI.d.ts.map → prime-protocol-3aHqoxSH.d.ts.map} +1 -1
- package/dist/profile-cell.d.ts +2 -2
- package/dist/{promotion-gate-DG_PSJx_.d.ts → promotion-gate-D-ffRHFQ.d.ts} +3 -3
- package/dist/{promotion-gate-DG_PSJx_.d.ts.map → promotion-gate-D-ffRHFQ.d.ts.map} +1 -1
- package/dist/{promotion-policy-DCgftbnd.js → promotion-policy-CfgRPGx0.js} +4 -4
- package/dist/{promotion-policy-DCgftbnd.js.map → promotion-policy-CfgRPGx0.js.map} +1 -1
- package/dist/{proposal-findings-CS6LoGGp.js → proposal-findings-BFtn6Lcx.js} +2 -2
- package/dist/{proposal-findings-CS6LoGGp.js.map → proposal-findings-BFtn6Lcx.js.map} +1 -1
- package/dist/{registry-BqoX13FD.d.ts → registry-x5n4GeBx.d.ts} +3 -3
- package/dist/{registry-BqoX13FD.d.ts.map → registry-x5n4GeBx.d.ts.map} +1 -1
- package/dist/{release-confidence-B4Xxdpmn.js → release-confidence-baM0TqCx.js} +2 -2
- package/dist/{release-confidence-B4Xxdpmn.js.map → release-confidence-baM0TqCx.js.map} +1 -1
- package/dist/reporting.d.ts +13 -6
- package/dist/reporting.d.ts.map +1 -1
- package/dist/reporting.js +5 -5
- package/dist/{summary-report-9kwI6jFQ.d.ts → research-report-CUbXuGX-.d.ts} +6 -121
- package/dist/research-report-CUbXuGX-.d.ts.map +1 -0
- package/dist/{researcher-BuojS14L.d.ts → researcher-D6D7q9uQ.d.ts} +4 -4
- package/dist/{researcher-BuojS14L.d.ts.map → researcher-D6D7q9uQ.d.ts.map} +1 -1
- package/dist/{reward-hacking-BYiDFbIl.js → reward-hacking-DNiHskry.js} +2 -2
- package/dist/{reward-hacking-BYiDFbIl.js.map → reward-hacking-DNiHskry.js.map} +1 -1
- package/dist/{reward-hacking-CIdVwVe4.d.ts → reward-hacking-_CAip56v.d.ts} +2 -2
- package/dist/{reward-hacking-CIdVwVe4.d.ts.map → reward-hacking-_CAip56v.d.ts.map} +1 -1
- package/dist/rl.d.ts +35 -17
- package/dist/rl.d.ts.map +1 -1
- package/dist/rl.js +116 -24
- package/dist/rl.js.map +1 -1
- package/dist/rollout/index.d.ts +5 -6
- package/dist/rollout/index.js +7 -6
- package/dist/{rollout-B86tqluQ.js → rollout-CCh4eSB3.js} +6 -5
- package/dist/{rollout-B86tqluQ.js.map → rollout-CCh4eSB3.js.map} +1 -1
- package/dist/{rollout-nodes-DhSPJ2X7.js → rollout-nodes-DzmHlPAC.js} +2 -2
- package/dist/rollout-nodes-DzmHlPAC.js.map +1 -0
- package/dist/{rubric-predictive-validity-Bbi88Aut.d.ts → rubric-predictive-validity-BTN3nNhC.d.ts} +2 -2
- package/dist/{rubric-predictive-validity-Bbi88Aut.d.ts.map → rubric-predictive-validity-BTN3nNhC.d.ts.map} +1 -1
- package/dist/{rubric-predictive-validity-DL7gJ51F.js → rubric-predictive-validity-Cln7r56F.js} +2 -2
- package/dist/{rubric-predictive-validity-DL7gJ51F.js.map → rubric-predictive-validity-Cln7r56F.js.map} +1 -1
- package/dist/{run-record-DTTx9Ktr.js → run-record-CbrxTcCO.js} +2 -2
- package/dist/{run-record-DTTx9Ktr.js.map → run-record-CbrxTcCO.js.map} +1 -1
- package/dist/{run-record-pBlhZizT.d.ts → run-record-hti3ETmO.d.ts} +2 -2
- package/dist/{run-record-pBlhZizT.d.ts.map → run-record-hti3ETmO.d.ts.map} +1 -1
- package/dist/{runtime-rollouts-BNrm5nC_.js → runtime-rollouts-eO9qpGE9.js} +269 -55
- package/dist/{runtime-rollouts-BNrm5nC_.js.map → runtime-rollouts-eO9qpGE9.js.map} +1 -1
- package/dist/{schema-PDKQ_iNE.d.ts → schema-BTTzvMnn.d.ts} +24 -5
- package/dist/schema-BTTzvMnn.d.ts.map +1 -0
- package/dist/{schema-ChIZfnqY.js → schema-b18jtzZw.js} +56 -3
- package/dist/schema-b18jtzZw.js.map +1 -0
- package/dist/search/index.d.ts +2 -2
- package/dist/search/index.js +2 -2
- package/dist/{search-kernel-C4XnLKIW.d.ts → search-kernel-IpyhPDQd.d.ts} +287 -276
- package/dist/search-kernel-IpyhPDQd.d.ts.map +1 -0
- package/dist/{search-ledger-9liYyZf5.js → search-ledger-D_ENQh0d.js} +4 -4
- package/dist/{search-ledger-9liYyZf5.js.map → search-ledger-D_ENQh0d.js.map} +1 -1
- package/dist/{search-ledger-file-BhOdgYIt.js → search-ledger-file-J8Xh9pU_.js} +3 -3
- package/dist/{search-ledger-file-BhOdgYIt.js.map → search-ledger-file-J8Xh9pU_.js.map} +1 -1
- package/dist/{search-shipper-B6tMNx1I.js → search-shipper-BUf7s92U.js} +3 -3
- package/dist/{search-shipper-B6tMNx1I.js.map → search-shipper-BUf7s92U.js.map} +1 -1
- package/dist/{search-summary-CISbbxyr.js → search-summary-B2RpvkkQ.js} +5 -5
- package/dist/{search-summary-CISbbxyr.js.map → search-summary-B2RpvkkQ.js.map} +1 -1
- package/dist/{sequential-1-T2oi1_.d.ts → sequential-B-zx24n_.d.ts} +2 -2
- package/dist/{sequential-1-T2oi1_.d.ts.map → sequential-B-zx24n_.d.ts.map} +1 -1
- package/dist/{sequential-Ko7T-zvu.js → sequential-C6k0Wrb7.js} +3 -3
- package/dist/{sequential-Ko7T-zvu.js.map → sequential-C6k0Wrb7.js.map} +1 -1
- package/dist/{sequential-9TVb5Nu5.js → sequential-pLr7Ukad.js} +3 -3
- package/dist/{sequential-9TVb5Nu5.js.map → sequential-pLr7Ukad.js.map} +1 -1
- package/dist/{single-run-lock-CUj2tjxT.js → single-run-lock-BSKsoeQF.js} +2 -2
- package/dist/{single-run-lock-CUj2tjxT.js.map → single-run-lock-BSKsoeQF.js.map} +1 -1
- package/dist/{skillopt-optimization-method-BtX7xXDd.js → skillopt-optimization-method-BnR2yh-a.js} +11 -11
- package/dist/{skillopt-optimization-method-BtX7xXDd.js.map → skillopt-optimization-method-BnR2yh-a.js.map} +1 -1
- package/dist/{statistical-heldout-Bx1QUDNy.d.ts → statistical-heldout-AvgLVFp6.d.ts} +6 -6
- package/dist/{statistical-heldout-Bx1QUDNy.d.ts.map → statistical-heldout-AvgLVFp6.d.ts.map} +1 -1
- package/dist/{statistical-heldout-DLO4Ebos.js → statistical-heldout-BvcAVtof.js} +3 -3
- package/dist/{statistical-heldout-DLO4Ebos.js.map → statistical-heldout-BvcAVtof.js.map} +1 -1
- package/dist/{statistics-CvvC-MPv.js → statistics-CHs0jlsY.js} +184 -2
- package/dist/statistics-CHs0jlsY.js.map +1 -0
- package/dist/statistics.d.ts +2 -2
- package/dist/statistics.js +2 -2
- package/dist/{store-tool-spans-kCDPEwjL.d.ts → store-tool-spans-Bm0-YhHG.d.ts} +5 -5
- package/dist/{store-tool-spans-kCDPEwjL.d.ts.map → store-tool-spans-Bm0-YhHG.d.ts.map} +1 -1
- package/dist/{summary-report-BEhqoxrA.js → summary-report-BgdIlM_w.js} +3 -3
- package/dist/{summary-report-BEhqoxrA.js.map → summary-report-BgdIlM_w.js.map} +1 -1
- package/dist/summary-report-figures-BoFCoiOP.d.ts +112 -0
- package/dist/summary-report-figures-BoFCoiOP.d.ts.map +1 -0
- package/dist/supervisor-run/index.d.ts +32 -8
- package/dist/supervisor-run/index.d.ts.map +1 -1
- package/dist/supervisor-run/index.js +3 -3
- package/dist/{systemone-CSwi1hp-.d.ts → systemone-DPVj7a1g.d.ts} +7 -7
- package/dist/{systemone-CSwi1hp-.d.ts.map → systemone-DPVj7a1g.d.ts.map} +1 -1
- package/dist/{systemone-review-WpWosn3a.d.ts → systemone-review-CrnsTRav.d.ts} +2 -2
- package/dist/{systemone-review-WpWosn3a.d.ts.map → systemone-review-CrnsTRav.d.ts.map} +1 -1
- package/dist/systemone.d.ts +3 -3
- package/dist/systemone.js +1 -1
- package/dist/{tool-groups-Bcasvncd.d.ts → tool-groups-5pgmtTmE.d.ts} +3 -3
- package/dist/tool-groups-5pgmtTmE.d.ts.map +1 -0
- package/dist/{tool-waste-BqSmmPUz.js → tool-waste-DWSohyd3.js} +2 -2
- package/dist/{tool-waste-BqSmmPUz.js.map → tool-waste-DWSohyd3.js.map} +1 -1
- package/dist/{trace-questions-DI42jXPj.d.ts → trace-questions-ETZDn5ax.d.ts} +3 -3
- package/dist/{trace-questions-DI42jXPj.d.ts.map → trace-questions-ETZDn5ax.d.ts.map} +1 -1
- package/dist/trace-repair/index.d.ts +2 -2
- package/dist/trace-repair/index.js +1 -1
- package/dist/traces.d.ts +4 -4
- package/dist/training-admission-xaDOlQ_U.d.ts +31 -0
- package/dist/training-admission-xaDOlQ_U.d.ts.map +1 -0
- package/dist/{tree-D2cNtu9m.js → tree-DA_WI1aV.js} +5 -5
- package/dist/{tree-D2cNtu9m.js.map → tree-DA_WI1aV.js.map} +1 -1
- package/dist/{types-DbGSC2No.d.ts → types-Dtt11Ppr.d.ts} +2 -2
- package/dist/{types-DbGSC2No.d.ts.map → types-Dtt11Ppr.d.ts.map} +1 -1
- package/dist/{types-CLGrB4Sv.d.ts → types-_dfu6Ox2.d.ts} +4 -4
- package/dist/{types-CLGrB4Sv.d.ts.map → types-_dfu6Ox2.d.ts.map} +1 -1
- package/dist/{types-ByrbgALT.d.ts → types-qJwFZTqa.d.ts} +7 -6
- package/dist/types-qJwFZTqa.d.ts.map +1 -0
- package/dist/{types-CEgIBy0W.d.ts → types-rf0yhJmW.d.ts} +3 -3
- package/dist/{types-CEgIBy0W.d.ts.map → types-rf0yhJmW.d.ts.map} +1 -1
- package/dist/wire/index.d.ts +1 -1
- package/docs/adopt-stack.md +2 -0
- package/docs/concepts.md +4 -1
- package/docs/design/statistics-decisions.md +17 -0
- package/docs/rollout.md +124 -4
- package/docs/search-ledger.md +18 -1
- package/docs/trace-analysis.md +11 -3
- package/package.json +3 -3
- package/dist/agent-profile-cell-3kYxUsK2.d.ts.map +0 -1
- package/dist/analyze-runs-BaziIw93.d.ts.map +0 -1
- package/dist/benchmark-command-DRAHkn4D.js.map +0 -1
- package/dist/exporters-BKZLt1Px.js.map +0 -1
- package/dist/exporters-dQKYD_Zo.d.ts +0 -159
- package/dist/exporters-dQKYD_Zo.d.ts.map +0 -1
- package/dist/failure-cluster-DOoa7CBg.d.ts.map +0 -1
- package/dist/hf-dataset-Bv114tzB.js.map +0 -1
- package/dist/index-BI9ecONy.d.ts.map +0 -1
- package/dist/index-BriU7rfL.d.ts.map +0 -1
- package/dist/index-C8a9Dyan.d.ts.map +0 -1
- package/dist/index-D-0mg-eu.d.ts.map +0 -1
- package/dist/index-DHWFYUVW.d.ts.map +0 -1
- package/dist/index-VSN1IZQp.d.ts.map +0 -1
- package/dist/journal-CTX5uK-n.js.map +0 -1
- package/dist/llm-judge-DzAT7Wka.js.map +0 -1
- package/dist/mint-Ck92efNo.js.map +0 -1
- package/dist/pareto-UzjB3ZBk.js.map +0 -1
- package/dist/reward-ap_R9mCH.d.ts +0 -53
- package/dist/reward-ap_R9mCH.d.ts.map +0 -1
- package/dist/rollout-nodes-DhSPJ2X7.js.map +0 -1
- package/dist/schema-ChIZfnqY.js.map +0 -1
- package/dist/schema-PDKQ_iNE.d.ts.map +0 -1
- package/dist/search-kernel-C4XnLKIW.d.ts.map +0 -1
- package/dist/statistics-CvvC-MPv.js.map +0 -1
- package/dist/summary-report-9kwI6jFQ.d.ts.map +0 -1
- package/dist/tool-groups-Bcasvncd.d.ts.map +0 -1
- package/dist/types-ByrbgALT.d.ts.map +0 -1
package/dist/{paired-promotion-decision-Bi9__RQS.js.map → paired-promotion-decision-BoWHWL1i.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paired-promotion-decision-Bi9__RQS.js","names":[],"sources":["../src/paired-delta-test.ts","../src/paired-promotion-decision.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 * Eligibility follows the requested target. A continuous mean needs the\n * bootstrap minimum; binary outcomes and explicit median targets use the\n * exact-test minimum. A small-sample sign diagnostic cannot certify a mean\n * effect. These floors establish estimator eligibility, not adequate power.\n */\n\nimport { minimumPairsForPairedDeltaTest, pairedDeltaTest } from './paired-delta-test'\nimport {\n BOOTSTRAP_GATE_MIN_N,\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 test also imposes its own\n * minimum: bootstrap eligibility for a continuous mean, or the exact-test\n * minimum for binary and explicit median targets. This is not a power guarantee. */\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 /** Declared binary support {0, binaryScale}, including when all observations\n * are zero. Must be finite and positive; every observation must use that\n * support. Uses the risk-difference mean, so cannot accompany 'median'.\n * Omitted: infer binary support from observed positive values. */\n binaryScale?: number\n /**\n * Declare the outcome continuous: never infer a two-point support from the\n * observed values, so the estimator is fixed before the data is seen. A\n * sealed call on a continuous measure must route to the bootstrap whatever\n * the sample happens to look like; with inference on, a sample whose values\n * all land on {0, s} is silently decided on the score interval instead.\n * Measured under discovery's E1 alternative (deltas in {+1, -0.5, 0} on a\n * zero baseline) at 20 pairs: 5.4 % of 2,000 simulated samples (seed 11)\n * re-route without this flag, 0 with it; the exact rate is 5.54 %\n * (`paired-promotion-power.test.ts`). Cannot accompany `binaryScale`.\n */\n continuous?: boolean\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 /** Declared or inferred positive level ({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 for the target, confidence, and caller floor. */\n minimumPairs: number\n /** n >= minimumPairs. */\n sufficient: boolean\n /** The deciding interval is zero-width at numeric precision 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 /** Declared or inferred positive binary level; null off the binary path. */\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 declaredBinaryScale?: number,\n continuous = false,\n): PairedDecisionShape {\n if (continuous && declaredBinaryScale !== undefined) {\n throw new Error('pairedDecisionShape: continuous cannot accompany binaryScale')\n }\n if (declaredBinaryScale !== undefined) {\n if (!Number.isFinite(declaredBinaryScale) || declaredBinaryScale <= 0) {\n throw new Error('pairedDecisionShape: binaryScale must be finite and positive')\n }\n if (statistic === 'median') {\n throw new Error('pairedDecisionShape: binaryScale requires the mean statistic, not median')\n }\n for (const [name, arm] of [\n ['before', before],\n ['after', after],\n ] as const) {\n for (let i = 0; i < arm.length; i++) {\n const value = arm[i]!\n if (value !== 0 && value !== declaredBinaryScale) {\n throw new Error(\n `pairedDecisionShape: ${name}[${i}] must be 0 or binaryScale (${declaredBinaryScale}); got ${value}`,\n )\n }\n }\n }\n }\n const tieFraction = before.length === 0 ? null : pairedDeltaTieFraction(before, after)\n if (statistic === 'median') {\n return { statistic: 'median_bootstrap', binaryScale: null, tieFraction }\n }\n if (continuous) {\n return { statistic: 'mean_bootstrap', binaryScale: null, tieFraction }\n }\n const binaryScale = declaredBinaryScale ?? 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 { binaryScale, tieFraction } = pairedDecisionShape(\n before,\n after,\n options.statistic,\n options.binaryScale,\n options.continuous ?? false,\n )\n const estimatorMinimum =\n binaryScale === null && options.statistic !== 'median' ? BOOTSTRAP_GATE_MIN_N : exactMinimum\n const minimumPairs = Math.max(requestedMinimum, exactMinimum, estimatorMinimum)\n const n = before.length\n const sufficient = n >= minimumPairs\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: minimumPairs,\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 ? bootstrapStatistic === 'mean'\n ? ` The mean requires ${minimumPairs} pairs for bootstrap eligibility;` +\n ` the exact sign-test p=${fmt(test.pValue ?? 1)} does not establish a mean effect.`\n : ` Below ${BOOTSTRAP_GATE_MIN_N} pairs the interval is descriptive only;` +\n ` the median decision uses the exact one-sided sign test, p=${fmt(test.pValue ?? 1)}.`\n : '',\n }\n }\n\n // Equivalent deltas can differ by rounding after subtraction and averaging.\n // Use the interval's own scale so tiny score units retain the same decision\n // as a rescaled copy of the evidence.\n const intervalScale = Math.max(Math.abs(core.low), Math.abs(core.high))\n const intervalTolerance = intervalScale * Number.EPSILON * 8\n const indeterminate =\n !Number.isFinite(core.low) ||\n !Number.isFinite(core.high) ||\n core.high - core.low <= intervalTolerance\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"],"mappings":";;;AAgCA,SAAgB,+BAA+B,aAAa,KAAc;CACxE,IAAI,CAAC,OAAO,SAAS,UAAU,KAAK,cAAc,KAAK,cAAc,GACnE,MAAM,IAAI,MACR,oEAAoE,YACtE;CAEF,MAAM,iBAAiB,IAAI,cAAc;CACzC,OAAO,KAAK,KAAK,KAAK,KAAK,IAAI,aAAa,CAAC;AAC/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,gBACd,QACA,OACA,UAAkC,CAAC,GACZ;CACvB,MAAM,YAAY,QAAQ,aAAa;CACvC,IAAI,CAAC,OAAO,SAAS,SAAS,GAC5B,MAAM,IAAI,MAAM,kDAAkD,WAAW;CAG/E,MAAM,eAAe,+BADF,QAAQ,cAAc,GACqB;CAC9D,MAAM,mBAAmB,QAAQ,YAAY;CAC7C,IAAI,CAAC,OAAO,UAAU,gBAAgB,KAAK,mBAAmB,GAC5D,MAAM,IAAI,MAAM,6DAA6D,kBAAkB;CAEjG,MAAM,eAAe,KAAK,IAAI,kBAAkB,YAAY;CAC5D,MAAM,YAAY,gBAAgB,QAAQ,OAAO,OAAO;CACxD,MAAM,aAAa,UAAU,KAAK;CAIlC,MAAM,gBACJ,UAAU,IAAI,MACb,CAAC,OAAO,SAAS,UAAU,GAAG,KAC7B,CAAC,OAAO,SAAS,UAAU,IAAI,KAC/B,UAAU,QAAQ,UAAU;CAEhC,IAAI,UAAU,cACZ,OAAO;EACL;EACA,QAAQ;EACR,QAAQ;EACR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EACA;EACA;EACA;EACA,SAAS,cAAc,CAAC,iBAAiB,KAAK,mBAAmB,CAAC;EAClE,GAAG;CACL;AACF;AAEA,SAAS,IAAI,GAAmB;CAC9B,OAAO,EAAE,QAAQ,CAAC;AACpB"}
|
|
1
|
+
{"version":3,"file":"paired-promotion-decision-BoWHWL1i.js","names":[],"sources":["../src/paired-delta-test.ts","../src/paired-promotion-decision.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 * Eligibility follows the requested target. A continuous mean needs the\n * bootstrap minimum; binary outcomes and explicit median targets use the\n * exact-test minimum. A small-sample sign diagnostic cannot certify a mean\n * effect. These floors establish estimator eligibility, not adequate power.\n */\n\nimport { minimumPairsForPairedDeltaTest, pairedDeltaTest } from './paired-delta-test'\nimport {\n BOOTSTRAP_GATE_MIN_N,\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 test also imposes its own\n * minimum: bootstrap eligibility for a continuous mean, or the exact-test\n * minimum for binary and explicit median targets. This is not a power guarantee. */\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 /** Declared binary support {0, binaryScale}, including when all observations\n * are zero. Must be finite and positive; every observation must use that\n * support. Uses the risk-difference mean, so cannot accompany 'median'.\n * Omitted: infer binary support from observed positive values. */\n binaryScale?: number\n /**\n * Declare the outcome continuous: never infer a two-point support from the\n * observed values, so the estimator is fixed before the data is seen. A\n * sealed call on a continuous measure must route to the bootstrap whatever\n * the sample happens to look like; with inference on, a sample whose values\n * all land on {0, s} is silently decided on the score interval instead.\n * Measured under discovery's E1 alternative (deltas in {+1, -0.5, 0} on a\n * zero baseline) at 20 pairs: 5.4 % of 2,000 simulated samples (seed 11)\n * re-route without this flag, 0 with it; the exact rate is 5.54 %\n * (`paired-promotion-power.test.ts`). Cannot accompany `binaryScale`.\n */\n continuous?: boolean\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 /** Declared or inferred positive level ({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 for the target, confidence, and caller floor. */\n minimumPairs: number\n /** n >= minimumPairs. */\n sufficient: boolean\n /** The deciding interval is zero-width at numeric precision 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 /** Declared or inferred positive binary level; null off the binary path. */\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 declaredBinaryScale?: number,\n continuous = false,\n): PairedDecisionShape {\n if (continuous && declaredBinaryScale !== undefined) {\n throw new Error('pairedDecisionShape: continuous cannot accompany binaryScale')\n }\n if (declaredBinaryScale !== undefined) {\n if (!Number.isFinite(declaredBinaryScale) || declaredBinaryScale <= 0) {\n throw new Error('pairedDecisionShape: binaryScale must be finite and positive')\n }\n if (statistic === 'median') {\n throw new Error('pairedDecisionShape: binaryScale requires the mean statistic, not median')\n }\n for (const [name, arm] of [\n ['before', before],\n ['after', after],\n ] as const) {\n for (let i = 0; i < arm.length; i++) {\n const value = arm[i]!\n if (value !== 0 && value !== declaredBinaryScale) {\n throw new Error(\n `pairedDecisionShape: ${name}[${i}] must be 0 or binaryScale (${declaredBinaryScale}); got ${value}`,\n )\n }\n }\n }\n }\n const tieFraction = before.length === 0 ? null : pairedDeltaTieFraction(before, after)\n if (statistic === 'median') {\n return { statistic: 'median_bootstrap', binaryScale: null, tieFraction }\n }\n if (continuous) {\n return { statistic: 'mean_bootstrap', binaryScale: null, tieFraction }\n }\n const binaryScale = declaredBinaryScale ?? 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 { binaryScale, tieFraction } = pairedDecisionShape(\n before,\n after,\n options.statistic,\n options.binaryScale,\n options.continuous ?? false,\n )\n const estimatorMinimum =\n binaryScale === null && options.statistic !== 'median' ? BOOTSTRAP_GATE_MIN_N : exactMinimum\n const minimumPairs = Math.max(requestedMinimum, exactMinimum, estimatorMinimum)\n const n = before.length\n const sufficient = n >= minimumPairs\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: minimumPairs,\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 ? bootstrapStatistic === 'mean'\n ? ` The mean requires ${minimumPairs} pairs for bootstrap eligibility;` +\n ` the exact sign-test p=${fmt(test.pValue ?? 1)} does not establish a mean effect.`\n : ` Below ${BOOTSTRAP_GATE_MIN_N} pairs the interval is descriptive only;` +\n ` the median decision uses the exact one-sided sign test, p=${fmt(test.pValue ?? 1)}.`\n : '',\n }\n }\n\n // Equivalent deltas can differ by rounding after subtraction and averaging.\n // Use the interval's own scale so tiny score units retain the same decision\n // as a rescaled copy of the evidence.\n const intervalScale = Math.max(Math.abs(core.low), Math.abs(core.high))\n const intervalTolerance = intervalScale * Number.EPSILON * 8\n const indeterminate =\n !Number.isFinite(core.low) ||\n !Number.isFinite(core.high) ||\n core.high - core.low <= intervalTolerance\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"],"mappings":";;;AAgCA,SAAgB,+BAA+B,aAAa,KAAc;CACxE,IAAI,CAAC,OAAO,SAAS,UAAU,KAAK,cAAc,KAAK,cAAc,GACnE,MAAM,IAAI,MACR,oEAAoE,YACtE;CAEF,MAAM,iBAAiB,IAAI,cAAc;CACzC,OAAO,KAAK,KAAK,KAAK,KAAK,IAAI,aAAa,CAAC;AAC/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,SAAgB,gBACd,QACA,OACA,UAAkC,CAAC,GACZ;CACvB,MAAM,YAAY,QAAQ,aAAa;CACvC,IAAI,CAAC,OAAO,SAAS,SAAS,GAC5B,MAAM,IAAI,MAAM,kDAAkD,WAAW;CAG/E,MAAM,eAAe,+BADF,QAAQ,cAAc,GACqB;CAC9D,MAAM,mBAAmB,QAAQ,YAAY;CAC7C,IAAI,CAAC,OAAO,UAAU,gBAAgB,KAAK,mBAAmB,GAC5D,MAAM,IAAI,MAAM,6DAA6D,kBAAkB;CAEjG,MAAM,eAAe,KAAK,IAAI,kBAAkB,YAAY;CAC5D,MAAM,YAAY,gBAAgB,QAAQ,OAAO,OAAO;CACxD,MAAM,aAAa,UAAU,KAAK;CAIlC,MAAM,gBACJ,UAAU,IAAI,MACb,CAAC,OAAO,SAAS,UAAU,GAAG,KAC7B,CAAC,OAAO,SAAS,UAAU,IAAI,KAC/B,UAAU,QAAQ,UAAU;CAEhC,IAAI,UAAU,cACZ,OAAO;EACL;EACA,QAAQ;EACR,QAAQ;EACR;EACA;EACA;EACA,aAAa,cAAc,CAAC,iBAAiB,UAAU,MAAM;CAC/D;CAGF,MAAM,cAAc,OAAO,KAAK,OAAO,UAAU,MAAM,SAAU,QAAQ,SAAS;CAClF,MAAM,QAAQ,eAAe,aAAa,SAAS;CACnD,MAAM,WAA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
|
1
|
-
import {
|
|
1
|
+
import { k as wilson } from "./statistics-CHs0jlsY.js";
|
|
2
2
|
import { t as mulberry32 } from "./random-DrzcgC7F.js";
|
|
3
|
-
import { t as decidePairedPromotion } from "./paired-promotion-decision-
|
|
3
|
+
import { t as decidePairedPromotion } from "./paired-promotion-decision-BoWHWL1i.js";
|
|
4
4
|
// src/paired-promotion-power.ts
|
|
5
5
|
/**
|
|
6
6
|
* @module
|
|
@@ -286,4 +286,4 @@ function validateLaw(law, where) {
|
|
|
286
286
|
}
|
|
287
287
|
export { pairedPromotionPower as n, requiredPairsForPairedPromotion as r, drawValue as t };
|
|
288
288
|
|
|
289
|
-
//# sourceMappingURL=paired-promotion-power-
|
|
289
|
+
//# sourceMappingURL=paired-promotion-power-BXH3gzvs.js.map
|
package/dist/{paired-promotion-power-D03cUj9E.js.map → paired-promotion-power-BXH3gzvs.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paired-promotion-power-D03cUj9E.js","names":[],"sources":["../src/paired-promotion-power.ts"],"sourcesContent":["/**\n * @module\n * Joint power of a configured {@link decidePairedPromotion} call, computed by\n * running that call on data drawn from a registered alternative.\n *\n * Why a simulation and not a formula: `decidePairedPromotion` is not one test.\n * It routes by sample size (exact sign test below `BOOTSTRAP_GATE_MIN_N`,\n * paired bootstrap at or above it) and by shape (Tango's score interval on a\n * two-point outcome), and on top of the deciding interval it applies a\n * sufficiency floor, a zero-width refusal and McNemar's exact veto. A\n * preregistration usually seals two such calls, a continuous primary and a\n * pass/fail veto drawn from the same episodes, and promotes only when both\n * promote. The sample size at which THAT procedure reaches a target power is\n * not the power of any one channel: the sign-test power at n can be 0.8 while\n * the promotion probability is well below it because the veto binds\n * (agent-eval#785). Closed forms exist for single channels only, and each one\n * shipped here under-sized the call it stood in for (`mcnemarRequiredN` is\n * Lachin's normal approximation, 0.65 exact power where it promised 0.8 at 14\n * pairs; `requiredPairedSampleSize` sizes a paired t the procedure never runs).\n * So the only faithful power is the procedure's own promotion rate under the\n * alternative, and that is what this module computes: draw n pairs from the\n * registered law, run every configured call on them exactly as the caller\n * will, repeat, count.\n *\n * The alternative is DECLARATIVE and serializable, never a sampler function,\n * so a preregistration can seal it as bytes: a mixture of cells, each with a\n * probability, an optional pass/fail outcome per arm for the binary calls,\n * and a law for the candidate-minus-baseline delta on the continuous scale.\n * Drawing the cell first and the delta given the cell is what makes the two\n * channels one joint law rather than two marginals.\n *\n * Everything is seeded (`mulberry32`), so a sizing is reproducible from its\n * inputs, and every estimate carries its Monte Carlo standard error and a\n * Wilson interval: a power read at 0.80 from 1,000 simulations is 0.80 ± 0.013.\n */\n\nimport {\n decidePairedPromotion,\n type PairedDecisionMethod,\n type PairedPromotionDecision,\n type PairedPromotionDecisionOptions,\n} from './paired-promotion-decision'\nimport { wilson } from './statistics/paired-binary'\nimport { mulberry32 } from './statistics/random'\n\n/** A serializable law for one scalar draw. */\nexport type PairedValueLaw =\n | { kind: 'point'; value: number }\n | { kind: 'atoms'; atoms: ReadonlyArray<{ value: number; probability: number }> }\n | { kind: 'normal'; mean: number; sd: number }\n\nexport interface PairedPromotionAlternativeCell {\n /** Probability of this cell. The cells' probabilities sum to 1. */\n probability: number\n /** Pass/fail outcome of each arm in this cell. Required by every call whose\n * `outcome` is `'pass'`; ignored otherwise. */\n pass?: { control: boolean; treatment: boolean }\n /** Law of the candidate-minus-baseline delta on the continuous scale, given\n * this cell. A tie is `{ kind: 'point', value: 0 }`. */\n delta: PairedValueLaw\n}\n\nexport interface PairedPromotionAlternative {\n /** The registered joint law: the cell is drawn first, then the delta given\n * the cell, so pass/fail and delta are dependent exactly as registered. */\n cells: ReadonlyArray<PairedPromotionAlternativeCell>\n /**\n * Law of the control arm's value on the continuous scale; the candidate is\n * control plus delta. Default `{ kind: 'point', value: 0 }`. The mean and\n * median bootstraps read only the deltas, so the baseline changes nothing\n * there; it matters only when a `'delta'` call infers its shape from the\n * observed values (see `continuous` on {@link PairedPromotionDecisionOptions}).\n */\n baseline?: PairedValueLaw\n}\n\nexport interface PairedPromotionPowerCall {\n /** What the call reads from each simulated pair: `'delta'` gives it\n * `(control, control + delta)` on the continuous scale, `'pass'` gives it\n * each arm's pass/fail as `0` or `options.binaryScale ?? 1`. */\n outcome: 'delta' | 'pass'\n /** The call's options, exactly as the caller will run it. `minPairs`\n * defaults to the simulated n, the value a gate seals; a caller-supplied\n * value is kept, and one above n refuses every simulation. A `'pass'` call\n * must declare `binaryScale`: the simulation never declares one on the\n * caller's behalf, because a declared scale routes an all-zero sample to\n * the score interval where an inferred one refuses it. */\n options: PairedPromotionDecisionOptions\n}\n\nexport interface PairedPromotionPowerOptions {\n /** Total paired episodes, ties included. */\n n: number\n alternative: PairedPromotionAlternative\n /** Every call must return `promote: true` for a simulation to count as a\n * promotion. At least one call. */\n calls: ReadonlyArray<PairedPromotionPowerCall>\n /** Simulated data sets. Default 1000. */\n simulations?: number\n /** PRNG seed for the simulated draws (not the bootstrap's seed, which each\n * call carries in its own options). Default 1. */\n seed?: number\n}\n\nexport interface PairedPromotionCallRates {\n outcome: 'delta' | 'pass'\n /** Fraction of simulations in which this call alone promoted. */\n promote: number\n /** Fractions of simulations in which each refusal channel fired. */\n insufficient: number\n indeterminate: number\n exactTestVetoes: number\n /** Fraction in which the call was sufficient, determinate, not vetoed, and\n * still did not clear its threshold. */\n hold: number\n /** Fraction of simulations decided by each method; the regime the call\n * actually ran in at this n. */\n methods: Partial<Record<PairedDecisionMethod, number>>\n}\n\nexport interface PairedPromotionPowerResult {\n n: number\n simulations: number\n seed: number\n /** Fraction of simulations in which every call promoted: the joint power. */\n power: number\n /** Monte Carlo standard error of `power`. */\n standardError: number\n /** Wilson 95% interval on `power`. */\n low: number\n high: number\n /** Fraction in which at least one call refused (insufficient, indeterminate\n * or vetoed); the rest of the non-promotions are holds. */\n refuse: number\n hold: number\n /** Per-call rates, in the order the calls were supplied. */\n calls: PairedPromotionCallRates[]\n}\n\nexport interface RequiredPairsForPairedPromotionOptions {\n /** Target joint power. Default 0.8. */\n target?: number\n alternative: PairedPromotionAlternative\n calls: ReadonlyArray<PairedPromotionPowerCall>\n /** Smallest n to consider. Default 1. */\n minPairs?: number\n /** Largest n to consider; the scan stops there with `n: null` if the target\n * is never reached. Default 200. */\n maxPairs?: number\n simulations?: number\n seed?: number\n}\n\nexport interface RequiredPairsForPairedPromotionResult {\n target: number\n /** First n scanned whose estimated joint power reaches the target, or null\n * when no n up to `maxPairs` does. Descriptive only: power is not monotone\n * in n on the exact and discrete routes, the scan reads one noisy estimate\n * per n, and the first crossing of many is biased low. Read the curve. */\n n: number | null\n /**\n * The conservative choice, which a preregistration should prefer: the first\n * scanned n whose Wilson lower bound reaches the target AND whose\n * independent confirmation (a second simulation at that n on a fresh seed,\n * `confirmation` below) also has its lower bound at or above the target. The\n * confirmation is what keeps the 95 % coverage: a scan over many n gives\n * Monte Carlo noise many chances to push one bound across, so the scan's own\n * bound selects a candidate and never certifies it. Never set while `n` is\n * null. Null when not reached by `maxPairs`.\n */\n nAtLowerBound: number | null\n /** The independent simulation at `nAtLowerBound`; null when not reached. */\n confirmation: PairedPromotionPowerResult | null\n /** Every n scanned, in order, with its scan estimate; candidates whose\n * confirmation failed are in `rejected`. The scan stops at `nAtLowerBound`\n * when that is reached, else at `maxPairs`. */\n curve: PairedPromotionPowerResult[]\n /** Candidates the scan's bound selected and the confirmation refused. */\n rejected: PairedPromotionPowerResult[]\n}\n\n/**\n * Joint power of the configured calls at `n` under the registered alternative:\n * the fraction of simulated data sets on which every call promotes.\n */\nexport function pairedPromotionPower(\n options: PairedPromotionPowerOptions,\n): PairedPromotionPowerResult {\n const n = options.n\n if (!Number.isInteger(n) || n < 1) {\n throw new Error(`pairedPromotionPower: n must be a positive integer, got ${n}`)\n }\n const simulations = options.simulations ?? 1000\n if (!Number.isInteger(simulations) || simulations < 1) {\n throw new Error(\n `pairedPromotionPower: simulations must be a positive integer, got ${simulations}`,\n )\n }\n const seed = options.seed ?? 1\n if (!Number.isFinite(seed)) {\n throw new Error(`pairedPromotionPower: seed must be finite, got ${seed}`)\n }\n const calls = validateCalls(options.calls)\n const alternative = validateAlternative(options.alternative, calls)\n const rng = mulberry32(seed)\n\n let promotions = 0\n let refusals = 0\n const perCall = calls.map(() => ({\n promote: 0,\n insufficient: 0,\n indeterminate: 0,\n exactTestVetoes: 0,\n hold: 0,\n methods: new Map<PairedDecisionMethod, number>(),\n }))\n\n for (let s = 0; s < simulations; s++) {\n const pairs = drawPairs(alternative, n, rng)\n let all = true\n let anyRefusal = false\n for (let c = 0; c < calls.length; c++) {\n const call = calls[c]!\n const decision = runCall(call, pairs, n)\n const tally = perCall[c]!\n tally.methods.set(decision.method, (tally.methods.get(decision.method) ?? 0) + 1)\n if (decision.promote) tally.promote++\n else {\n if (!decision.sufficient) tally.insufficient++\n if (decision.indeterminate) tally.indeterminate++\n if (decision.exactTestVetoes) tally.exactTestVetoes++\n if (decision.sufficient && !decision.indeterminate && !decision.exactTestVetoes) {\n tally.hold++\n }\n }\n if (!decision.promote) all = false\n if (!decision.sufficient || decision.indeterminate || decision.exactTestVetoes) {\n anyRefusal = true\n }\n }\n if (all) promotions++\n else if (anyRefusal) refusals++\n }\n\n const power = promotions / simulations\n const interval = wilson(promotions, simulations, 0.95)\n return {\n n,\n simulations,\n seed,\n power,\n standardError: Math.sqrt((power * (1 - power)) / simulations),\n low: interval.lower,\n high: interval.upper,\n refuse: refusals / simulations,\n hold: (simulations - promotions - refusals) / simulations,\n calls: perCall.map((tally, c) => ({\n outcome: calls[c]!.outcome,\n promote: tally.promote / simulations,\n insufficient: tally.insufficient / simulations,\n indeterminate: tally.indeterminate / simulations,\n exactTestVetoes: tally.exactTestVetoes / simulations,\n hold: tally.hold / simulations,\n methods: Object.fromEntries(\n [...tally.methods.entries()].map(([method, count]) => [method, count / simulations]),\n ) as Partial<Record<PairedDecisionMethod, number>>,\n })),\n }\n}\n\n/**\n * First n at which {@link pairedPromotionPower} reaches the target, scanning\n * every n from `minPairs` upward. Both the point-estimate answer and the\n * confirmed lower-bound answer are returned; the scan runs until the latter is\n * reached (so the curve past `n` is retained) or `maxPairs` is exhausted. A\n * candidate selected by the scan's bound is certified only by an independent\n * simulation at that n on a different seed; a candidate that fails it is\n * recorded and the scan continues.\n */\nexport function requiredPairsForPairedPromotion(\n options: RequiredPairsForPairedPromotionOptions,\n): RequiredPairsForPairedPromotionResult {\n const target = options.target ?? 0.8\n if (!Number.isFinite(target) || target <= 0 || target >= 1) {\n throw new Error(`requiredPairsForPairedPromotion: target must be in (0,1), got ${target}`)\n }\n const minPairs = options.minPairs ?? 1\n const maxPairs = options.maxPairs ?? 200\n if (!Number.isInteger(minPairs) || minPairs < 1) {\n throw new Error(\n `requiredPairsForPairedPromotion: minPairs must be a positive integer, got ${minPairs}`,\n )\n }\n if (!Number.isInteger(maxPairs) || maxPairs < minPairs) {\n throw new Error(\n `requiredPairsForPairedPromotion: maxPairs must be an integer >= minPairs, got ${maxPairs}`,\n )\n }\n const seed = options.seed ?? 1\n const curve: PairedPromotionPowerResult[] = []\n const rejected: PairedPromotionPowerResult[] = []\n let n: number | null = null\n let nAtLowerBound: number | null = null\n let confirmation: PairedPromotionPowerResult | null = null\n for (let candidate = minPairs; candidate <= maxPairs; candidate++) {\n const result = pairedPromotionPower({\n n: candidate,\n alternative: options.alternative,\n calls: options.calls,\n simulations: options.simulations,\n seed,\n })\n curve.push(result)\n if (n === null && result.power >= target) n = candidate\n if (result.low >= target) {\n // A fresh stream, keyed by the candidate so no two confirmations share\n // draws with each other or with the scan.\n const check = pairedPromotionPower({\n n: candidate,\n alternative: options.alternative,\n calls: options.calls,\n simulations: options.simulations,\n seed: confirmationSeed(seed, candidate),\n })\n if (check.low >= target) {\n nAtLowerBound = candidate\n confirmation = check\n break\n }\n rejected.push(check)\n }\n }\n return { target, n, nAtLowerBound, confirmation, curve, rejected }\n}\n\n/** A seed for the confirmation at `n` that never equals the scan seed. */\nfunction confirmationSeed(seed: number, n: number): number {\n // Golden-ratio hashing keeps distinct (seed, n) pairs on distinct 32-bit\n // streams; the final `| 1` guarantees it differs from the scan's own seed\n // for every n, whose stream the scan already consumed.\n return ((Math.imul((seed | 0) ^ 0x9e3779b9, 0x85ebca6b) + Math.imul(n, 0xc2b2ae35)) | 1) >>> 0\n}\n\ninterface DrawnPairs {\n control: number[]\n candidate: number[]\n controlPass: boolean[]\n candidatePass: boolean[]\n}\n\nfunction drawPairs(\n alternative: PairedPromotionAlternative,\n n: number,\n rng: () => number,\n): DrawnPairs {\n const baseline = alternative.baseline ?? { kind: 'point', value: 0 }\n const control: number[] = new Array(n)\n const candidate: number[] = new Array(n)\n const controlPass: boolean[] = new Array(n)\n const candidatePass: boolean[] = new Array(n)\n for (let i = 0; i < n; i++) {\n const cell = drawCell(alternative.cells, rng)\n const base = drawValue(baseline, rng)\n control[i] = base\n candidate[i] = base + drawValue(cell.delta, rng)\n controlPass[i] = cell.pass?.control ?? false\n candidatePass[i] = cell.pass?.treatment ?? false\n }\n return { control, candidate, controlPass, candidatePass }\n}\n\nfunction drawCell(\n cells: ReadonlyArray<PairedPromotionAlternativeCell>,\n rng: () => number,\n): PairedPromotionAlternativeCell {\n const u = rng()\n let cumulative = 0\n for (const cell of cells) {\n cumulative += cell.probability\n if (u < cumulative) return cell\n }\n // Rounding at the top of the cumulative sum lands here with probability ~0.\n return cells[cells.length - 1]!\n}\n\nexport function drawValue(law: PairedValueLaw, rng: () => number): number {\n switch (law.kind) {\n case 'point':\n return law.value\n case 'atoms': {\n const u = rng()\n let cumulative = 0\n for (const atom of law.atoms) {\n cumulative += atom.probability\n if (u < cumulative) return atom.value\n }\n return law.atoms[law.atoms.length - 1]!.value\n }\n case 'normal': {\n const u1 = 1 - rng()\n const u2 = rng()\n return law.mean + law.sd * Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2)\n }\n }\n}\n\nfunction runCall(\n call: PairedPromotionPowerCall,\n pairs: DrawnPairs,\n n: number,\n): PairedPromotionDecision {\n const options: PairedPromotionDecisionOptions = { minPairs: n, ...call.options }\n if (call.outcome === 'pass') {\n // Validated present: the scale is the caller's, never filled in here.\n const scale = call.options.binaryScale as number\n return decidePairedPromotion(\n pairs.controlPass.map((p) => (p ? scale : 0)),\n pairs.candidatePass.map((p) => (p ? scale : 0)),\n options,\n )\n }\n return decidePairedPromotion(pairs.control, pairs.candidate, options)\n}\n\nfunction validateCalls(\n calls: ReadonlyArray<PairedPromotionPowerCall>,\n): ReadonlyArray<PairedPromotionPowerCall> {\n if (!Array.isArray(calls) || calls.length === 0) {\n throw new Error('pairedPromotionPower: at least one call is required')\n }\n calls.forEach((call, i) => {\n if (call.outcome !== 'delta' && call.outcome !== 'pass') {\n throw new Error(`pairedPromotionPower: calls[${i}].outcome must be 'delta' or 'pass'`)\n }\n if (call.options === null || typeof call.options !== 'object') {\n throw new Error(`pairedPromotionPower: calls[${i}].options must be an object`)\n }\n if (\n call.options.minPairs !== undefined &&\n (!Number.isInteger(call.options.minPairs) || call.options.minPairs < 1)\n ) {\n throw new Error(\n `pairedPromotionPower: calls[${i}].options.minPairs must be a positive integer`,\n )\n }\n // Every combination the decision itself refuses is refused here, before\n // the first draw, with the reason named.\n if (call.outcome === 'pass') {\n const scale = call.options.binaryScale\n if (scale === undefined || !Number.isFinite(scale) || scale <= 0) {\n throw new Error(\n `pairedPromotionPower: calls[${i}] is a 'pass' call and must declare a finite positive options.binaryScale`,\n )\n }\n if (call.options.continuous) {\n throw new Error(\n `pairedPromotionPower: calls[${i}] is a 'pass' call; continuous cannot accompany it`,\n )\n }\n if (call.options.statistic === 'median') {\n throw new Error(\n `pairedPromotionPower: calls[${i}] is a 'pass' call; binaryScale requires the mean statistic, not median`,\n )\n }\n } else if (call.options.binaryScale !== undefined) {\n throw new Error(\n `pairedPromotionPower: calls[${i}] is a 'delta' call and cannot declare binaryScale; use a 'pass' call for a two-point outcome`,\n )\n }\n })\n return calls\n}\n\nfunction validateAlternative(\n alternative: PairedPromotionAlternative,\n calls: ReadonlyArray<PairedPromotionPowerCall>,\n): PairedPromotionAlternative {\n if (!alternative || !Array.isArray(alternative.cells) || alternative.cells.length === 0) {\n throw new Error('pairedPromotionPower: alternative.cells must be a non-empty array')\n }\n const needsPass = calls.some((call) => call.outcome === 'pass')\n let total = 0\n alternative.cells.forEach((cell, i) => {\n if (!Number.isFinite(cell.probability) || cell.probability < 0) {\n throw new Error(`pairedPromotionPower: cells[${i}].probability must be a finite number >= 0`)\n }\n total += cell.probability\n if (needsPass) {\n if (\n !cell.pass ||\n typeof cell.pass.control !== 'boolean' ||\n typeof cell.pass.treatment !== 'boolean'\n ) {\n throw new Error(\n `pairedPromotionPower: cells[${i}].pass must give control and treatment booleans when a 'pass' call is configured`,\n )\n }\n }\n validateLaw(cell.delta, `cells[${i}].delta`)\n })\n if (Math.abs(total - 1) > 1e-9) {\n throw new Error(`pairedPromotionPower: cell probabilities must sum to 1, got ${total}`)\n }\n if (alternative.baseline !== undefined) validateLaw(alternative.baseline, 'baseline')\n return alternative\n}\n\nfunction validateLaw(law: PairedValueLaw, where: string): void {\n if (!law || typeof law !== 'object') {\n throw new Error(`pairedPromotionPower: ${where} must be a law object`)\n }\n switch (law.kind) {\n case 'point':\n if (!Number.isFinite(law.value)) {\n throw new Error(`pairedPromotionPower: ${where}.value must be finite`)\n }\n return\n case 'atoms': {\n if (!Array.isArray(law.atoms) || law.atoms.length === 0) {\n throw new Error(`pairedPromotionPower: ${where}.atoms must be a non-empty array`)\n }\n let total = 0\n law.atoms.forEach((atom, i) => {\n if (!Number.isFinite(atom.value)) {\n throw new Error(`pairedPromotionPower: ${where}.atoms[${i}].value must be finite`)\n }\n if (!Number.isFinite(atom.probability) || atom.probability < 0) {\n throw new Error(\n `pairedPromotionPower: ${where}.atoms[${i}].probability must be a finite number >= 0`,\n )\n }\n total += atom.probability\n })\n if (Math.abs(total - 1) > 1e-9) {\n throw new Error(\n `pairedPromotionPower: ${where}.atoms probabilities must sum to 1, got ${total}`,\n )\n }\n return\n }\n case 'normal':\n if (!Number.isFinite(law.mean) || !Number.isFinite(law.sd) || law.sd < 0) {\n throw new Error(`pairedPromotionPower: ${where} needs a finite mean and a finite sd >= 0`)\n }\n return\n default:\n throw new Error(`pairedPromotionPower: ${where}.kind must be 'point', 'atoms' or 'normal'`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyLA,SAAgB,qBACd,SAC4B;CAC5B,MAAM,IAAI,QAAQ;CAClB,IAAI,CAAC,OAAO,UAAU,CAAC,KAAK,IAAI,GAC9B,MAAM,IAAI,MAAM,2DAA2D,GAAG;CAEhF,MAAM,cAAc,QAAQ,eAAe;CAC3C,IAAI,CAAC,OAAO,UAAU,WAAW,KAAK,cAAc,GAClD,MAAM,IAAI,MACR,qEAAqE,aACvE;CAEF,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI,CAAC,OAAO,SAAS,IAAI,GACvB,MAAM,IAAI,MAAM,kDAAkD,MAAM;CAE1E,MAAM,QAAQ,cAAc,QAAQ,KAAK;CACzC,MAAM,cAAc,oBAAoB,QAAQ,aAAa,KAAK;CAClE,MAAM,MAAM,WAAW,IAAI;CAE3B,IAAI,aAAa;CACjB,IAAI,WAAW;CACf,MAAM,UAAU,MAAM,WAAW;EAC/B,SAAS;EACT,cAAc;EACd,eAAe;EACf,iBAAiB;EACjB,MAAM;EACN,yBAAS,IAAI,IAAkC;CACjD,EAAE;CAEF,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,KAAK;EACpC,MAAM,QAAQ,UAAU,aAAa,GAAG,GAAG;EAC3C,IAAI,MAAM;EACV,IAAI,aAAa;EACjB,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;GACrC,MAAM,OAAO,MAAM;GACnB,MAAM,WAAW,QAAQ,MAAM,OAAO,CAAC;GACvC,MAAM,QAAQ,QAAQ;GACtB,MAAM,QAAQ,IAAI,SAAS,SAAS,MAAM,QAAQ,IAAI,SAAS,MAA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AEF,SAAS,KAAK;GAChB,CAAC;GACD,IAAI,KAAK,IAAI,QAAQ,CAAC,IAAI,MACxB,MAAM,IAAI,MACR,yBAAyB,MAAM,0CAA0C,OAC3E;GAEF;EACF;EACA,KAAK;GACH,IAAI,CAAC,OAAO,SAAS,IAAI,IAAI,KAAK,CAAC,OAAO,SAAS,IAAI,EAAE,KAAK,IAAI,KAAK,GACrE,MAAM,IAAI,MAAM,yBAAyB,MAAM,0CAA0C;GAE3F;EACF,SACE,MAAM,IAAI,MAAM,yBAAyB,MAAM,2CAA2C;CAC9F;AACF"}
|
|
1
|
+
{"version":3,"file":"paired-promotion-power-BXH3gzvs.js","names":[],"sources":["../src/paired-promotion-power.ts"],"sourcesContent":["/**\n * @module\n * Joint power of a configured {@link decidePairedPromotion} call, computed by\n * running that call on data drawn from a registered alternative.\n *\n * Why a simulation and not a formula: `decidePairedPromotion` is not one test.\n * It routes by sample size (exact sign test below `BOOTSTRAP_GATE_MIN_N`,\n * paired bootstrap at or above it) and by shape (Tango's score interval on a\n * two-point outcome), and on top of the deciding interval it applies a\n * sufficiency floor, a zero-width refusal and McNemar's exact veto. A\n * preregistration usually seals two such calls, a continuous primary and a\n * pass/fail veto drawn from the same episodes, and promotes only when both\n * promote. The sample size at which THAT procedure reaches a target power is\n * not the power of any one channel: the sign-test power at n can be 0.8 while\n * the promotion probability is well below it because the veto binds\n * (agent-eval#785). Closed forms exist for single channels only, and each one\n * shipped here under-sized the call it stood in for (`mcnemarRequiredN` is\n * Lachin's normal approximation, 0.65 exact power where it promised 0.8 at 14\n * pairs; `requiredPairedSampleSize` sizes a paired t the procedure never runs).\n * So the only faithful power is the procedure's own promotion rate under the\n * alternative, and that is what this module computes: draw n pairs from the\n * registered law, run every configured call on them exactly as the caller\n * will, repeat, count.\n *\n * The alternative is DECLARATIVE and serializable, never a sampler function,\n * so a preregistration can seal it as bytes: a mixture of cells, each with a\n * probability, an optional pass/fail outcome per arm for the binary calls,\n * and a law for the candidate-minus-baseline delta on the continuous scale.\n * Drawing the cell first and the delta given the cell is what makes the two\n * channels one joint law rather than two marginals.\n *\n * Everything is seeded (`mulberry32`), so a sizing is reproducible from its\n * inputs, and every estimate carries its Monte Carlo standard error and a\n * Wilson interval: a power read at 0.80 from 1,000 simulations is 0.80 ± 0.013.\n */\n\nimport {\n decidePairedPromotion,\n type PairedDecisionMethod,\n type PairedPromotionDecision,\n type PairedPromotionDecisionOptions,\n} from './paired-promotion-decision'\nimport { wilson } from './statistics/paired-binary'\nimport { mulberry32 } from './statistics/random'\n\n/** A serializable law for one scalar draw. */\nexport type PairedValueLaw =\n | { kind: 'point'; value: number }\n | { kind: 'atoms'; atoms: ReadonlyArray<{ value: number; probability: number }> }\n | { kind: 'normal'; mean: number; sd: number }\n\nexport interface PairedPromotionAlternativeCell {\n /** Probability of this cell. The cells' probabilities sum to 1. */\n probability: number\n /** Pass/fail outcome of each arm in this cell. Required by every call whose\n * `outcome` is `'pass'`; ignored otherwise. */\n pass?: { control: boolean; treatment: boolean }\n /** Law of the candidate-minus-baseline delta on the continuous scale, given\n * this cell. A tie is `{ kind: 'point', value: 0 }`. */\n delta: PairedValueLaw\n}\n\nexport interface PairedPromotionAlternative {\n /** The registered joint law: the cell is drawn first, then the delta given\n * the cell, so pass/fail and delta are dependent exactly as registered. */\n cells: ReadonlyArray<PairedPromotionAlternativeCell>\n /**\n * Law of the control arm's value on the continuous scale; the candidate is\n * control plus delta. Default `{ kind: 'point', value: 0 }`. The mean and\n * median bootstraps read only the deltas, so the baseline changes nothing\n * there; it matters only when a `'delta'` call infers its shape from the\n * observed values (see `continuous` on {@link PairedPromotionDecisionOptions}).\n */\n baseline?: PairedValueLaw\n}\n\nexport interface PairedPromotionPowerCall {\n /** What the call reads from each simulated pair: `'delta'` gives it\n * `(control, control + delta)` on the continuous scale, `'pass'` gives it\n * each arm's pass/fail as `0` or `options.binaryScale ?? 1`. */\n outcome: 'delta' | 'pass'\n /** The call's options, exactly as the caller will run it. `minPairs`\n * defaults to the simulated n, the value a gate seals; a caller-supplied\n * value is kept, and one above n refuses every simulation. A `'pass'` call\n * must declare `binaryScale`: the simulation never declares one on the\n * caller's behalf, because a declared scale routes an all-zero sample to\n * the score interval where an inferred one refuses it. */\n options: PairedPromotionDecisionOptions\n}\n\nexport interface PairedPromotionPowerOptions {\n /** Total paired episodes, ties included. */\n n: number\n alternative: PairedPromotionAlternative\n /** Every call must return `promote: true` for a simulation to count as a\n * promotion. At least one call. */\n calls: ReadonlyArray<PairedPromotionPowerCall>\n /** Simulated data sets. Default 1000. */\n simulations?: number\n /** PRNG seed for the simulated draws (not the bootstrap's seed, which each\n * call carries in its own options). Default 1. */\n seed?: number\n}\n\nexport interface PairedPromotionCallRates {\n outcome: 'delta' | 'pass'\n /** Fraction of simulations in which this call alone promoted. */\n promote: number\n /** Fractions of simulations in which each refusal channel fired. */\n insufficient: number\n indeterminate: number\n exactTestVetoes: number\n /** Fraction in which the call was sufficient, determinate, not vetoed, and\n * still did not clear its threshold. */\n hold: number\n /** Fraction of simulations decided by each method; the regime the call\n * actually ran in at this n. */\n methods: Partial<Record<PairedDecisionMethod, number>>\n}\n\nexport interface PairedPromotionPowerResult {\n n: number\n simulations: number\n seed: number\n /** Fraction of simulations in which every call promoted: the joint power. */\n power: number\n /** Monte Carlo standard error of `power`. */\n standardError: number\n /** Wilson 95% interval on `power`. */\n low: number\n high: number\n /** Fraction in which at least one call refused (insufficient, indeterminate\n * or vetoed); the rest of the non-promotions are holds. */\n refuse: number\n hold: number\n /** Per-call rates, in the order the calls were supplied. */\n calls: PairedPromotionCallRates[]\n}\n\nexport interface RequiredPairsForPairedPromotionOptions {\n /** Target joint power. Default 0.8. */\n target?: number\n alternative: PairedPromotionAlternative\n calls: ReadonlyArray<PairedPromotionPowerCall>\n /** Smallest n to consider. Default 1. */\n minPairs?: number\n /** Largest n to consider; the scan stops there with `n: null` if the target\n * is never reached. Default 200. */\n maxPairs?: number\n simulations?: number\n seed?: number\n}\n\nexport interface RequiredPairsForPairedPromotionResult {\n target: number\n /** First n scanned whose estimated joint power reaches the target, or null\n * when no n up to `maxPairs` does. Descriptive only: power is not monotone\n * in n on the exact and discrete routes, the scan reads one noisy estimate\n * per n, and the first crossing of many is biased low. Read the curve. */\n n: number | null\n /**\n * The conservative choice, which a preregistration should prefer: the first\n * scanned n whose Wilson lower bound reaches the target AND whose\n * independent confirmation (a second simulation at that n on a fresh seed,\n * `confirmation` below) also has its lower bound at or above the target. The\n * confirmation is what keeps the 95 % coverage: a scan over many n gives\n * Monte Carlo noise many chances to push one bound across, so the scan's own\n * bound selects a candidate and never certifies it. Never set while `n` is\n * null. Null when not reached by `maxPairs`.\n */\n nAtLowerBound: number | null\n /** The independent simulation at `nAtLowerBound`; null when not reached. */\n confirmation: PairedPromotionPowerResult | null\n /** Every n scanned, in order, with its scan estimate; candidates whose\n * confirmation failed are in `rejected`. The scan stops at `nAtLowerBound`\n * when that is reached, else at `maxPairs`. */\n curve: PairedPromotionPowerResult[]\n /** Candidates the scan's bound selected and the confirmation refused. */\n rejected: PairedPromotionPowerResult[]\n}\n\n/**\n * Joint power of the configured calls at `n` under the registered alternative:\n * the fraction of simulated data sets on which every call promotes.\n */\nexport function pairedPromotionPower(\n options: PairedPromotionPowerOptions,\n): PairedPromotionPowerResult {\n const n = options.n\n if (!Number.isInteger(n) || n < 1) {\n throw new Error(`pairedPromotionPower: n must be a positive integer, got ${n}`)\n }\n const simulations = options.simulations ?? 1000\n if (!Number.isInteger(simulations) || simulations < 1) {\n throw new Error(\n `pairedPromotionPower: simulations must be a positive integer, got ${simulations}`,\n )\n }\n const seed = options.seed ?? 1\n if (!Number.isFinite(seed)) {\n throw new Error(`pairedPromotionPower: seed must be finite, got ${seed}`)\n }\n const calls = validateCalls(options.calls)\n const alternative = validateAlternative(options.alternative, calls)\n const rng = mulberry32(seed)\n\n let promotions = 0\n let refusals = 0\n const perCall = calls.map(() => ({\n promote: 0,\n insufficient: 0,\n indeterminate: 0,\n exactTestVetoes: 0,\n hold: 0,\n methods: new Map<PairedDecisionMethod, number>(),\n }))\n\n for (let s = 0; s < simulations; s++) {\n const pairs = drawPairs(alternative, n, rng)\n let all = true\n let anyRefusal = false\n for (let c = 0; c < calls.length; c++) {\n const call = calls[c]!\n const decision = runCall(call, pairs, n)\n const tally = perCall[c]!\n tally.methods.set(decision.method, (tally.methods.get(decision.method) ?? 0) + 1)\n if (decision.promote) tally.promote++\n else {\n if (!decision.sufficient) tally.insufficient++\n if (decision.indeterminate) tally.indeterminate++\n if (decision.exactTestVetoes) tally.exactTestVetoes++\n if (decision.sufficient && !decision.indeterminate && !decision.exactTestVetoes) {\n tally.hold++\n }\n }\n if (!decision.promote) all = false\n if (!decision.sufficient || decision.indeterminate || decision.exactTestVetoes) {\n anyRefusal = true\n }\n }\n if (all) promotions++\n else if (anyRefusal) refusals++\n }\n\n const power = promotions / simulations\n const interval = wilson(promotions, simulations, 0.95)\n return {\n n,\n simulations,\n seed,\n power,\n standardError: Math.sqrt((power * (1 - power)) / simulations),\n low: interval.lower,\n high: interval.upper,\n refuse: refusals / simulations,\n hold: (simulations - promotions - refusals) / simulations,\n calls: perCall.map((tally, c) => ({\n outcome: calls[c]!.outcome,\n promote: tally.promote / simulations,\n insufficient: tally.insufficient / simulations,\n indeterminate: tally.indeterminate / simulations,\n exactTestVetoes: tally.exactTestVetoes / simulations,\n hold: tally.hold / simulations,\n methods: Object.fromEntries(\n [...tally.methods.entries()].map(([method, count]) => [method, count / simulations]),\n ) as Partial<Record<PairedDecisionMethod, number>>,\n })),\n }\n}\n\n/**\n * First n at which {@link pairedPromotionPower} reaches the target, scanning\n * every n from `minPairs` upward. Both the point-estimate answer and the\n * confirmed lower-bound answer are returned; the scan runs until the latter is\n * reached (so the curve past `n` is retained) or `maxPairs` is exhausted. A\n * candidate selected by the scan's bound is certified only by an independent\n * simulation at that n on a different seed; a candidate that fails it is\n * recorded and the scan continues.\n */\nexport function requiredPairsForPairedPromotion(\n options: RequiredPairsForPairedPromotionOptions,\n): RequiredPairsForPairedPromotionResult {\n const target = options.target ?? 0.8\n if (!Number.isFinite(target) || target <= 0 || target >= 1) {\n throw new Error(`requiredPairsForPairedPromotion: target must be in (0,1), got ${target}`)\n }\n const minPairs = options.minPairs ?? 1\n const maxPairs = options.maxPairs ?? 200\n if (!Number.isInteger(minPairs) || minPairs < 1) {\n throw new Error(\n `requiredPairsForPairedPromotion: minPairs must be a positive integer, got ${minPairs}`,\n )\n }\n if (!Number.isInteger(maxPairs) || maxPairs < minPairs) {\n throw new Error(\n `requiredPairsForPairedPromotion: maxPairs must be an integer >= minPairs, got ${maxPairs}`,\n )\n }\n const seed = options.seed ?? 1\n const curve: PairedPromotionPowerResult[] = []\n const rejected: PairedPromotionPowerResult[] = []\n let n: number | null = null\n let nAtLowerBound: number | null = null\n let confirmation: PairedPromotionPowerResult | null = null\n for (let candidate = minPairs; candidate <= maxPairs; candidate++) {\n const result = pairedPromotionPower({\n n: candidate,\n alternative: options.alternative,\n calls: options.calls,\n simulations: options.simulations,\n seed,\n })\n curve.push(result)\n if (n === null && result.power >= target) n = candidate\n if (result.low >= target) {\n // A fresh stream, keyed by the candidate so no two confirmations share\n // draws with each other or with the scan.\n const check = pairedPromotionPower({\n n: candidate,\n alternative: options.alternative,\n calls: options.calls,\n simulations: options.simulations,\n seed: confirmationSeed(seed, candidate),\n })\n if (check.low >= target) {\n nAtLowerBound = candidate\n confirmation = check\n break\n }\n rejected.push(check)\n }\n }\n return { target, n, nAtLowerBound, confirmation, curve, rejected }\n}\n\n/** A seed for the confirmation at `n` that never equals the scan seed. */\nfunction confirmationSeed(seed: number, n: number): number {\n // Golden-ratio hashing keeps distinct (seed, n) pairs on distinct 32-bit\n // streams; the final `| 1` guarantees it differs from the scan's own seed\n // for every n, whose stream the scan already consumed.\n return ((Math.imul((seed | 0) ^ 0x9e3779b9, 0x85ebca6b) + Math.imul(n, 0xc2b2ae35)) | 1) >>> 0\n}\n\ninterface DrawnPairs {\n control: number[]\n candidate: number[]\n controlPass: boolean[]\n candidatePass: boolean[]\n}\n\nfunction drawPairs(\n alternative: PairedPromotionAlternative,\n n: number,\n rng: () => number,\n): DrawnPairs {\n const baseline = alternative.baseline ?? { kind: 'point', value: 0 }\n const control: number[] = new Array(n)\n const candidate: number[] = new Array(n)\n const controlPass: boolean[] = new Array(n)\n const candidatePass: boolean[] = new Array(n)\n for (let i = 0; i < n; i++) {\n const cell = drawCell(alternative.cells, rng)\n const base = drawValue(baseline, rng)\n control[i] = base\n candidate[i] = base + drawValue(cell.delta, rng)\n controlPass[i] = cell.pass?.control ?? false\n candidatePass[i] = cell.pass?.treatment ?? false\n }\n return { control, candidate, controlPass, candidatePass }\n}\n\nfunction drawCell(\n cells: ReadonlyArray<PairedPromotionAlternativeCell>,\n rng: () => number,\n): PairedPromotionAlternativeCell {\n const u = rng()\n let cumulative = 0\n for (const cell of cells) {\n cumulative += cell.probability\n if (u < cumulative) return cell\n }\n // Rounding at the top of the cumulative sum lands here with probability ~0.\n return cells[cells.length - 1]!\n}\n\nexport function drawValue(law: PairedValueLaw, rng: () => number): number {\n switch (law.kind) {\n case 'point':\n return law.value\n case 'atoms': {\n const u = rng()\n let cumulative = 0\n for (const atom of law.atoms) {\n cumulative += atom.probability\n if (u < cumulative) return atom.value\n }\n return law.atoms[law.atoms.length - 1]!.value\n }\n case 'normal': {\n const u1 = 1 - rng()\n const u2 = rng()\n return law.mean + law.sd * Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2)\n }\n }\n}\n\nfunction runCall(\n call: PairedPromotionPowerCall,\n pairs: DrawnPairs,\n n: number,\n): PairedPromotionDecision {\n const options: PairedPromotionDecisionOptions = { minPairs: n, ...call.options }\n if (call.outcome === 'pass') {\n // Validated present: the scale is the caller's, never filled in here.\n const scale = call.options.binaryScale as number\n return decidePairedPromotion(\n pairs.controlPass.map((p) => (p ? scale : 0)),\n pairs.candidatePass.map((p) => (p ? scale : 0)),\n options,\n )\n }\n return decidePairedPromotion(pairs.control, pairs.candidate, options)\n}\n\nfunction validateCalls(\n calls: ReadonlyArray<PairedPromotionPowerCall>,\n): ReadonlyArray<PairedPromotionPowerCall> {\n if (!Array.isArray(calls) || calls.length === 0) {\n throw new Error('pairedPromotionPower: at least one call is required')\n }\n calls.forEach((call, i) => {\n if (call.outcome !== 'delta' && call.outcome !== 'pass') {\n throw new Error(`pairedPromotionPower: calls[${i}].outcome must be 'delta' or 'pass'`)\n }\n if (call.options === null || typeof call.options !== 'object') {\n throw new Error(`pairedPromotionPower: calls[${i}].options must be an object`)\n }\n if (\n call.options.minPairs !== undefined &&\n (!Number.isInteger(call.options.minPairs) || call.options.minPairs < 1)\n ) {\n throw new Error(\n `pairedPromotionPower: calls[${i}].options.minPairs must be a positive integer`,\n )\n }\n // Every combination the decision itself refuses is refused here, before\n // the first draw, with the reason named.\n if (call.outcome === 'pass') {\n const scale = call.options.binaryScale\n if (scale === undefined || !Number.isFinite(scale) || scale <= 0) {\n throw new Error(\n `pairedPromotionPower: calls[${i}] is a 'pass' call and must declare a finite positive options.binaryScale`,\n )\n }\n if (call.options.continuous) {\n throw new Error(\n `pairedPromotionPower: calls[${i}] is a 'pass' call; continuous cannot accompany it`,\n )\n }\n if (call.options.statistic === 'median') {\n throw new Error(\n `pairedPromotionPower: calls[${i}] is a 'pass' call; binaryScale requires the mean statistic, not median`,\n )\n }\n } else if (call.options.binaryScale !== undefined) {\n throw new Error(\n `pairedPromotionPower: calls[${i}] is a 'delta' call and cannot declare binaryScale; use a 'pass' call for a two-point outcome`,\n )\n }\n })\n return calls\n}\n\nfunction validateAlternative(\n alternative: PairedPromotionAlternative,\n calls: ReadonlyArray<PairedPromotionPowerCall>,\n): PairedPromotionAlternative {\n if (!alternative || !Array.isArray(alternative.cells) || alternative.cells.length === 0) {\n throw new Error('pairedPromotionPower: alternative.cells must be a non-empty array')\n }\n const needsPass = calls.some((call) => call.outcome === 'pass')\n let total = 0\n alternative.cells.forEach((cell, i) => {\n if (!Number.isFinite(cell.probability) || cell.probability < 0) {\n throw new Error(`pairedPromotionPower: cells[${i}].probability must be a finite number >= 0`)\n }\n total += cell.probability\n if (needsPass) {\n if (\n !cell.pass ||\n typeof cell.pass.control !== 'boolean' ||\n typeof cell.pass.treatment !== 'boolean'\n ) {\n throw new Error(\n `pairedPromotionPower: cells[${i}].pass must give control and treatment booleans when a 'pass' call is configured`,\n )\n }\n }\n validateLaw(cell.delta, `cells[${i}].delta`)\n })\n if (Math.abs(total - 1) > 1e-9) {\n throw new Error(`pairedPromotionPower: cell probabilities must sum to 1, got ${total}`)\n }\n if (alternative.baseline !== undefined) validateLaw(alternative.baseline, 'baseline')\n return alternative\n}\n\nfunction validateLaw(law: PairedValueLaw, where: string): void {\n if (!law || typeof law !== 'object') {\n throw new Error(`pairedPromotionPower: ${where} must be a law object`)\n }\n switch (law.kind) {\n case 'point':\n if (!Number.isFinite(law.value)) {\n throw new Error(`pairedPromotionPower: ${where}.value must be finite`)\n }\n return\n case 'atoms': {\n if (!Array.isArray(law.atoms) || law.atoms.length === 0) {\n throw new Error(`pairedPromotionPower: ${where}.atoms must be a non-empty array`)\n }\n let total = 0\n law.atoms.forEach((atom, i) => {\n if (!Number.isFinite(atom.value)) {\n throw new Error(`pairedPromotionPower: ${where}.atoms[${i}].value must be finite`)\n }\n if (!Number.isFinite(atom.probability) || atom.probability < 0) {\n throw new Error(\n `pairedPromotionPower: ${where}.atoms[${i}].probability must be a finite number >= 0`,\n )\n }\n total += atom.probability\n })\n if (Math.abs(total - 1) > 1e-9) {\n throw new Error(\n `pairedPromotionPower: ${where}.atoms probabilities must sum to 1, got ${total}`,\n )\n }\n return\n }\n case 'normal':\n if (!Number.isFinite(law.mean) || !Number.isFinite(law.sd) || law.sd < 0) {\n throw new Error(`pairedPromotionPower: ${where} needs a finite mean and a finite sd >= 0`)\n }\n return\n default:\n throw new Error(`pairedPromotionPower: ${where}.kind must be 'point', 'atoms' or 'normal'`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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EAAE,KAAK,IAAI,KAAK,GACrE,MAAM,IAAI,MAAM,yBAAyB,MAAM,0CAA0C;GAE3F;EACF,SACE,MAAM,IAAI,MAAM,yBAAyB,MAAM,2CAA2C;CAC9F;AACF"}
|
|
@@ -1,11 +1,50 @@
|
|
|
1
1
|
import { a as hashCanonical, i as compareCodeUnits, r as canonicalString } from "./canonical-CicJlINA.js";
|
|
2
|
-
import {
|
|
3
|
-
import { i as pairedDeltaTest, r as minimumPairsForPairedDeltaTest, t as decidePairedPromotion } from "./paired-promotion-decision-
|
|
4
|
-
import { a as SearchLedgerError } from "./search-ledger-file-
|
|
2
|
+
import { _ as DECISION_PAIRED_DELTA_STATISTIC, pt as mean, rt as confidenceInterval } from "./statistics-CHs0jlsY.js";
|
|
3
|
+
import { i as pairedDeltaTest, r as minimumPairsForPairedDeltaTest, t as decidePairedPromotion } from "./paired-promotion-decision-BoWHWL1i.js";
|
|
4
|
+
import { a as SearchLedgerError } from "./search-ledger-file-J8Xh9pU_.js";
|
|
5
|
+
import { l as searchUnitScores, p as USD_TOLERANCE, t as FileSearchLedger, u as searchCellId } from "./search-ledger-D_ENQh0d.js";
|
|
5
6
|
import { c as redactText } from "./redact-zp_ILC4l.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { n as pairedPromotionPower } from "./paired-promotion-power-BXH3gzvs.js";
|
|
8
|
+
import { t as acquireSingleRunLock } from "./single-run-lock-BSKsoeQF.js";
|
|
9
|
+
/** The kernel every `runSearch` ledger names as its search implementation. */
|
|
10
|
+
const SEARCH_KERNEL_SOURCE = {
|
|
11
|
+
uri: "npm:@tangle-network/agent-eval#runSearch",
|
|
12
|
+
revision: hashCanonical({
|
|
13
|
+
name: "tangle.search-kernel.2026-09",
|
|
14
|
+
dispatch: "claim, then rung and root, then screen, then train; first allocated first within a stage",
|
|
15
|
+
expansion: "when no cell waits, fewer than twice the lanes capacity run, the cap admits one proposal and its expected screens, and overspend has not taken the search past its cap",
|
|
16
|
+
parents: "a policy names at least one parent, and every parent finished its screen",
|
|
17
|
+
reservation: {
|
|
18
|
+
hard: "the lane per-cell maximum",
|
|
19
|
+
estimate: "1.5 times the p99 of the lane settled cells once 20 settled, else the lane prior"
|
|
20
|
+
},
|
|
21
|
+
retries: "a retryable errored attempt runs again, up to maxAttempts",
|
|
22
|
+
rungs: "when a node finishes its cells, the allocator names the nodes it advances, deepest rung first; each is recorded advanced and its rung allocated when the cap admits the rung",
|
|
23
|
+
resume: "an unrecorded operation is recorded failed at an unknown cost with floor 0; a recorded proposal is finished from its stored output; an unsettled cell is offered to adopt before it runs",
|
|
24
|
+
writers: "one kernel per ledger file on a host, by a pid lock beside the ledger",
|
|
25
|
+
divergence: "a node whose train mean over shared units rises above its parent while its descriptive or bootstrap selection interval against the parent lies wholly on the worse side is decided invalid when its cells finish",
|
|
26
|
+
claim: "with a test split: after expansion stops, the claim plan is stored on the claim operation, the finalists are decided, beforeClaim records or refuses exposure on the sealed roster before test allocation or resumed dispatch, the root and finalist test cells run together, and the claim decides; the kernel refuses to start a claim without a selection split, a minimumEffect, a pinned judge, or (under a cap) a claim reserve for the root and 3 finalists plus a cap for one screening round",
|
|
27
|
+
close: "the allocator prunes the nodes left waiting on a rung, except the policy leader; then, with a test split, the claim decides; without one, the policy leader is selected when it has a scored cell; every other undecided node is rejected",
|
|
28
|
+
complete: "a node leads only when it has a scored cell on the ranked split and no cell there ended unscored: a final unscored outcome, or an error with no attempt left"
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
/** The operation that holds the claim's plan. */
|
|
32
|
+
const CLAIM_OPERATION = "claim";
|
|
33
|
+
const ESTIMATE_MARGIN = 1.5;
|
|
34
|
+
/** Dispatch order: claim cells first, then rungs and the root, then screens, then train. */
|
|
35
|
+
const STAGE_PRIORITY = {
|
|
36
|
+
claim: 0,
|
|
37
|
+
rung: 1,
|
|
38
|
+
root: 1,
|
|
39
|
+
screen: 2,
|
|
40
|
+
train: 3,
|
|
41
|
+
external: 3
|
|
42
|
+
};
|
|
43
|
+
/** The expansion index a kernel operation id encodes, or null. */
|
|
44
|
+
function searchExpansionIndex(operationId) {
|
|
45
|
+
const match = /^expand-(\d+)$/.exec(operationId);
|
|
46
|
+
return match ? Number(match[1]) : null;
|
|
47
|
+
}
|
|
9
48
|
// src/statistics/normalize-signed-zero.ts
|
|
10
49
|
/** Normalize IEEE negative zero before numerical evidence reaches canonical JSON. */
|
|
11
50
|
function normalizeSignedZero(value) {
|
|
@@ -898,45 +937,6 @@ function closedSearchResult(state) {
|
|
|
898
937
|
function isTerminal(node) {
|
|
899
938
|
return node.status !== null && node.status !== "advanced";
|
|
900
939
|
}
|
|
901
|
-
/** The kernel every `runSearch` ledger names as its search implementation. */
|
|
902
|
-
const SEARCH_KERNEL_SOURCE = {
|
|
903
|
-
uri: "npm:@tangle-network/agent-eval#runSearch",
|
|
904
|
-
revision: hashCanonical({
|
|
905
|
-
name: "tangle.search-kernel.2026-09",
|
|
906
|
-
dispatch: "claim, then rung and root, then screen, then train; first allocated first within a stage",
|
|
907
|
-
expansion: "when no cell waits, fewer than twice the lanes capacity run, the cap admits one proposal and its expected screens, and overspend has not taken the search past its cap",
|
|
908
|
-
parents: "a policy names at least one parent, and every parent finished its screen",
|
|
909
|
-
reservation: {
|
|
910
|
-
hard: "the lane per-cell maximum",
|
|
911
|
-
estimate: "1.5 times the p99 of the lane settled cells once 20 settled, else the lane prior"
|
|
912
|
-
},
|
|
913
|
-
retries: "a retryable errored attempt runs again, up to maxAttempts",
|
|
914
|
-
rungs: "when a node finishes its cells, the allocator names the nodes it advances, deepest rung first; each is recorded advanced and its rung allocated when the cap admits the rung",
|
|
915
|
-
resume: "an unrecorded operation is recorded failed at an unknown cost with floor 0; a recorded proposal is finished from its stored output; an unsettled cell is offered to adopt before it runs",
|
|
916
|
-
writers: "one kernel per ledger file on a host, by a pid lock beside the ledger",
|
|
917
|
-
divergence: "a node whose train mean over shared units rises above its parent while its descriptive or bootstrap selection interval against the parent lies wholly on the worse side is decided invalid when its cells finish",
|
|
918
|
-
claim: "with a test split: after expansion stops, the claim plan is stored on the claim operation, the finalists are decided, the root and finalist test cells run together, and the claim decides; the kernel refuses to start a claim without a selection split, a minimumEffect, a pinned judge, or (under a cap) a claim reserve for the root and 3 finalists plus a cap for one screening round",
|
|
919
|
-
close: "the allocator prunes the nodes left waiting on a rung, except the policy leader; then, with a test split, the claim decides; without one, the policy leader is selected when it has a scored cell; every other undecided node is rejected",
|
|
920
|
-
complete: "a node leads only when it has a scored cell on the ranked split and no cell there ended unscored: a final unscored outcome, or an error with no attempt left"
|
|
921
|
-
})
|
|
922
|
-
};
|
|
923
|
-
/** The operation that holds the claim's plan. */
|
|
924
|
-
const CLAIM_OPERATION = "claim";
|
|
925
|
-
const ESTIMATE_MARGIN = 1.5;
|
|
926
|
-
/** Dispatch order: claim cells first, then rungs and the root, then screens, then train. */
|
|
927
|
-
const STAGE_PRIORITY = {
|
|
928
|
-
claim: 0,
|
|
929
|
-
rung: 1,
|
|
930
|
-
root: 1,
|
|
931
|
-
screen: 2,
|
|
932
|
-
train: 3,
|
|
933
|
-
external: 3
|
|
934
|
-
};
|
|
935
|
-
/** The expansion index a kernel operation id encodes, or null. */
|
|
936
|
-
function searchExpansionIndex(operationId) {
|
|
937
|
-
const match = /^expand-(\d+)$/.exec(operationId);
|
|
938
|
-
return match ? Number(match[1]) : null;
|
|
939
|
-
}
|
|
940
940
|
// src/campaign/search-kernel-claim.ts
|
|
941
941
|
/** The sealed-test lifecycle: preflight, durable plan, cell allocation, and final claim. */
|
|
942
942
|
var SearchKernelClaim = class {
|
|
@@ -1049,6 +1049,13 @@ var SearchKernelClaim = class {
|
|
|
1049
1049
|
});
|
|
1050
1050
|
await this.host.refresh();
|
|
1051
1051
|
if (plan.test !== "run") return;
|
|
1052
|
+
await this.host.options.beforeClaim?.(structuredClone({
|
|
1053
|
+
searchId: this.host.recorder.searchId,
|
|
1054
|
+
claim: this.host.state.header.objective.claim,
|
|
1055
|
+
plan,
|
|
1056
|
+
candidateDigests: [root, ...plan.finalists.map((finalist) => finalist.nodeId)].map((nodeId) => this.host.state.node(nodeId).artifactDigest),
|
|
1057
|
+
tasks: this.host.state.header.splits.test.tasks
|
|
1058
|
+
}));
|
|
1052
1059
|
const missing = this.claimCells(plan.finalists.length, root, plan).map((cell) => ({
|
|
1053
1060
|
...cell,
|
|
1054
1061
|
cellId: searchCellId(this.host.recorder.searchId, cell.nodeId, cell.plan.taskId, "test", cell.plan.rep)
|
|
@@ -2321,6 +2328,6 @@ function paretoFrontierWithCrowding(candidates, objectives) {
|
|
|
2321
2328
|
if (frontier.length === 0) return [];
|
|
2322
2329
|
return crowdingDistance(frontier, objectives).sort((a, b) => b.distance - a.distance);
|
|
2323
2330
|
}
|
|
2324
|
-
export {
|
|
2331
|
+
export { searchEstimateMethod as C, CLAIM_OPERATION as D, normalizeSignedZero as E, SEARCH_KERNEL_SOURCE as O, searchCellSetDigest as S, seedFromDigest as T, searchClaimReserveUsd as _, searchDivergence as a, estimateNode as b, MIN_OUTCOMES_FOR_WEIGHT as c, rankingSplit as d, summarizeSamples as f, searchClaimDecision as g, planSearchClaim as h, runSearch as i, searchExpansionIndex as k, operatorYield as l, decideSearchClaim as m, paretoFrontier as n, searchPolicyView as o, SEARCH_CLAIM_RULE as p, paretoFrontierWithCrowding as r, EXPANSION_OPERATORS as s, dominates as t, INSUFFICIENT_FROM as u, verifySearchClaim as v, searchPosterior as w, estimateNodeFromCells as x, SEARCH_ESTIMATOR as y };
|
|
2325
2332
|
|
|
2326
|
-
//# sourceMappingURL=pareto-
|
|
2333
|
+
//# sourceMappingURL=pareto-B226QGVD.js.map
|