@takk/bayesoutputgate 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +92 -0
- package/LICENSE +190 -0
- package/NOTICE +45 -0
- package/README.md +403 -0
- package/SECURITY.md +98 -0
- package/SPEC.md +467 -0
- package/dist/adapter/index.cjs +411 -0
- package/dist/adapter/index.d.cts +29 -0
- package/dist/adapter/index.d.ts +29 -0
- package/dist/adapter/index.js +404 -0
- package/dist/audit/index.cjs +82 -0
- package/dist/audit/index.d.cts +40 -0
- package/dist/audit/index.d.ts +40 -0
- package/dist/audit/index.js +77 -0
- package/dist/bayesfactor/index.cjs +152 -0
- package/dist/bayesfactor/index.d.cts +15 -0
- package/dist/bayesfactor/index.d.ts +15 -0
- package/dist/bayesfactor/index.js +149 -0
- package/dist/beta/index.cjs +180 -0
- package/dist/beta/index.d.cts +45 -0
- package/dist/beta/index.d.ts +45 -0
- package/dist/beta/index.js +178 -0
- package/dist/calibration/index.cjs +339 -0
- package/dist/calibration/index.d.cts +53 -0
- package/dist/calibration/index.d.ts +53 -0
- package/dist/calibration/index.js +333 -0
- package/dist/cli/index.cjs +968 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +966 -0
- package/dist/dimensions/index.cjs +106 -0
- package/dist/dimensions/index.d.cts +33 -0
- package/dist/dimensions/index.d.ts +33 -0
- package/dist/dimensions/index.js +104 -0
- package/dist/edge/index.cjs +1141 -0
- package/dist/edge/index.d.cts +12 -0
- package/dist/edge/index.d.ts +12 -0
- package/dist/edge/index.js +1109 -0
- package/dist/gate/index.cjs +803 -0
- package/dist/gate/index.d.cts +77 -0
- package/dist/gate/index.d.ts +77 -0
- package/dist/gate/index.js +799 -0
- package/dist/hypothesis/index.cjs +268 -0
- package/dist/hypothesis/index.d.cts +38 -0
- package/dist/hypothesis/index.d.ts +38 -0
- package/dist/hypothesis/index.js +266 -0
- package/dist/index.cjs +1141 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +1109 -0
- package/dist/likelihood/index.cjs +137 -0
- package/dist/likelihood/index.d.cts +23 -0
- package/dist/likelihood/index.d.ts +23 -0
- package/dist/likelihood/index.js +132 -0
- package/dist/node/index.cjs +1282 -0
- package/dist/node/index.d.cts +24 -0
- package/dist/node/index.d.ts +24 -0
- package/dist/node/index.js +1246 -0
- package/dist/policy/index.cjs +88 -0
- package/dist/policy/index.d.cts +11 -0
- package/dist/policy/index.d.ts +11 -0
- package/dist/policy/index.js +85 -0
- package/dist/types-bMjn1j4e.d.cts +159 -0
- package/dist/types-bMjn1j4e.d.ts +159 -0
- package/package.json +142 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AuditMeta, AuditEntry } from '../audit/index.cjs';
|
|
2
|
+
import { AssessOptions } from '../calibration/index.cjs';
|
|
3
|
+
import { HypothesisManager } from '../hypothesis/index.cjs';
|
|
4
|
+
import { e as DimensionModel, P as PolicyConfig, h as GateGuards, S as ScoreVector, g as GateDecision, L as LabeledObservation, A as AssumptionReport } from '../types-bMjn1j4e.cjs';
|
|
5
|
+
|
|
6
|
+
/** Evaluate one output's scores against the dimension models under a policy, in a single call. */
|
|
7
|
+
declare function evaluate(scores: ScoreVector, models: readonly DimensionModel[], policy: PolicyConfig, guards?: GateGuards): GateDecision;
|
|
8
|
+
/** Options for an {@link OutputGate}. */
|
|
9
|
+
interface OutputGateOptions {
|
|
10
|
+
readonly models: readonly DimensionModel[];
|
|
11
|
+
readonly policy: PolicyConfig;
|
|
12
|
+
/** Optional assumption guards applied to every decision. */
|
|
13
|
+
readonly guards?: GateGuards;
|
|
14
|
+
}
|
|
15
|
+
/** A stateless gate over fixed calibrated models and a fixed policy. */
|
|
16
|
+
declare class OutputGate {
|
|
17
|
+
private readonly models;
|
|
18
|
+
private readonly policy;
|
|
19
|
+
private readonly guards;
|
|
20
|
+
constructor(options: OutputGateOptions);
|
|
21
|
+
/** Evaluate one output's scores. */
|
|
22
|
+
evaluate(scores: ScoreVector): GateDecision;
|
|
23
|
+
/** A copy of the gate's dimension models. */
|
|
24
|
+
dimensionModels(): DimensionModel[];
|
|
25
|
+
}
|
|
26
|
+
/** Assumption guards for an {@link OutputGateMonitor}, computed from the fitted history. */
|
|
27
|
+
interface MonitorGuards extends AssessOptions {
|
|
28
|
+
/** When true, escalate if goodness-of-fit is inadequate for the fitted history. */
|
|
29
|
+
readonly requireGoodnessOfFit?: boolean;
|
|
30
|
+
/** When true, escalate if the dimensions are not conditionally independent. */
|
|
31
|
+
readonly requireIndependence?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Options for an {@link OutputGateMonitor}. */
|
|
34
|
+
interface OutputGateMonitorOptions {
|
|
35
|
+
readonly policy: PolicyConfig;
|
|
36
|
+
/** An existing hypothesis manager to continue calibrating, or a fresh one is created. */
|
|
37
|
+
readonly manager?: HypothesisManager;
|
|
38
|
+
/** Optional guards; when set, assumptions are assessed from the history on every {@link OutputGateMonitor.fit}. */
|
|
39
|
+
readonly guards?: MonitorGuards;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A gate that records every decision into an append-only audit chain and can recalibrate its models
|
|
43
|
+
* online as labeled outcomes are observed. The audit chain is the compliance evidence (EU AI Act):
|
|
44
|
+
* what was decided, on what evidence, sealed so it cannot be altered after the fact. When guards are
|
|
45
|
+
* configured, a batch {@link OutputGateMonitor.fit} also assesses the modeling assumptions, and the
|
|
46
|
+
* gate escalates rather than trusting a Bayes Factor from a misspecified model.
|
|
47
|
+
*/
|
|
48
|
+
declare class OutputGateMonitor {
|
|
49
|
+
private readonly manager;
|
|
50
|
+
private readonly policy;
|
|
51
|
+
private readonly chain;
|
|
52
|
+
private readonly guards;
|
|
53
|
+
private assumptions;
|
|
54
|
+
constructor(options: OutputGateMonitorOptions);
|
|
55
|
+
/** Fold one labeled observation into the calibration. Does not recompute the assumption report. */
|
|
56
|
+
observe(observation: LabeledObservation): this;
|
|
57
|
+
/** Fold a batch of labeled observations, and reassess the modeling assumptions when guarded. */
|
|
58
|
+
fit(observations: Iterable<LabeledObservation>): this;
|
|
59
|
+
/** Evaluate without recording. */
|
|
60
|
+
evaluate(scores: ScoreVector): GateDecision;
|
|
61
|
+
private guardsForEvaluate;
|
|
62
|
+
/** Evaluate and seal the decision into the audit chain. */
|
|
63
|
+
record(scores: ScoreVector, meta?: AuditMeta): Promise<{
|
|
64
|
+
decision: GateDecision;
|
|
65
|
+
entry: AuditEntry;
|
|
66
|
+
}>;
|
|
67
|
+
/** A copy of the audit chain. */
|
|
68
|
+
auditTrail(): AuditEntry[];
|
|
69
|
+
/** Number of sealed decisions. */
|
|
70
|
+
get auditLength(): number;
|
|
71
|
+
/** The most recent assumption report, present after a guarded {@link OutputGateMonitor.fit}. */
|
|
72
|
+
get assumptionReport(): AssumptionReport | undefined;
|
|
73
|
+
/** The current calibrated dimension models. */
|
|
74
|
+
models(): DimensionModel[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { type MonitorGuards, OutputGate, OutputGateMonitor, type OutputGateMonitorOptions, type OutputGateOptions, evaluate };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AuditMeta, AuditEntry } from '../audit/index.js';
|
|
2
|
+
import { AssessOptions } from '../calibration/index.js';
|
|
3
|
+
import { HypothesisManager } from '../hypothesis/index.js';
|
|
4
|
+
import { e as DimensionModel, P as PolicyConfig, h as GateGuards, S as ScoreVector, g as GateDecision, L as LabeledObservation, A as AssumptionReport } from '../types-bMjn1j4e.js';
|
|
5
|
+
|
|
6
|
+
/** Evaluate one output's scores against the dimension models under a policy, in a single call. */
|
|
7
|
+
declare function evaluate(scores: ScoreVector, models: readonly DimensionModel[], policy: PolicyConfig, guards?: GateGuards): GateDecision;
|
|
8
|
+
/** Options for an {@link OutputGate}. */
|
|
9
|
+
interface OutputGateOptions {
|
|
10
|
+
readonly models: readonly DimensionModel[];
|
|
11
|
+
readonly policy: PolicyConfig;
|
|
12
|
+
/** Optional assumption guards applied to every decision. */
|
|
13
|
+
readonly guards?: GateGuards;
|
|
14
|
+
}
|
|
15
|
+
/** A stateless gate over fixed calibrated models and a fixed policy. */
|
|
16
|
+
declare class OutputGate {
|
|
17
|
+
private readonly models;
|
|
18
|
+
private readonly policy;
|
|
19
|
+
private readonly guards;
|
|
20
|
+
constructor(options: OutputGateOptions);
|
|
21
|
+
/** Evaluate one output's scores. */
|
|
22
|
+
evaluate(scores: ScoreVector): GateDecision;
|
|
23
|
+
/** A copy of the gate's dimension models. */
|
|
24
|
+
dimensionModels(): DimensionModel[];
|
|
25
|
+
}
|
|
26
|
+
/** Assumption guards for an {@link OutputGateMonitor}, computed from the fitted history. */
|
|
27
|
+
interface MonitorGuards extends AssessOptions {
|
|
28
|
+
/** When true, escalate if goodness-of-fit is inadequate for the fitted history. */
|
|
29
|
+
readonly requireGoodnessOfFit?: boolean;
|
|
30
|
+
/** When true, escalate if the dimensions are not conditionally independent. */
|
|
31
|
+
readonly requireIndependence?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Options for an {@link OutputGateMonitor}. */
|
|
34
|
+
interface OutputGateMonitorOptions {
|
|
35
|
+
readonly policy: PolicyConfig;
|
|
36
|
+
/** An existing hypothesis manager to continue calibrating, or a fresh one is created. */
|
|
37
|
+
readonly manager?: HypothesisManager;
|
|
38
|
+
/** Optional guards; when set, assumptions are assessed from the history on every {@link OutputGateMonitor.fit}. */
|
|
39
|
+
readonly guards?: MonitorGuards;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A gate that records every decision into an append-only audit chain and can recalibrate its models
|
|
43
|
+
* online as labeled outcomes are observed. The audit chain is the compliance evidence (EU AI Act):
|
|
44
|
+
* what was decided, on what evidence, sealed so it cannot be altered after the fact. When guards are
|
|
45
|
+
* configured, a batch {@link OutputGateMonitor.fit} also assesses the modeling assumptions, and the
|
|
46
|
+
* gate escalates rather than trusting a Bayes Factor from a misspecified model.
|
|
47
|
+
*/
|
|
48
|
+
declare class OutputGateMonitor {
|
|
49
|
+
private readonly manager;
|
|
50
|
+
private readonly policy;
|
|
51
|
+
private readonly chain;
|
|
52
|
+
private readonly guards;
|
|
53
|
+
private assumptions;
|
|
54
|
+
constructor(options: OutputGateMonitorOptions);
|
|
55
|
+
/** Fold one labeled observation into the calibration. Does not recompute the assumption report. */
|
|
56
|
+
observe(observation: LabeledObservation): this;
|
|
57
|
+
/** Fold a batch of labeled observations, and reassess the modeling assumptions when guarded. */
|
|
58
|
+
fit(observations: Iterable<LabeledObservation>): this;
|
|
59
|
+
/** Evaluate without recording. */
|
|
60
|
+
evaluate(scores: ScoreVector): GateDecision;
|
|
61
|
+
private guardsForEvaluate;
|
|
62
|
+
/** Evaluate and seal the decision into the audit chain. */
|
|
63
|
+
record(scores: ScoreVector, meta?: AuditMeta): Promise<{
|
|
64
|
+
decision: GateDecision;
|
|
65
|
+
entry: AuditEntry;
|
|
66
|
+
}>;
|
|
67
|
+
/** A copy of the audit chain. */
|
|
68
|
+
auditTrail(): AuditEntry[];
|
|
69
|
+
/** Number of sealed decisions. */
|
|
70
|
+
get auditLength(): number;
|
|
71
|
+
/** The most recent assumption report, present after a guarded {@link OutputGateMonitor.fit}. */
|
|
72
|
+
get assumptionReport(): AssumptionReport | undefined;
|
|
73
|
+
/** The current calibrated dimension models. */
|
|
74
|
+
models(): DimensionModel[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { type MonitorGuards, OutputGate, OutputGateMonitor, type OutputGateMonitorOptions, type OutputGateOptions, evaluate };
|