@cogitator-ai/evals 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -14
- package/dist/calibrate-judge.d.ts +53 -0
- package/dist/calibrate-judge.d.ts.map +1 -0
- package/dist/calibrate-judge.js +114 -0
- package/dist/calibrate-judge.js.map +1 -0
- package/dist/datasets/dataset.d.ts.map +1 -1
- package/dist/datasets/dataset.js +3 -27
- package/dist/datasets/dataset.js.map +1 -1
- package/dist/eval-comparison.d.ts +71 -2
- package/dist/eval-comparison.d.ts.map +1 -1
- package/dist/eval-comparison.js +149 -42
- package/dist/eval-comparison.js.map +1 -1
- package/dist/index.d.ts +16 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/metrics/g-eval.d.ts +29 -0
- package/dist/metrics/g-eval.d.ts.map +1 -0
- package/dist/metrics/g-eval.js +89 -0
- package/dist/metrics/g-eval.js.map +1 -0
- package/dist/metrics/index.d.ts +3 -1
- package/dist/metrics/index.d.ts.map +1 -1
- package/dist/metrics/index.js +1 -0
- package/dist/metrics/index.js.map +1 -1
- package/dist/metrics/judge-prompt.d.ts +31 -0
- package/dist/metrics/judge-prompt.d.ts.map +1 -0
- package/dist/metrics/judge-prompt.js +90 -0
- package/dist/metrics/judge-prompt.js.map +1 -0
- package/dist/metrics/llm-judge.d.ts +96 -9
- package/dist/metrics/llm-judge.d.ts.map +1 -1
- package/dist/metrics/llm-judge.js +265 -120
- package/dist/metrics/llm-judge.js.map +1 -1
- package/dist/options.d.ts +4 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +9 -0
- package/dist/options.js.map +1 -0
- package/dist/pairwise.d.ts +53 -0
- package/dist/pairwise.d.ts.map +1 -0
- package/dist/pairwise.js +118 -0
- package/dist/pairwise.js.map +1 -0
- package/dist/schema.d.ts +16 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +17 -0
- package/dist/schema.js.map +1 -1
- package/dist/stats/bootstrap.d.ts +22 -0
- package/dist/stats/bootstrap.d.ts.map +1 -0
- package/dist/stats/bootstrap.js +34 -0
- package/dist/stats/bootstrap.js.map +1 -0
- package/dist/stats/correlation.d.ts +11 -0
- package/dist/stats/correlation.d.ts.map +1 -0
- package/dist/stats/correlation.js +42 -0
- package/dist/stats/correlation.js.map +1 -0
- package/dist/stats/effect-size.d.ts +7 -0
- package/dist/stats/effect-size.d.ts.map +1 -0
- package/dist/stats/effect-size.js +17 -0
- package/dist/stats/effect-size.js.map +1 -0
- package/dist/stats/holm.d.ts +7 -0
- package/dist/stats/holm.d.ts.map +1 -0
- package/dist/stats/holm.js +21 -0
- package/dist/stats/holm.js.map +1 -0
- package/dist/stats/index.d.ts +10 -2
- package/dist/stats/index.d.ts.map +1 -1
- package/dist/stats/index.js +7 -1
- package/dist/stats/index.js.map +1 -1
- package/dist/stats/mcnemar.d.ts +9 -0
- package/dist/stats/mcnemar.d.ts.map +1 -1
- package/dist/stats/mcnemar.js +27 -13
- package/dist/stats/mcnemar.js.map +1 -1
- package/dist/stats/normal.d.ts +5 -0
- package/dist/stats/normal.d.ts.map +1 -0
- package/dist/stats/normal.js +19 -0
- package/dist/stats/normal.js.map +1 -0
- package/dist/stats/precision.d.ts +12 -0
- package/dist/stats/precision.d.ts.map +1 -0
- package/dist/stats/precision.js +29 -0
- package/dist/stats/precision.js.map +1 -0
- package/dist/stats/random.d.ts +6 -0
- package/dist/stats/random.d.ts.map +1 -0
- package/dist/stats/random.js +25 -0
- package/dist/stats/random.js.map +1 -0
- package/dist/stats/ranks.d.ts +5 -0
- package/dist/stats/ranks.d.ts.map +1 -0
- package/dist/stats/ranks.js +24 -0
- package/dist/stats/ranks.js.map +1 -0
- package/dist/stats/t-test.d.ts +4 -0
- package/dist/stats/t-test.d.ts.map +1 -1
- package/dist/stats/t-test.js +9 -3
- package/dist/stats/t-test.js.map +1 -1
- package/dist/stats/wilcoxon.d.ts +19 -0
- package/dist/stats/wilcoxon.d.ts.map +1 -0
- package/dist/stats/wilcoxon.js +70 -0
- package/dist/stats/wilcoxon.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { EvalSuiteResult } from './eval-suite.js';
|
|
2
|
+
import type { JudgeContext } from './metrics/llm-judge.js';
|
|
3
|
+
export interface PairwiseOptions {
|
|
4
|
+
/** What makes one answer better than the other. Default: correct, relevant, complete, clear */
|
|
5
|
+
criteria?: string;
|
|
6
|
+
/** The name the result reports. Default `pairwise` */
|
|
7
|
+
name?: string;
|
|
8
|
+
}
|
|
9
|
+
export type PairwiseSide = 'baseline' | 'challenger';
|
|
10
|
+
export type PairwiseOutcome = PairwiseSide | 'tie';
|
|
11
|
+
/** One of the two verdicts on a case */
|
|
12
|
+
export interface PairwiseVerdict {
|
|
13
|
+
/** The side shown to the judge first, as answer A */
|
|
14
|
+
first: PairwiseSide;
|
|
15
|
+
/** The side the judge preferred, or `tie` */
|
|
16
|
+
preferred: PairwiseOutcome;
|
|
17
|
+
reasoning?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface PairwiseCase {
|
|
20
|
+
/** Position of the case in the dataset */
|
|
21
|
+
index: number;
|
|
22
|
+
input: string;
|
|
23
|
+
winner: PairwiseOutcome;
|
|
24
|
+
/** The verdict with the baseline first, then the one with the challenger first */
|
|
25
|
+
verdicts: PairwiseVerdict[];
|
|
26
|
+
/** The side that errored and so lost the case without a judge call */
|
|
27
|
+
errored?: PairwiseSide;
|
|
28
|
+
/** Why the judge gave no verdict in one of the orders, which makes the case a tie */
|
|
29
|
+
error?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface PairwiseResult {
|
|
32
|
+
name: string;
|
|
33
|
+
wins: {
|
|
34
|
+
baseline: number;
|
|
35
|
+
challenger: number;
|
|
36
|
+
};
|
|
37
|
+
ties: number;
|
|
38
|
+
/** Cases compared: those at least one side answered */
|
|
39
|
+
cases: number;
|
|
40
|
+
/** Challenger wins over the decided cases (wins of either side), NaN when none was decided */
|
|
41
|
+
winRate: number;
|
|
42
|
+
/** Cases the judge failed on in at least one order, counted as ties */
|
|
43
|
+
judgeErrors: number;
|
|
44
|
+
/** USD the judge calls cost, as far as the judge reported usage */
|
|
45
|
+
cost: number;
|
|
46
|
+
perCase: PairwiseCase[];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Asks the judge which side answered each case better, see `EvalComparisonOptions.pairwise`.
|
|
50
|
+
* Cases both sides errored on are left out
|
|
51
|
+
*/
|
|
52
|
+
export declare function judgePairwise(baseline: EvalSuiteResult, challenger: EvalSuiteResult, judge: JudgeContext, options: PairwiseOptions, concurrency: number, signal?: AbortSignal): Promise<PairwiseResult>;
|
|
53
|
+
//# sourceMappingURL=pairwise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pairwise.d.ts","sourceRoot":"","sources":["../src/pairwise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAUxD,MAAM,WAAW,eAAe;IAC9B,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,YAAY,CAAC;AAErD,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,KAAK,CAAC;AAEnD,wCAAwC;AACxC,MAAM,WAAW,eAAe;IAC9B,qDAAqD;IACrD,KAAK,EAAE,YAAY,CAAC;IACpB,6CAA6C;IAC7C,SAAS,EAAE,eAAe,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,eAAe,CAAC;IACxB,kFAAkF;IAClF,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,sEAAsE;IACtE,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,8FAA8F;IAC9F,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB;AA4GD;;;GAGG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,eAAe,EAC3B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,cAAc,CAAC,CAmCzB"}
|
package/dist/pairwise.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { judgePrompt, parseJudgeOutput, sumUsage, untilAborted, usageOf, } from './metrics/llm-judge.js';
|
|
2
|
+
import { conversationBlock, evidenceBlock, tagged, wrapped } from './metrics/judge-prompt.js';
|
|
3
|
+
/** The instructions of a pairwise verdict */
|
|
4
|
+
function pairwiseInstructions(criteria) {
|
|
5
|
+
const basis = criteria
|
|
6
|
+
? `on these criteria:\n${criteria}`
|
|
7
|
+
: 'overall: which is more correct, relevant, complete and clear';
|
|
8
|
+
return `You are comparing two answers to the same request to decide which one is better ${basis}\n\nThe order of the answers says nothing about their quality, and a longer answer is better only for what its length adds.\n\nScore 0 when <answer_a> is better, 1 when <answer_b> is better, 0.5 when neither is better.\n\nRespond with JSON: {"score": <0, 0.5 or 1>, "reasoning": "<explanation>"}`;
|
|
9
|
+
}
|
|
10
|
+
/** The case and the two answers, A then B. A multi-turn case shows each side's whole conversation */
|
|
11
|
+
function pairwiseMessage(a, b) {
|
|
12
|
+
const evidence = evidenceBlock(a, false);
|
|
13
|
+
const multiTurn = (a.case.turns?.length ?? 0) > 0;
|
|
14
|
+
const shared = [
|
|
15
|
+
...(multiTurn
|
|
16
|
+
? ['Each answer is a whole conversation, the user messages being the same in both.']
|
|
17
|
+
: [tagged('input', a.case.input)]),
|
|
18
|
+
...(evidence === undefined ? [] : [evidence]),
|
|
19
|
+
...(a.case.expected ? [tagged('expected', a.case.expected)] : []),
|
|
20
|
+
];
|
|
21
|
+
const answer = (tag, result) => multiTurn ? wrapped(tag, conversationBlock(result)) : tagged(tag, result.output);
|
|
22
|
+
return [...shared, answer('answer_a', a), answer('answer_b', b)].join('\n');
|
|
23
|
+
}
|
|
24
|
+
const other = (side) => side === 'baseline' ? 'challenger' : 'baseline';
|
|
25
|
+
async function ask(judge, instructions, first, a, b, signal) {
|
|
26
|
+
try {
|
|
27
|
+
const answered = await untilAborted(judge.cogitator.run({
|
|
28
|
+
input: judgePrompt(instructions, pairwiseMessage(a, b)),
|
|
29
|
+
...(signal && { signal }),
|
|
30
|
+
}), signal);
|
|
31
|
+
const usage = usageOf(answered.usage);
|
|
32
|
+
const verdict = parseJudgeOutput(answered.output);
|
|
33
|
+
if (!verdict)
|
|
34
|
+
return { error: 'could not parse judge response', ...(usage && { usage }) };
|
|
35
|
+
const score = verdict.outOf === undefined ? verdict.score : verdict.score / verdict.outOf;
|
|
36
|
+
const preferred = score < 0.5 ? first : score > 0.5 ? other(first) : 'tie';
|
|
37
|
+
return {
|
|
38
|
+
verdict: {
|
|
39
|
+
first,
|
|
40
|
+
preferred,
|
|
41
|
+
...(verdict.reasoning !== undefined && { reasoning: verdict.reasoning }),
|
|
42
|
+
},
|
|
43
|
+
...(usage && { usage }),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A case judged both ways round: the baseline first, then the challenger first. Agreeing
|
|
52
|
+
* verdicts give the case to that side, disagreeing ones or a tie make it a tie
|
|
53
|
+
*/
|
|
54
|
+
async function judgeCase(judge, instructions, index, baseline, challenger, signal) {
|
|
55
|
+
const input = baseline.case.input;
|
|
56
|
+
if (baseline.error !== undefined || challenger.error !== undefined) {
|
|
57
|
+
const errored = baseline.error !== undefined ? 'baseline' : 'challenger';
|
|
58
|
+
return { result: { index, input, winner: other(errored), verdicts: [], errored } };
|
|
59
|
+
}
|
|
60
|
+
const asked = await Promise.all([
|
|
61
|
+
ask(judge, instructions, 'baseline', baseline, challenger, signal),
|
|
62
|
+
ask(judge, instructions, 'challenger', challenger, baseline, signal),
|
|
63
|
+
]);
|
|
64
|
+
const usage = sumUsage(asked.map((one) => one.usage));
|
|
65
|
+
const verdicts = asked.flatMap((one) => (one.verdict ? [one.verdict] : []));
|
|
66
|
+
const errors = asked.flatMap((one) => (one.error === undefined ? [] : [one.error]));
|
|
67
|
+
const [first, second] = verdicts;
|
|
68
|
+
const winner = errors.length === 0 && first.preferred === second.preferred ? first.preferred : 'tie';
|
|
69
|
+
return {
|
|
70
|
+
result: {
|
|
71
|
+
index,
|
|
72
|
+
input,
|
|
73
|
+
winner,
|
|
74
|
+
verdicts,
|
|
75
|
+
...(errors.length > 0 && { error: errors.join(', ') }),
|
|
76
|
+
},
|
|
77
|
+
...(usage && { usage }),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Asks the judge which side answered each case better, see `EvalComparisonOptions.pairwise`.
|
|
82
|
+
* Cases both sides errored on are left out
|
|
83
|
+
*/
|
|
84
|
+
export async function judgePairwise(baseline, challenger, judge, options, concurrency, signal) {
|
|
85
|
+
const instructions = pairwiseInstructions(options.criteria);
|
|
86
|
+
const pairs = baseline.results.flatMap((b, index) => {
|
|
87
|
+
const c = challenger.results[index];
|
|
88
|
+
return c && (b.error === undefined || c.error === undefined) ? [{ index, b, c }] : [];
|
|
89
|
+
});
|
|
90
|
+
const judged = new Array(pairs.length);
|
|
91
|
+
let next = 0;
|
|
92
|
+
const worker = async () => {
|
|
93
|
+
while (next < pairs.length && !signal?.aborted) {
|
|
94
|
+
const at = next++;
|
|
95
|
+
const { index, b, c } = pairs[at];
|
|
96
|
+
judged[at] = await judgeCase(judge, instructions, index, b, c, signal);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, pairs.length) }, worker));
|
|
100
|
+
signal?.throwIfAborted();
|
|
101
|
+
const perCase = judged.map((one) => one.result);
|
|
102
|
+
const wins = {
|
|
103
|
+
baseline: perCase.filter((one) => one.winner === 'baseline').length,
|
|
104
|
+
challenger: perCase.filter((one) => one.winner === 'challenger').length,
|
|
105
|
+
};
|
|
106
|
+
const decided = wins.baseline + wins.challenger;
|
|
107
|
+
return {
|
|
108
|
+
name: options.name ?? 'pairwise',
|
|
109
|
+
wins,
|
|
110
|
+
ties: perCase.length - decided,
|
|
111
|
+
cases: perCase.length,
|
|
112
|
+
winRate: decided === 0 ? Number.NaN : wins.challenger / decided,
|
|
113
|
+
judgeErrors: perCase.filter((one) => one.error !== undefined).length,
|
|
114
|
+
cost: judged.reduce((sum, one) => sum + (one.usage?.cost ?? 0), 0),
|
|
115
|
+
perCase,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=pairwise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pairwise.js","sourceRoot":"","sources":["../src/pairwise.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,QAAQ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G,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG;QACX,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,MAAM;QACnE,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,YAAY,CAAC,CAAC,MAAM;KACxE,CAAC;IACF,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC;IAChD,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,UAAU;QAChC,IAAI;QACJ,IAAI,EAAE,OAAO,CAAC,MAAM,GAAG,OAAO;QAC9B,KAAK,EAAE,OAAO,CAAC,MAAM;QACrB,OAAO,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,OAAO;QAC/D,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,MAAM;QACpE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;QAClE,OAAO;KACR,CAAC;AACJ,CAAC"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface JudgeCogitator {
|
|
|
30
30
|
run(agent: unknown, options: {
|
|
31
31
|
input: string;
|
|
32
32
|
useMemory?: boolean;
|
|
33
|
+
signal?: AbortSignal;
|
|
33
34
|
}): Promise<{
|
|
34
35
|
output: string;
|
|
35
36
|
structured?: unknown;
|
|
@@ -54,12 +55,27 @@ export declare const JudgeConfigSchema: z.ZodObject<{
|
|
|
54
55
|
cogitator: z.ZodOptional<z.ZodCustom<JudgeCogitator, JudgeCogitator>>;
|
|
55
56
|
cache: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<JudgeCache, JudgeCache>]>>;
|
|
56
57
|
concurrency: z.ZodOptional<z.ZodNumber>;
|
|
58
|
+
samples: z.ZodOptional<z.ZodNumber>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
export declare const PairwiseOptionsSchema: z.ZodObject<{
|
|
61
|
+
criteria: z.ZodOptional<z.ZodString>;
|
|
62
|
+
name: z.ZodOptional<z.ZodString>;
|
|
57
63
|
}, z.core.$strip>;
|
|
58
64
|
export declare const EvalComparisonConfigSchema: z.ZodObject<{
|
|
59
65
|
concurrency: z.ZodDefault<z.ZodNumber>;
|
|
60
66
|
timeout: z.ZodDefault<z.ZodNumber>;
|
|
61
67
|
retries: z.ZodDefault<z.ZodNumber>;
|
|
62
68
|
trials: z.ZodDefault<z.ZodNumber>;
|
|
69
|
+
alpha: z.ZodDefault<z.ZodNumber>;
|
|
70
|
+
test: z.ZodDefault<z.ZodEnum<{
|
|
71
|
+
t: "t";
|
|
72
|
+
wilcoxon: "wilcoxon";
|
|
73
|
+
}>>;
|
|
74
|
+
seed: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
75
|
+
pairwise: z.ZodOptional<z.ZodObject<{
|
|
76
|
+
criteria: z.ZodOptional<z.ZodString>;
|
|
77
|
+
name: z.ZodOptional<z.ZodString>;
|
|
78
|
+
}, z.core.$strip>>;
|
|
63
79
|
}, z.core.$strip>;
|
|
64
80
|
export type ExpectedToolCall = z.output<typeof ExpectedToolCallSchema>;
|
|
65
81
|
export type EvalCase = z.output<typeof EvalCaseSchema>;
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,wFAAwF;AACxF,eAAO,MAAM,sBAAsB;;;iBAGjC,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;;iBAWzB,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;iBAKhC,CAAC;AAEH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,CACD,KAAK,EAAE,OAAO,EACd,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,wFAAwF;AACxF,eAAO,MAAM,sBAAsB;;;iBAGjC,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;;iBAWzB,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;iBAKhC,CAAC;AAEH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,CACD,KAAK,EAAE,OAAO,EACd,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACpE,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC,CAAC;CAChF;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACnE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAmBD,eAAO,MAAM,iBAAiB;;;;;;;;iBAsB5B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;iBAGhC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;iBAYrC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACvE,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AACvD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAC3D,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACrE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACzE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC7D,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACjE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,0BAA0B,CAAC,CAAC"}
|
package/dist/schema.js
CHANGED
|
@@ -49,11 +49,28 @@ export const JudgeConfigSchema = z.object({
|
|
|
49
49
|
* metrics. Default: no limit of its own
|
|
50
50
|
*/
|
|
51
51
|
concurrency: z.number().int().positive().optional(),
|
|
52
|
+
/**
|
|
53
|
+
* Verdicts per case and judge metric, a positive integer, 1 by default. The score is the mean
|
|
54
|
+
* of the verdicts the judge gave, their spread is in the score's `details`. Each verdict is
|
|
55
|
+
* cached on its own, so use a `temperature` above 0 for verdicts that differ
|
|
56
|
+
*/
|
|
57
|
+
samples: z.number().int().positive().optional(),
|
|
58
|
+
});
|
|
59
|
+
export const PairwiseOptionsSchema = z.object({
|
|
60
|
+
criteria: z.string().trim().min(1, 'criteria must not be empty').optional(),
|
|
61
|
+
name: z.string().trim().min(1, 'name must not be empty').optional(),
|
|
52
62
|
});
|
|
53
63
|
export const EvalComparisonConfigSchema = z.object({
|
|
54
64
|
concurrency: z.number().int().min(1).default(5),
|
|
55
65
|
timeout: z.number().int().min(1000).default(30000),
|
|
56
66
|
retries: z.number().int().min(0).max(10).default(0),
|
|
57
67
|
trials: z.number().int().min(1).default(1),
|
|
68
|
+
/** Significance level, after Holm's correction across the compared metrics */
|
|
69
|
+
alpha: z.number().gt(0).lt(1).default(0.05),
|
|
70
|
+
/** Test for metrics that are not binary, and for latency and cost */
|
|
71
|
+
test: z.enum(['t', 'wilcoxon']).default('t'),
|
|
72
|
+
/** Seeds the bootstrap of the confidence intervals, so they are the same on every run */
|
|
73
|
+
seed: z.union([z.number(), z.string()]).optional(),
|
|
74
|
+
pairwise: PairwiseOptionsSchema.optional(),
|
|
58
75
|
});
|
|
59
76
|
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,wFAAwF;AACxF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CACxD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,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1C,8EAA8E;IAC9E,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3C,qEAAqE;IACrE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IAC5C,yFAAyF;IACzF,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE;IAClD,QAAQ,EAAE,qBAAqB,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const BootstrapOptionsSchema: z.ZodObject<{
|
|
3
|
+
confidence: z.ZodDefault<z.ZodNumber>;
|
|
4
|
+
resamples: z.ZodDefault<z.ZodNumber>;
|
|
5
|
+
seed: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
export type BootstrapOptions = z.input<typeof BootstrapOptionsSchema>;
|
|
8
|
+
export interface BootstrapInterval {
|
|
9
|
+
/** Lower bound of the interval */
|
|
10
|
+
low: number;
|
|
11
|
+
/** Upper bound of the interval */
|
|
12
|
+
high: number;
|
|
13
|
+
/** Mean of the values themselves */
|
|
14
|
+
mean: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Percentile bootstrap confidence interval of the mean: the values are resampled with
|
|
18
|
+
* replacement `resamples` times and the interval spans the middle `confidence` share of the
|
|
19
|
+
* resampled means. With `seed` the interval is the same on every run. All NaN for no values
|
|
20
|
+
*/
|
|
21
|
+
export declare function bootstrapCI(values: readonly number[], options?: BootstrapOptions): BootstrapInterval;
|
|
22
|
+
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/stats/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,sBAAsB;;;;iBAIjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,MAAM,WAAW,iBAAiB;IAChC,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,OAAO,GAAE,gBAAqB,GAC7B,iBAAiB,CAiBnB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { mean, percentile } from './percentiles.js';
|
|
3
|
+
import { seededRandom } from './random.js';
|
|
4
|
+
export const BootstrapOptionsSchema = z.object({
|
|
5
|
+
confidence: z.number().gt(0).lt(1).default(0.95),
|
|
6
|
+
resamples: z.number().int().positive().default(2000),
|
|
7
|
+
seed: z.union([z.number(), z.string()]).optional(),
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Percentile bootstrap confidence interval of the mean: the values are resampled with
|
|
11
|
+
* replacement `resamples` times and the interval spans the middle `confidence` share of the
|
|
12
|
+
* resampled means. With `seed` the interval is the same on every run. All NaN for no values
|
|
13
|
+
*/
|
|
14
|
+
export function bootstrapCI(values, options = {}) {
|
|
15
|
+
const { confidence, resamples, seed } = BootstrapOptionsSchema.parse(options);
|
|
16
|
+
if (values.length === 0)
|
|
17
|
+
return { low: Number.NaN, high: Number.NaN, mean: Number.NaN };
|
|
18
|
+
const random = seededRandom(seed);
|
|
19
|
+
const n = values.length;
|
|
20
|
+
const means = new Array(resamples);
|
|
21
|
+
for (let r = 0; r < resamples; r++) {
|
|
22
|
+
let sum = 0;
|
|
23
|
+
for (let i = 0; i < n; i++)
|
|
24
|
+
sum += values[Math.floor(random() * n)];
|
|
25
|
+
means[r] = sum / n;
|
|
26
|
+
}
|
|
27
|
+
const tail = (1 - confidence) / 2;
|
|
28
|
+
return {
|
|
29
|
+
low: percentile(means, tail),
|
|
30
|
+
high: percentile(means, 1 - tail),
|
|
31
|
+
mean: mean([...values]),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/stats/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IAChD,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACpD,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE;CACnD,CAAC,CAAC;AAaH;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,MAAyB,EACzB,UAA4B,EAAE;IAE9B,MAAM,EAAE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|
5
|
+
export declare function pearson(x: readonly number[], y: readonly number[]): number;
|
|
6
|
+
/**
|
|
7
|
+
* Spearman's rank correlation of paired values: Pearson's correlation of their ranks, ties
|
|
8
|
+
* sharing the mean of their ranks. NaN when Pearson's would be
|
|
9
|
+
*/
|
|
10
|
+
export declare function spearman(x: readonly number[], y: readonly number[]): number;
|
|
11
|
+
//# sourceMappingURL=correlation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlation.d.ts","sourceRoot":"","sources":["../../src/stats/correlation.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAkB1E;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAG3E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { mean } from './percentiles.js';
|
|
2
|
+
import { averageRanks } from './ranks.js';
|
|
3
|
+
import { isConstant, withoutNoise } from './precision.js';
|
|
4
|
+
function assertPaired(x, y) {
|
|
5
|
+
if (x.length !== y.length)
|
|
6
|
+
throw new Error('Sample arrays must have equal length');
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Pearson's correlation of paired values, from -1 to 1. NaN when there are fewer than 2 pairs
|
|
10
|
+
* or either side does not vary
|
|
11
|
+
*/
|
|
12
|
+
export function pearson(x, y) {
|
|
13
|
+
assertPaired(x, y);
|
|
14
|
+
if (x.length < 2)
|
|
15
|
+
return Number.NaN;
|
|
16
|
+
if (isConstant(x.map(withoutNoise)) || isConstant(y.map(withoutNoise)))
|
|
17
|
+
return Number.NaN;
|
|
18
|
+
const mx = mean([...x]);
|
|
19
|
+
const my = mean([...y]);
|
|
20
|
+
let sxy = 0;
|
|
21
|
+
let sxx = 0;
|
|
22
|
+
let syy = 0;
|
|
23
|
+
for (let i = 0; i < x.length; i++) {
|
|
24
|
+
const dx = x[i] - mx;
|
|
25
|
+
const dy = y[i] - my;
|
|
26
|
+
sxy += dx * dy;
|
|
27
|
+
sxx += dx * dx;
|
|
28
|
+
syy += dy * dy;
|
|
29
|
+
}
|
|
30
|
+
if (sxx === 0 || syy === 0)
|
|
31
|
+
return Number.NaN;
|
|
32
|
+
return Math.max(-1, Math.min(1, sxy / Math.sqrt(sxx * syy)));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Spearman's rank correlation of paired values: Pearson's correlation of their ranks, ties
|
|
36
|
+
* sharing the mean of their ranks. NaN when Pearson's would be
|
|
37
|
+
*/
|
|
38
|
+
export function spearman(x, y) {
|
|
39
|
+
assertPaired(x, y);
|
|
40
|
+
return pearson(averageRanks(x.map(withoutNoise)), averageRanks(y.map(withoutNoise)));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=correlation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"correlation.js","sourceRoot":"","sources":["../../src/stats/correlation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEvD,SAAS,YAAY,CAAC,CAAoB,EAAE,CAAoB;IAC9D,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;AACrF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,CAAoB,EAAE,CAAoB;IAChE,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnB,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC;IACpC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CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cohen's d for paired samples (dz): the mean of the paired differences over their standard
|
|
3
|
+
* deviation, the differences rounded to 12 significant digits. NaN with fewer than 2 differences,
|
|
4
|
+
* plus or minus Infinity when the differences are all the same and not 0, 0 when they are all 0
|
|
5
|
+
*/
|
|
6
|
+
export declare function cohensD(differences: readonly number[]): number;
|
|
7
|
+
//# sourceMappingURL=effect-size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effect-size.d.ts","sourceRoot":"","sources":["../../src/stats/effect-size.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAO9D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { mean, stdDev } from './percentiles.js';
|
|
2
|
+
import { isConstant, withoutNoise } from './precision.js';
|
|
3
|
+
/**
|
|
4
|
+
* Cohen's d for paired samples (dz): the mean of the paired differences over their standard
|
|
5
|
+
* deviation, the differences rounded to 12 significant digits. NaN with fewer than 2 differences,
|
|
6
|
+
* plus or minus Infinity when the differences are all the same and not 0, 0 when they are all 0
|
|
7
|
+
*/
|
|
8
|
+
export function cohensD(differences) {
|
|
9
|
+
if (differences.length < 2)
|
|
10
|
+
return Number.NaN;
|
|
11
|
+
const values = differences.map(withoutNoise);
|
|
12
|
+
if (isConstant(values)) {
|
|
13
|
+
return values[0] === 0 ? 0 : Math.sign(values[0]) * Number.POSITIVE_INFINITY;
|
|
14
|
+
}
|
|
15
|
+
return mean(values) / stdDev(values);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=effect-size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effect-size.js","sourceRoot":"","sources":["../../src/stats/effect-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEvD;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,WAA8B;IACpD,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC;IAC9C,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC7C,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAC/E,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Holm-Bonferroni adjusted p-values, in the order given: the i-th smallest of m p-values is
|
|
3
|
+
* multiplied by m - i + 1, kept from falling below the ones before it and capped at 1. Rejecting
|
|
4
|
+
* where an adjusted p-value is below alpha keeps the family-wise error rate at alpha
|
|
5
|
+
*/
|
|
6
|
+
export declare function holm(pValues: readonly number[]): number[];
|
|
7
|
+
//# sourceMappingURL=holm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"holm.d.ts","sourceRoot":"","sources":["../../src/stats/holm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAazD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Holm-Bonferroni adjusted p-values, in the order given: the i-th smallest of m p-values is
|
|
3
|
+
* multiplied by m - i + 1, kept from falling below the ones before it and capped at 1. Rejecting
|
|
4
|
+
* where an adjusted p-value is below alpha keeps the family-wise error rate at alpha
|
|
5
|
+
*/
|
|
6
|
+
export function holm(pValues) {
|
|
7
|
+
for (const p of pValues) {
|
|
8
|
+
if (!(p >= 0 && p <= 1))
|
|
9
|
+
throw new Error(`p-values must be between 0 and 1, got ${p}`);
|
|
10
|
+
}
|
|
11
|
+
const m = pValues.length;
|
|
12
|
+
const order = pValues.map((p, index) => ({ p, index })).sort((a, b) => a.p - b.p);
|
|
13
|
+
const adjusted = new Array(m);
|
|
14
|
+
let running = 0;
|
|
15
|
+
for (const [rank, { p, index }] of order.entries()) {
|
|
16
|
+
running = Math.max(running, Math.min(1, (m - rank) * p));
|
|
17
|
+
adjusted[index] = running;
|
|
18
|
+
}
|
|
19
|
+
return adjusted;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=holm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"holm.js","sourceRoot":"","sources":["../../src/stats/holm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAAC,OAA0B;IAC7C,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,EAAE,CAAC,CAAC;IACzF,CAAC;IACD,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IACzB,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClF,MAAM,QAAQ,GAAG,IAAI,KAAK,CAAS,CAAC,CAAC,CAAC;IACtC,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;QACnD,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACzD,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;IAC5B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/stats/index.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
export { percentile, mean, median, stdDev, aggregate } from './percentiles.js';
|
|
2
2
|
export { pairedTTest } from './t-test.js';
|
|
3
3
|
export type { TTestResult } from './t-test.js';
|
|
4
|
-
export { mcnemarsTest } from './mcnemar.js';
|
|
5
|
-
export type { McNemarResult } from './mcnemar.js';
|
|
4
|
+
export { mcnemarsTest, mcnemarExact } from './mcnemar.js';
|
|
5
|
+
export type { McNemarResult, McNemarExactResult } from './mcnemar.js';
|
|
6
|
+
export { wilcoxonSignedRank } from './wilcoxon.js';
|
|
7
|
+
export type { WilcoxonResult } from './wilcoxon.js';
|
|
8
|
+
export { bootstrapCI } from './bootstrap.js';
|
|
9
|
+
export type { BootstrapOptions, BootstrapInterval } from './bootstrap.js';
|
|
10
|
+
export { cohensD } from './effect-size.js';
|
|
11
|
+
export { holm } from './holm.js';
|
|
12
|
+
export { pearson, spearman } from './correlation.js';
|
|
13
|
+
export { seededRandom } from './random.js';
|
|
6
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stats/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stats/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/stats/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export { percentile, mean, median, stdDev, aggregate } from './percentiles.js';
|
|
2
2
|
export { pairedTTest } from './t-test.js';
|
|
3
|
-
export { mcnemarsTest } from './mcnemar.js';
|
|
3
|
+
export { mcnemarsTest, mcnemarExact } from './mcnemar.js';
|
|
4
|
+
export { wilcoxonSignedRank } from './wilcoxon.js';
|
|
5
|
+
export { bootstrapCI } from './bootstrap.js';
|
|
6
|
+
export { cohensD } from './effect-size.js';
|
|
7
|
+
export { holm } from './holm.js';
|
|
8
|
+
export { pearson, spearman } from './correlation.js';
|
|
9
|
+
export { seededRandom } from './random.js';
|
|
4
10
|
//# sourceMappingURL=index.js.map
|
package/dist/stats/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stats/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stats/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/stats/mcnemar.d.ts
CHANGED
|
@@ -4,4 +4,13 @@ export interface McNemarResult {
|
|
|
4
4
|
significant: boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare function mcnemarsTest(pairsACorrect_BIncorrect: number, pairsAIncorrect_BCorrect: number): McNemarResult;
|
|
7
|
+
export interface McNemarExactResult {
|
|
8
|
+
pValue: number;
|
|
9
|
+
significant: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Exact McNemar test: the two-sided binomial test of `b` against `b + c` discordant pairs at
|
|
13
|
+
* one half. Preferred over `mcnemarsTest` when there are few discordant pairs (below 25)
|
|
14
|
+
*/
|
|
15
|
+
export declare function mcnemarExact(b: number, c: number): McNemarExactResult;
|
|
7
16
|
//# sourceMappingURL=mcnemar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcnemar.d.ts","sourceRoot":"","sources":["../../src/stats/mcnemar.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcnemar.d.ts","sourceRoot":"","sources":["../../src/stats/mcnemar.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB;AAOD,wBAAgB,YAAY,CAC1B,wBAAwB,EAAE,MAAM,EAChC,wBAAwB,EAAE,MAAM,GAC/B,aAAa,CAiBf;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAoBrE"}
|
package/dist/stats/mcnemar.js
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const a1 = 0.254829592;
|
|
3
|
-
const a2 = -0.284496736;
|
|
4
|
-
const a3 = 1.421413741;
|
|
5
|
-
const a4 = -1.453152027;
|
|
6
|
-
const a5 = 1.061405429;
|
|
7
|
-
const p = 0.3275911;
|
|
8
|
-
const sign = x < 0 ? -1 : 1;
|
|
9
|
-
const absX = Math.abs(x);
|
|
10
|
-
const t = 1.0 / (1.0 + p * absX);
|
|
11
|
-
const y = 1.0 - ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t * Math.exp(-absX * absX);
|
|
12
|
-
return 1.0 - sign * y;
|
|
13
|
-
}
|
|
1
|
+
import { erfc } from './normal.js';
|
|
14
2
|
function chiSquareSurvival(x) {
|
|
15
3
|
if (x <= 0)
|
|
16
4
|
return 1;
|
|
@@ -31,4 +19,30 @@ export function mcnemarsTest(pairsACorrect_BIncorrect, pairsAIncorrect_BCorrect)
|
|
|
31
19
|
significant: pValue < 0.05,
|
|
32
20
|
};
|
|
33
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Exact McNemar test: the two-sided binomial test of `b` against `b + c` discordant pairs at
|
|
24
|
+
* one half. Preferred over `mcnemarsTest` when there are few discordant pairs (below 25)
|
|
25
|
+
*/
|
|
26
|
+
export function mcnemarExact(b, c) {
|
|
27
|
+
for (const [label, count] of [
|
|
28
|
+
['b', b],
|
|
29
|
+
['c', c],
|
|
30
|
+
]) {
|
|
31
|
+
if (!Number.isInteger(count) || count < 0) {
|
|
32
|
+
throw new Error(`${label} must be a non-negative integer, got ${count}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const n = b + c;
|
|
36
|
+
if (n === 0)
|
|
37
|
+
return { pValue: 1, significant: false };
|
|
38
|
+
const k = Math.min(b, c);
|
|
39
|
+
let logPmf = -n * Math.LN2;
|
|
40
|
+
let tail = 0;
|
|
41
|
+
for (let i = 0; i <= k; i++) {
|
|
42
|
+
tail += Math.exp(logPmf);
|
|
43
|
+
logPmf += Math.log((n - i) / (i + 1));
|
|
44
|
+
}
|
|
45
|
+
const pValue = Math.min(1, 2 * tail);
|
|
46
|
+
return { pValue, significant: pValue < 0.05 };
|
|
47
|
+
}
|
|
34
48
|
//# sourceMappingURL=mcnemar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcnemar.js","sourceRoot":"","sources":["../../src/stats/mcnemar.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcnemar.js","sourceRoot":"","sources":["../../src/stats/mcnemar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAQhC,SAAS,iBAAiB,CAAC,CAAS;IAClC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IACrB,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,wBAAgC,EAChC,wBAAgC;IAEhC,MAAM,CAAC,GAAG,wBAAwB,CAAC;IACnC,MAAM,CAAC,GAAG,wBAAwB,CAAC;IAEnC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;IACzD,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAE5C,OAAO;QACL,SAAS;QACT,MAAM;QACN,WAAW,EAAE,MAAM,GAAG,IAAI;KAC3B,CAAC;AACJ,CAAC;AAOD;;;GAGG;AACH,MAA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