-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
537 additions
and
563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,14 @@ | ||
import * as P from './prelude.js'; | ||
import * as internal from './internal/Classify.js'; | ||
|
||
export const Label = { | ||
TN: 'TN', | ||
TP: 'TP', | ||
FP: 'FP', | ||
FN: 'FN', | ||
} as const; | ||
export type Label = 'TP' | 'TN' | 'FP' | 'FN'; | ||
|
||
export type Label = (typeof Label)[keyof typeof Label]; | ||
|
||
export const LabelSchema: P.Schema.Schema<Label> = P.Schema.Literal( | ||
'TP', | ||
'TN', | ||
'FP', | ||
'FN', | ||
); | ||
|
||
export const defaultIsNil = <I>(x: I): boolean => x === null || x === undefined; | ||
export const values = internal.values; | ||
|
||
export type Classify<O, T> = (output: O, expected: T) => Label; | ||
|
||
export const make = | ||
<O, T>( | ||
isEqual: (output: O, expected: T) => boolean, | ||
isOutputNil: (output: O) => boolean = defaultIsNil, | ||
isExpectedNil: (expected: T) => boolean = defaultIsNil, | ||
): Classify<O, T> => | ||
(output, expected) => { | ||
const eq = isEqual(output, expected); | ||
const oNil = isOutputNil(output); | ||
const eNil = isExpectedNil(expected); | ||
|
||
if (oNil && eNil) { | ||
return Label.TN; | ||
} | ||
|
||
if (!oNil && !eNil && eq) { | ||
return Label.TP; | ||
} | ||
|
||
if ((!oNil && eNil) || (!oNil && !eNil && !eq)) { | ||
return Label.FP; | ||
} | ||
|
||
return Label.FN; | ||
}; | ||
|
||
export type Stats = Record<Label, number> & { | ||
precision: number; | ||
recall: number; | ||
}; | ||
|
||
export const StatsSchema: P.Schema.Schema<Stats> = P.Schema.Struct({ | ||
TP: P.Schema.Number, | ||
TN: P.Schema.Number, | ||
FP: P.Schema.Number, | ||
FN: P.Schema.Number, | ||
precision: P.Schema.Number, | ||
recall: P.Schema.Number, | ||
}); | ||
|
||
export const Stats = { | ||
empty: (): Stats => ({ | ||
TP: 0, | ||
TN: 0, | ||
FP: 0, | ||
FN: 0, | ||
precision: 0, | ||
recall: 0, | ||
}), | ||
}; | ||
|
||
export const precision = (m: Stats): number => { | ||
const r = m.TP / (m.TP + m.FP); | ||
return isNaN(r) ? 0 : r; | ||
}; | ||
|
||
export const recall = (m: Stats): number => { | ||
const r = m.TP / (m.TP + m.FN); | ||
return isNaN(r) ? 0 : r; | ||
}; | ||
|
||
export const min = (xs: number[]): number => | ||
xs.reduce((min, x) => (x < min ? x : min), Infinity); | ||
|
||
export const max = (xs: number[]): number => | ||
xs.reduce((max, x) => (x > max ? x : max), -Infinity); | ||
|
||
export const mean = (xs: number[]): number | undefined => { | ||
if (xs.length === 0) { | ||
return undefined; | ||
} | ||
|
||
return xs.reduce((a, b) => a + b, 0) / xs.length; | ||
}; | ||
|
||
export const median = (xs: number[]): number | undefined => { | ||
if (xs.length === 0) { | ||
return undefined; | ||
} | ||
|
||
const sorted = xs.slice().sort((a, b) => a - b); | ||
const index = Math.floor(sorted.length / 2); | ||
|
||
return sorted.length % 2 === 0 | ||
? (sorted[index - 1] + sorted[index]) / 2 | ||
: sorted[index]; | ||
}; | ||
export const LabelSchema = internal.LabelSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as internal from './internal/DisplayConfig.js'; | ||
|
||
export type DisplayConfig = { | ||
/** @default true */ | ||
colorize: boolean; | ||
/** @default 2 */ | ||
columnPadding: number; | ||
corner: string; | ||
cornerLeft: string; | ||
cornerRight: string; | ||
cornerTop: string; | ||
cornerTopLeft: string; | ||
cornerTopRight: string; | ||
cornerBottomLeft: string; | ||
cornerBottomRight: string; | ||
cornerBottom: string; | ||
horizontal: string; | ||
vertical: string; | ||
}; | ||
|
||
export const makeDefault = internal.makeDefault; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,69 @@ | ||
export {summarize} from './Show/summarize.js'; | ||
export {diff} from './Show/diff.js'; | ||
export {stats} from './Show/stats.js'; | ||
export {DisplayConfig} from './Show/DisplayConfig.js'; | ||
import type {Stats} from './Classify.js'; | ||
import type {Diff} from './Test.js'; | ||
import type {TestRun} from './internal/Test.js'; | ||
import type * as P from './prelude.js'; | ||
|
||
export {summarize} from './internal/summarize.js'; | ||
export {diff} from './internal/diff.js'; | ||
export {stats} from './internal/stats.js'; | ||
|
||
export type DiffContext = { | ||
diff: Diff; | ||
}; | ||
|
||
export type DiffColumnNames = | ||
| 'TP' | ||
| 'TN' | ||
| 'FP' | ||
| 'FN' | ||
| 'precision' | ||
| 'recall'; | ||
|
||
export type DiffColumn = { | ||
name: DiffColumnNames; | ||
label: string; | ||
make: (ctx: DiffContext) => string[]; | ||
}; | ||
|
||
export type StatsContext = { | ||
stats: Stats; | ||
}; | ||
|
||
export type StatsColumnNames = | ||
| 'TP' | ||
| 'TN' | ||
| 'FP' | ||
| 'FN' | ||
| 'precision' | ||
| 'recall'; | ||
|
||
export type StatsColumn = { | ||
name: StatsColumnNames; | ||
label: string; | ||
make: (ctx: StatsContext) => string[]; | ||
}; | ||
|
||
export type SummarizeContext = { | ||
i: number; | ||
ids: string[]; | ||
testRun: TestRun; | ||
previousTestRun: P.O.Option<TestRun>; | ||
}; | ||
|
||
export type SummarizeColumnNames = | ||
| 'index' | ||
| 'hash' | ||
| 'input' | ||
| 'tags' | ||
| 'label' | ||
| 'expected' | ||
| 'result' | ||
| 'result_diff' | ||
| 'prev_result' | ||
| 'prev_result_diff'; | ||
|
||
export type SummarizeColumn = { | ||
name: SummarizeColumnNames; | ||
label: string; | ||
make: (ctx: SummarizeContext) => string[]; | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.