From 35901cb636928071feb25eb8bb3812df8b635ecf Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Wed, 18 Nov 2026 01:16:27 +0800 Subject: [PATCH 1/9] EVAL-AUTH-03: exact noisy-audit Bayes value and fixed-budget frontier --- .../evaluation_noisy_authorization.py | 175 ++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 src/spiral_ln/evaluation_noisy_authorization.py diff --git a/src/spiral_ln/evaluation_noisy_authorization.py b/src/spiral_ln/evaluation_noisy_authorization.py new file mode 100644 index 00000000..bebe7cb9 --- /dev/null +++ b/src/spiral_ln/evaluation_noisy_authorization.py @@ -0,0 +1,175 @@ +"""EVAL-AUTH-03: exact Bayes value of a binary, noisy authorization audit. + +All probability arithmetic is Fraction-exact. The modeled authorization prior, +audit sensitivity and audit false-positive rate are assumptions about a finite +synthetic channel, not independently authenticated properties of an issuer. + +For independent tasks, and a fixed rule for interpreting audit reports, sorting +their known expected risk reductions is optimal for a nonadaptive fixed-budget +audit schedule. A private shared latent variable or outcome-dependent costs +requires an extended state space and a new analysis. +""" +from __future__ import annotations + +from dataclasses import dataclass +from fractions import Fraction +from itertools import combinations +from typing import Sequence + +Q = Fraction + + +def _prob(value: Q, field: str) -> Q: + if not isinstance(value, Fraction) or not Q(0) <= value <= Q(1): + raise ValueError(f"{field} must be an exact Fraction in [0,1]") + return value + + +@dataclass(frozen=True) +class AuditChannel: + prior: Q + sensitivity: Q + false_positive: Q + + def __post_init__(self) -> None: + _prob(self.prior, "prior") + _prob(self.sensitivity, "sensitivity") + _prob(self.false_positive, "false_positive") + + +def public_error(channel: AuditChannel) -> Q: + """Optimal symmetric binary-error risk without reading the audit.""" + return min(channel.prior, Q(1) - channel.prior) + + +def audited_error(channel: AuditChannel) -> Q: + """Optimal risk when a binary audit outcome is observed before action. + + The two terms are the smaller joint mass of (authorization, report) + for report=true and report=false. Marginalizing the report gives the + uninspected risk, so this expression can never exceed public_error. + """ + p, t, f = channel.prior, channel.sensitivity, channel.false_positive + yes = min(p * t, (Q(1) - p) * f) + no = min(p * (Q(1) - t), (Q(1) - p) * (Q(1) - f)) + return yes + no + + +def audit_value(channel: AuditChannel) -> Q: + value = public_error(channel) - audited_error(channel) + if value < 0: + raise AssertionError("Bayes value of information must be nonnegative") + return value + + +def decide_public(estimated: AuditChannel) -> bool: + """Grant authorization only on a strictly greater posterior.""" + return estimated.prior > Q(1, 2) + + +def decide_after_report(estimated: AuditChannel, *, report: bool) -> bool: + """Conditional Bayes action using the fitted audit model. + + Compares unnormalized joint masses, avoiding a division at zero-support + reports. Ties deny permission. + """ + p, t, f = estimated.prior, estimated.sensitivity, estimated.false_positive + if report: + positive = p * t + negative = (Q(1) - p) * f + else: + positive = p * (Q(1) - t) + negative = (Q(1) - p) * (Q(1) - f) + return positive > negative + + +def expected_error_under_rule( + true_channel: AuditChannel, + estimated_channel: AuditChannel, + *, inspect: bool, +) -> Q: + """Evaluate a frozen classifier against the true finite channel. + + The true channel determines risk only; the decision rule sees estimated + probabilities and a report if and only if inspect=True. + """ + p, t, f = true_channel.prior, true_channel.sensitivity, true_channel.false_positive + if not inspect: + return (Q(1) - p) if decide_public(estimated_channel) else p + + incorrect = Q(0) + for report in (False, True): + chooses_grant = decide_after_report(estimated_channel, report=report) + authorized_mass = p * (t if report else Q(1) - t) + forbidden_mass = (Q(1) - p) * (f if report else Q(1) - f) + incorrect += forbidden_mass if chooses_grant else authorized_mass + return incorrect + + +def rule_audit_value( + true_channel: AuditChannel, estimated_channel: AuditChannel, +) -> Q: + """Signed value of *a fixed fitted decision rule*. + + Unlike Bayes value, the value here may be negative when fitted + probabilities are wrong. + """ + return expected_error_under_rule( + true_channel, estimated_channel, inspect=False + ) - expected_error_under_rule( + true_channel, estimated_channel, inspect=True + ) + + +@dataclass(frozen=True) +class AuditCandidate: + case_id: str + value: Q + + def __post_init__(self) -> None: + if not isinstance(self.case_id, str) or not self.case_id: + raise ValueError("case ID required") + if not isinstance(self.value, Fraction): + raise TypeError("expected risk reduction must be exact Fraction") + + +def optimal_fixed_budget( + candidates: Sequence[AuditCandidate], budget: int, +) -> tuple[AuditCandidate, ...]: + """Choose exactly B public candidates by value, then stable case ID. + + This is an optimal nonadaptive schedule when expected per-case risk + reductions add. It does not choose based on the withheld audit report. + """ + rows = tuple(candidates) + if type(budget) is not int or not 0 <= budget <= len(rows): + raise ValueError("budget must be an integer between zero and case count") + if len({row.case_id for row in rows}) != len(rows): + raise ValueError("duplicate case ID") + return tuple(sorted(rows, key=lambda x: (-x.value, x.case_id))[:budget]) + + +def audit_budget_frontier(candidates: Sequence[AuditCandidate]) -> tuple[Q, ...]: + """Maximum additive expected gain after exactly 0..N inspections.""" + rows = tuple(candidates) + ranked = optimal_fixed_budget(rows, len(rows)) + result = [Q(0)] + total = Q(0) + for candidate in ranked: + total += candidate.value + result.append(total) + return tuple(result) + + +def brute_force_budget_gain(candidates: Sequence[AuditCandidate], budget: int) -> Q: + """Independent small-domain enumeration for verifying the sorting law.""" + rows = tuple(candidates) + if type(budget) is not int or not 0 <= budget <= len(rows): + raise ValueError("invalid fixed budget") + if len({row.case_id for row in rows}) != len(rows): + raise ValueError("duplicate case ID") + return max( + (sum((item.value for item in selected), Q(0)) + for selected in combinations(rows, budget)), + default=Q(0), + ) From 26cf88f0ed25f4152c55b3fa1f4ed3cdd53c19d9 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Wed, 18 Nov 2026 01:16:50 +0800 Subject: [PATCH 2/9] EVAL-AUTH-03: exact Bayes and exhaustive additive audit-budget regression tests --- tests/test_evaluation_noisy_authorization.py | 87 ++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/test_evaluation_noisy_authorization.py diff --git a/tests/test_evaluation_noisy_authorization.py b/tests/test_evaluation_noisy_authorization.py new file mode 100644 index 00000000..7aafa916 --- /dev/null +++ b/tests/test_evaluation_noisy_authorization.py @@ -0,0 +1,87 @@ +"""Independent exact-Fraction oracles for EVAL-AUTH-03.""" +from fractions import Fraction as Q +from itertools import product + +import pytest + +from spiral_ln.evaluation_noisy_authorization import ( + AuditCandidate, AuditChannel, audit_budget_frontier, audit_value, + audited_error, brute_force_budget_gain, decide_after_report, + decide_public, expected_error_under_rule, optimal_fixed_budget, + public_error, rule_audit_value, +) + + +def test_named_exact_channels_and_bayes_value(): + excellent = AuditChannel(Q(1,2), Q(9,10), Q(1,10)) + weak = AuditChannel(Q(1,2), Q(3,5), Q(2,5)) + rare_good = AuditChannel(Q(1,8), Q(9,10), Q(1,10)) + rare_weak = AuditChannel(Q(1,8), Q(3,5), Q(2,5)) + assert (public_error(excellent), audited_error(excellent), + audit_value(excellent)) == (Q(1,2), Q(1,10), Q(2,5)) + assert audit_value(weak) == Q(1,10) + assert audit_value(rare_good) == Q(1,40) + assert audit_value(rare_weak) == Q(0) + + +def test_bayes_value_nonnegative_on_complete_fifth_grid(): + grid = [Q(0), Q(1,4), Q(1,2), Q(3,4), Q(1)] + for p,t,f in product(grid, repeat=3): + ch = AuditChannel(p,t,f) + value = audit_value(ch) + assert value == public_error(ch) - audited_error(ch) + assert Q(0) <= audited_error(ch) <= public_error(ch) <= Q(1,2) + assert value <= public_error(ch) + assert expected_error_under_rule(ch,ch,inspect=False) == public_error(ch) + assert expected_error_under_rule(ch,ch,inspect=True) == audited_error(ch) + + +def test_true_channel_noisy_fitted_rule_can_hurt(): + true = AuditChannel(Q(3,5), Q(1,2), Q(1,2)) + overconfident = AuditChannel(Q(3,5), Q(99,100), Q(1,100)) + assert audit_value(true) == Q(0) + assert decide_public(overconfident) is True + assert decide_after_report(overconfident, report=True) + assert not decide_after_report(overconfident, report=False) + assert expected_error_under_rule(true,overconfident,inspect=False) == Q(2,5) + assert expected_error_under_rule(true,overconfident,inspect=True) == Q(1,2) + assert rule_audit_value(true,overconfident) == -Q(1,10) + + +def test_fixed_budget_matches_independent_subset_census(): + values = (-Q(1,4), Q(0), Q(1,8), Q(2,5)) + for n in range(0, 5): + for vector in product(values, repeat=n): + rows = [AuditCandidate(str(i), value) for i,value in enumerate(vector)] + frontier = audit_budget_frontier(rows) + assert len(frontier) == n+1 + for budget in range(n+1): + selected = optimal_fixed_budget(rows,budget) + value = sum((item.value for item in selected),Q(0)) + assert frontier[budget] == value + assert value == brute_force_budget_gain(rows,budget) + + +def test_ties_and_zero_budget_are_stable(): + rows = [ + AuditCandidate("b",Q(1,4)), AuditCandidate("a",Q(1,4)), + AuditCandidate("c",-Q(1,3)) + ] + assert [x.case_id for x in optimal_fixed_budget(rows,2)] == ["a","b"] + assert optimal_fixed_budget(rows,0) == () + assert audit_budget_frontier(rows) == (Q(0),Q(1,4),Q(1,2),Q(1,6)) + + +def test_invalid_inputs_fail_closed(): + with pytest.raises(ValueError): + AuditChannel(Q(11,10),Q(1),Q(0)) + with pytest.raises(ValueError): + AuditChannel(Q(1,2),Q(-1,10),Q(1,2)) + with pytest.raises(ValueError): + optimal_fixed_budget([AuditCandidate("a",Q(1))],2) + with pytest.raises(ValueError): + optimal_fixed_budget([AuditCandidate("a",Q(1)),AuditCandidate("a",Q(2))],1) + with pytest.raises(TypeError): + AuditCandidate("foo",1) + with pytest.raises(ValueError): + AuditCandidate("",Q(1)) From 32d73d86d04b8c5eb06ee61ea64e10ab823d2cf9 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Wed, 18 Nov 2026 01:17:12 +0800 Subject: [PATCH 3/9] EVAL-AUTH-03: independent exact-channel receipt with source SHA-256 --- scripts/verify_eval_auth03.py | 93 +++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 scripts/verify_eval_auth03.py diff --git a/scripts/verify_eval_auth03.py b/scripts/verify_eval_auth03.py new file mode 100644 index 00000000..f53ee21e --- /dev/null +++ b/scripts/verify_eval_auth03.py @@ -0,0 +1,93 @@ +"""Regenerate source-hashed EVAL-AUTH-03 exact rational evidence. + +PYTHONPATH=src python scripts/verify_eval_auth03.py --output /tmp/eval_auth03.json +""" +from __future__ import annotations + +import argparse +from fractions import Fraction as Q +from hashlib import sha256 +from itertools import product +import json +from pathlib import Path +import sys + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "src")) + +from spiral_ln.evaluation_noisy_authorization import ( + AuditCandidate, AuditChannel, audit_value, audited_error, + audit_budget_frontier, brute_force_budget_gain, public_error, + rule_audit_value, +) + + +def calculate() -> dict[str, object]: + calibration = { + "balanced_reliable": AuditChannel(Q(1, 2), Q(9,10), Q(1,10)), + "balanced_weak": AuditChannel(Q(1, 2), Q(3,5), Q(2,5)), + "rare_reliable": AuditChannel(Q(1, 8), Q(9,10), Q(1,10)), + "rare_weak": AuditChannel(Q(1, 8), Q(3,5), Q(2,5)), + "intermediate_reliable": AuditChannel(Q(1,3), Q(9,10), Q(1,10)), + } + values = { + name: { + "risk_without_audit": str(public_error(ch)), + "risk_after_audit": str(audited_error(ch)), + "audit_value": str(audit_value(ch)), + } for name,ch in calibration.items() + } + grid = (Q(0),Q(1,4),Q(1,2),Q(3,4),Q(1)) + audited = 0 + for p,t,f in product(grid,repeat=3): + ch = AuditChannel(p,t,f) + assert Q(0) <= audit_value(ch) <= public_error(ch) + audited += 1 + + scores = (-Q(1,4),Q(0),Q(1,8),Q(2,5)) + checked = 0 + for n in range(5): + for vector in product(scores,repeat=n): + rows = [AuditCandidate(f"case{i}",score) for i,score in enumerate(vector)] + frontier = audit_budget_frontier(rows) + for b in range(n+1): + assert frontier[b] == brute_force_budget_gain(rows,b) + checked += 1 + + bad_model = rule_audit_value( + AuditChannel(Q(3,5),Q(1,2),Q(1,2)), + AuditChannel(Q(3,5),Q(99,100),Q(1,100)), + ) + assert bad_model == -Q(1,10) + + paths = ( + "src/spiral_ln/evaluation_noisy_authorization.py", + "tests/test_evaluation_noisy_authorization.py", + "scripts/verify_eval_auth03.py", + "paper/noisy_authorization_audit_budget.md", + ) + return { + "schema": "eval_auth03_exact_v1", + "evidence_level": "algebraic identities and finite exact oracle enumeration", + "neural_models_run": 0, + "named_channels": values, + "noisy_channel_grid_checked": audited, + "fixed_budget_bruteforce_checks": checked, + "counterexample_fitted_rule_negative_value": str(bad_model), + "source_sha256": {name: sha256((ROOT / name).read_bytes()).hexdigest() + for name in paths}, + } + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--output",type=Path) + args = parser.parse_args() + result = calculate() + serialized = json.dumps(result,indent=2,sort_keys=True) + "\n" + if args.output: + args.output.parent.mkdir(parents=True,exist_ok=True) + args.output.write_text(serialized,encoding="utf-8") + print(args.output) + else: + print(serialized,end="") From 56c2399565cab6c4be6dfc031db6ff235cbf2754 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Wed, 18 Nov 2026 01:17:51 +0800 Subject: [PATCH 4/9] EVAL-AUTH-03: scope exact noisy audit Bayes gains, fitted-rule reversal and ECA-02 gate --- paper/noisy_authorization_audit_budget.md | 73 +++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 paper/noisy_authorization_audit_budget.md diff --git a/paper/noisy_authorization_audit_budget.md b/paper/noisy_authorization_audit_budget.md new file mode 100644 index 00000000..57f0952d --- /dev/null +++ b/paper/noisy_authorization_audit_budget.md @@ -0,0 +1,73 @@ +# EVAL-AUTH-03: noisy authorization, posterior errors and the audit-budget frontier + +**Status:** exact finite probability calculus and reproducible oracles. No model calls, issuer authentication or empirical audit calibration. The mathematical ingredients are classical Bayesian decision theory and the value-of-information principle, applied to the ECA authorization setting. + +## 1. A binary audit with finite false-positive and false-negative channels + +Let `A=1` mean the host policy truly permits an action, and let `p=P(A=1 | public)` be the prior conditional on the full public evidence. An optional independent audit returns `S∈{0,1}`, with + +``` +t = P(S=1 | A=1, public) (sensitivity) +f = P(S=1 | A=0, public) (false positive rate). +``` + +We assume exact `p,t,f∈[0,1]`, symmetric 0/1 decision loss and a controller that chooses the Bayes action, breaking posterior ties toward denial. + +Without inspection, the minimum error is `r0=min(p,1-p)`. If the audit report is observed before the decision, its two possible values yield exact expected error + +``` +r1 = min(p*t, (1-p)*f) + min(p*(1-t), (1-p)*(1-f)). +``` + +The error reduction `v=r0-r1≥0` follows from subadditivity of the minimum over nonnegative masses: `min(a,c)+min(b,d)≤min(a+b,c+d)`. This is an algebraic identity in the declared channel and cannot establish that a real issuer has the stated sensitivity or false-positive rate. + +| Conditional public prior / channel | Error before | Error after | Value | +|---|---:|---:|---:| +| `p=1/2; t=9/10; f=1/10` | 1/2 | 1/10 | **2/5** | +| `p=1/2; t=3/5; f=2/5` | 1/2 | 2/5 | 1/10 | +| `p=1/8; t=9/10; f=1/10` | 1/8 | 1/10 | 1/40 | +| `p=1/8; t=3/5; f=2/5` | 1/8 | 1/8 | 0 | +| `p=1/3; t=9/10; f=1/10` | 1/3 | 1/10 | 7/30 | + +## 2. Exact nonadaptive fixed-budget policy + +For independent root items `i` with additive symmetric error loss and an audit decision chosen before seeing any private reports, suppose a budget requires inspecting exactly `B` items. The best expected risk reduction is the sum of the `B` highest audit values, including negative values when the decoder is a *fixed misspecified rule*: + +``` +max_{I subset of {1..N}, |I|=B} Σ_{i∈I} v_i + = Σ_{j=1..B} v_(j), +``` + +where `v_(1)≥...≥v_(N)` are sorted values. This is the exchange argument for choosing the top-B weights. `optimal_fixed_budget` gives a deterministic tie-break by public case ID; `audit_budget_frontier` provides all N+1 exact budget levels; `brute_force_budget_gain` enumerates every subset for independent regression. + +This optimality claim is for an additive nonadaptive setting with public case information. Shared latent states across items, audit outcomes that change beliefs about another case, sequential cost constraints, and adversarially selected audit reports require a richer decision model. A fixed maximum-budget constraint (at most B audits) may skip negative-value inspections, while the implemented comparator fixes *exactly* B to preserve equal-cost policy comparisons. + +## 3. The fitted-controller failure mode + +A model can hold incorrect priors or incorrect audit calibration. `expected_error_under_rule(true_channel, estimated_channel, inspect=...)` evaluates its deterministic action rule under a distinct true channel. Its signed audit benefit may be negative. + +A complete exact witness is + +``` +true: p=3/5, t=1/2, f=1/2 (audit contains zero information) +estimated: p=3/5, t=99/100, f=1/100. +``` + +The fitted controller authorizes without inspection, giving true error `2/5`. With the imaginary discriminating audit in its posterior, it authorizes positive reports and denies negative reports, giving actual error `1/2`. Its true gain is `-1/10`. This demonstrates why source independence and a valid signature do not certify the informational quality of an audit. + +## 4. Reproducibility + +```bash +PYTHONPATH=src python -m pytest -q tests/test_evaluation_noisy_authorization.py +PYTHONPATH=src python scripts/verify_eval_auth03.py --output /tmp/eval_auth03.json +``` + +The unit suite checks the five published exact channels, enumerates 125 rational probability triples, compares true Bayes risk with the model's rule, and exhaustively checks the sorting law against independent fixed-budget subset enumeration for every one-to-four-case roster over four signed audit values. The verifier records exact-rational outcomes and SHA-256 of its code, tests and this note. Hosted CI independently replays them; until that passes, the Lean or Python claims remain candidate artifacts. + +## 5. Next ECA-02 experiment and source boundaries + +The first [Control-Harness ECA-01](https://github.com/MoralityLabAI/Control-Harness/pull/49) is merged and its preregistered result remains fixed at [the original run](https://github.com/MoralityLabAI/Control-Harness/actions/runs/44131080443). The posterior-free ECA-01 audit is a host-truth oracle, so its exact 28/64 inspection frontier is a theorem-calibration control. + +ECA-02 should introduce **publicly known but imperfect authorization priors** and **noisy signed audits**. Fit each decision policy only on a distinct calibration cohort, select inspection targets under the same fixed budget without reading held-out hidden labels or audit reports, then evaluate on independent held-out roots. Use a registered equal-cost policy family: fixed-order random selection, public-uncertainty selection, fitted audit-value selection, and an oracle that knows the declared synthetic channel. Report false authorizations and missed permitted actions separately, alongside inspection cost and total error. Group repeated observations from the same root; protect an untouched second cohort from tuning. A model-based predictor is a separate future step. + +The original [MathCan AUTHQ-02](https://github.com/patrickdugan/MathCan/pull/140) remains a deterministic information-limit theorem. This new work analyzes the additional error caused by a *noisy* audit and by beliefs that misrepresent that audit. Neither independently authenticates external issuer authorities nor proves real-world safety. From 3b3b36d0b1a186fe7e73d53ba2dcbadcc08fea89 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Wed, 18 Nov 2026 01:18:03 +0800 Subject: [PATCH 5/9] EVAL-AUTH-03: focused exact noisy-audit CI with source-hashed output --- .github/workflows/eval-auth03.yml | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/eval-auth03.yml diff --git a/.github/workflows/eval-auth03.yml b/.github/workflows/eval-auth03.yml new file mode 100644 index 00000000..140d8afa --- /dev/null +++ b/.github/workflows/eval-auth03.yml @@ -0,0 +1,38 @@ +name: EVAL-AUTH-03 exact noisy audit +on: + pull_request: + paths: + - 'src/spiral_ln/evaluation_noisy_authorization.py' + - 'tests/test_evaluation_noisy_authorization.py' + - 'scripts/verify_eval_auth03.py' + - 'paper/noisy_authorization_audit_budget.md' + - '.github/workflows/eval-auth03.yml' + push: + paths: + - 'src/spiral_ln/evaluation_noisy_authorization.py' + - 'tests/test_evaluation_noisy_authorization.py' + - 'scripts/verify_eval_auth03.py' + - 'paper/noisy_authorization_audit_budget.md' + - '.github/workflows/eval-auth03.yml' + workflow_dispatch: +permissions: + contents: read +jobs: + rational: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - name: Install tests + run: python -m pip install -e '.[test]' + - name: Independent exact rational tests + run: python -m pytest tests/test_evaluation_noisy_authorization.py -q + - name: Source-hashed receipt + run: PYTHONPATH=src python scripts/verify_eval_auth03.py --output "${{ runner.temp }}/eval_auth03.json" + - uses: actions/upload-artifact@v4 + with: + name: eval-auth03-exact-receipt + path: ${{ runner.temp }}/eval_auth03.json From 2e968c09b01c927b64023394df28830fbd168c14 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Wed, 18 Nov 2026 01:31:15 +0800 Subject: [PATCH 6/9] EVAL-AUTH-04: exact asymmetric false-authorization cost and noisy-audit value --- .../evaluation_noisy_authorization.py | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/src/spiral_ln/evaluation_noisy_authorization.py b/src/spiral_ln/evaluation_noisy_authorization.py index bebe7cb9..f2ead4e4 100644 --- a/src/spiral_ln/evaluation_noisy_authorization.py +++ b/src/spiral_ln/evaluation_noisy_authorization.py @@ -173,3 +173,105 @@ def brute_force_budget_gain(candidates: Sequence[AuditCandidate], budget: int) - for selected in combinations(rows, budget)), default=Q(0), ) + + +# EVAL-AUTH-04: explicit asymmetric authorization error costs. + +def _positive_cost(value: Q, field: str) -> Q: + if not isinstance(value, Fraction) or value <= 0: + raise ValueError(f"{field} must be a positive exact Fraction") + return value + + +def weighted_public_error( + channel: AuditChannel, *, false_grant_cost: Q, missed_grant_cost: Q = Q(1), +) -> Q: + """Bayes error when false authorization and missed authorization differ.""" + c_fp = _positive_cost(false_grant_cost, "false_grant_cost") + c_fn = _positive_cost(missed_grant_cost, "missed_grant_cost") + p = channel.prior + return min(c_fn * p, c_fp * (Q(1) - p)) + + +def weighted_audited_error( + channel: AuditChannel, *, false_grant_cost: Q, missed_grant_cost: Q = Q(1), +) -> Q: + """Minimum weighted risk after a finite noisy report is observed.""" + c_fp = _positive_cost(false_grant_cost, "false_grant_cost") + c_fn = _positive_cost(missed_grant_cost, "missed_grant_cost") + p, t, f = channel.prior, channel.sensitivity, channel.false_positive + yes = min(c_fn * p * t, c_fp * (Q(1) - p) * f) + no = min(c_fn * p * (Q(1) - t), c_fp * (Q(1) - p) * (Q(1) - f)) + return yes + no + + +def weighted_audit_value( + channel: AuditChannel, *, false_grant_cost: Q, missed_grant_cost: Q = Q(1), +) -> Q: + value = weighted_public_error( + channel, false_grant_cost=false_grant_cost, + missed_grant_cost=missed_grant_cost, + ) - weighted_audited_error( + channel, false_grant_cost=false_grant_cost, + missed_grant_cost=missed_grant_cost, + ) + if value < 0: + raise AssertionError("Bayes value of information must be nonnegative") + return value + + +def weighted_decide_public( + estimated: AuditChannel, *, false_grant_cost: Q, missed_grant_cost: Q = Q(1), +) -> bool: + c_fp = _positive_cost(false_grant_cost, "false_grant_cost") + c_fn = _positive_cost(missed_grant_cost, "missed_grant_cost") + return c_fn * estimated.prior > c_fp * (Q(1) - estimated.prior) + + +def weighted_decide_after_report( + estimated: AuditChannel, *, report: bool, + false_grant_cost: Q, missed_grant_cost: Q = Q(1), +) -> bool: + c_fp = _positive_cost(false_grant_cost, "false_grant_cost") + c_fn = _positive_cost(missed_grant_cost, "missed_grant_cost") + p,t,f=estimated.prior,estimated.sensitivity,estimated.false_positive + allowed_mass = p * (t if report else Q(1) - t) + forbidden_mass = (Q(1) - p) * (f if report else Q(1) - f) + return c_fn * allowed_mass > c_fp * forbidden_mass + + +def weighted_expected_error_under_rule( + true_channel: AuditChannel, estimated_channel: AuditChannel, + *, inspect: bool, false_grant_cost: Q, missed_grant_cost: Q = Q(1), +) -> Q: + """Weighted true loss of a frozen, potentially miscalibrated controller.""" + c_fp = _positive_cost(false_grant_cost, "false_grant_cost") + c_fn = _positive_cost(missed_grant_cost, "missed_grant_cost") + p,t,f=true_channel.prior,true_channel.sensitivity,true_channel.false_positive + if not inspect: + return c_fp*(Q(1)-p) if weighted_decide_public( + estimated_channel,false_grant_cost=c_fp,missed_grant_cost=c_fn + ) else c_fn*p + total=Q(0) + for report in (False,True): + allowed_mass = p*(t if report else Q(1)-t) + forbidden_mass = (Q(1)-p)*(f if report else Q(1)-f) + chosen = weighted_decide_after_report( + estimated_channel,report=report, + false_grant_cost=c_fp,missed_grant_cost=c_fn, + ) + total += c_fp*forbidden_mass if chosen else c_fn*allowed_mass + return total + + +def weighted_rule_audit_value( + true_channel: AuditChannel, estimated_channel: AuditChannel, + *, false_grant_cost: Q, missed_grant_cost: Q = Q(1), +) -> Q: + return weighted_expected_error_under_rule( + true_channel,estimated_channel,inspect=False, + false_grant_cost=false_grant_cost,missed_grant_cost=missed_grant_cost, + ) - weighted_expected_error_under_rule( + true_channel,estimated_channel,inspect=True, + false_grant_cost=false_grant_cost,missed_grant_cost=missed_grant_cost, + ) From a81aed2a7e032ac1127c4e4e1fffd2ac7e569884 Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Wed, 18 Nov 2026 01:31:36 +0800 Subject: [PATCH 7/9] EVAL-AUTH-04: exhaustive weighted calibration and observed 76/59 crossover checks --- tests/test_evaluation_noisy_authorization.py | 68 ++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/test_evaluation_noisy_authorization.py b/tests/test_evaluation_noisy_authorization.py index 7aafa916..41a53cac 100644 --- a/tests/test_evaluation_noisy_authorization.py +++ b/tests/test_evaluation_noisy_authorization.py @@ -9,6 +9,9 @@ audited_error, brute_force_budget_gain, decide_after_report, decide_public, expected_error_under_rule, optimal_fixed_budget, public_error, rule_audit_value, + weighted_public_error, weighted_audited_error, weighted_audit_value, + weighted_decide_public, weighted_decide_after_report, + weighted_expected_error_under_rule, weighted_rule_audit_value, ) @@ -85,3 +88,68 @@ def test_invalid_inputs_fail_closed(): AuditCandidate("foo",1) with pytest.raises(ValueError): AuditCandidate("",Q(1)) + + +def test_weighted_bayes_threshold_and_named_channels(): + reliable=AuditChannel(Q(1,2),Q(9,10),Q(1,10)) + weak=AuditChannel(Q(1,2),Q(3,5),Q(2,5)) + assert weighted_public_error(reliable,false_grant_cost=Q(2)) == Q(1,2) + assert weighted_audited_error(reliable,false_grant_cost=Q(2)) == Q(3,20) + assert weighted_audit_value(reliable,false_grant_cost=Q(2)) == Q(7,20) + assert weighted_audit_value(weak,false_grant_cost=Q(2)) == Q(0) + assert not weighted_decide_public(reliable,false_grant_cost=Q(2)) + likely=AuditChannel(Q(4,5),Q(9,10),Q(1,10)) + assert weighted_decide_public(likely,false_grant_cost=Q(2)) + assert weighted_decide_after_report(reliable,report=True, + false_grant_cost=Q(2)) + assert not weighted_decide_after_report(reliable,report=False, + false_grant_cost=Q(2)) + + +def test_all_weighted_bayes_decisions_match_exact_risk_grid(): + grid=(Q(0),Q(1,4),Q(1,2),Q(3,4),Q(1)) + for c_fp in (Q(1,2),Q(1),Q(2),Q(5)): + for p,t,f in product(grid,repeat=3): + ch=AuditChannel(p,t,f) + a=weighted_public_error(ch,false_grant_cost=c_fp) + b=weighted_audited_error(ch,false_grant_cost=c_fp) + assert Q(0) <= b <= a + assert weighted_audit_value(ch,false_grant_cost=c_fp)==a-b + assert weighted_expected_error_under_rule( + ch,ch,inspect=False,false_grant_cost=c_fp + )==a + assert weighted_expected_error_under_rule( + ch,ch,inspect=True,false_grant_cost=c_fp + )==b + if c_fp==Q(1): + assert a==public_error(ch) + assert b==audited_error(ch) + + +def test_weighted_policy_may_be_worse_with_wrong_audit_model(): + true=AuditChannel(Q(3,5),Q(1,2),Q(1,2)) + estimated=AuditChannel(Q(3,5),Q(99,100),Q(1,100)) + assert weighted_rule_audit_value( + true,estimated,false_grant_cost=Q(1) + )==-Q(1,10) + + +def test_eca02_frozen_policy_cost_crossover_is_exact(): + # These counts are post-readout observations; this test is an accounting + # identity, not preregistered validation of a newly optimized policy. + fitted_fp,fitted_fn=461,492 + uncertainty_fp,uncertainty_fn=343,644 + break_even=Q(76,59) + assert break_even*(fitted_fp-uncertainty_fp)==uncertainty_fn-fitted_fn + assert Q(1)*fitted_fp+fitted_fn < Q(1)*uncertainty_fp+uncertainty_fn + assert Q(2)*fitted_fp+fitted_fn > Q(2)*uncertainty_fp+uncertainty_fn + + +def test_invalid_weighted_costs_fail_closed(): + ch=AuditChannel(Q(1,2),Q(1,2),Q(1,2)) + for cost in (Q(0),Q(-1,4)): + with pytest.raises(ValueError): + weighted_audit_value(ch,false_grant_cost=cost) + with pytest.raises(ValueError): + weighted_decide_public(ch,false_grant_cost=Q(1), + missed_grant_cost=Q(0)) From e00f9e4e8fbbbccee66e2e000ff08961cdc4cf5c Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Wed, 18 Nov 2026 01:31:50 +0800 Subject: [PATCH 8/9] EVAL-AUTH-04: source-hash weighted channel census and safety cost crossover --- scripts/verify_eval_auth03.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/verify_eval_auth03.py b/scripts/verify_eval_auth03.py index f53ee21e..2b6b05bc 100644 --- a/scripts/verify_eval_auth03.py +++ b/scripts/verify_eval_auth03.py @@ -19,6 +19,8 @@ AuditCandidate, AuditChannel, audit_value, audited_error, audit_budget_frontier, brute_force_budget_gain, public_error, rule_audit_value, + weighted_public_error, weighted_audited_error, weighted_audit_value, + weighted_expected_error_under_rule, ) @@ -60,6 +62,27 @@ def calculate() -> dict[str, object]: ) assert bad_model == -Q(1,10) + cost_grid = 0 + for false_grant_cost in (Q(1,2),Q(1),Q(2),Q(5)): + for p,t,f in product(grid,repeat=3): + ch=AuditChannel(p,t,f) + before=weighted_public_error( + ch,false_grant_cost=false_grant_cost + ) + after=weighted_audited_error( + ch,false_grant_cost=false_grant_cost + ) + assert Q(0) <= after <= before + assert weighted_audit_value( + ch,false_grant_cost=false_grant_cost + )==before-after + assert weighted_expected_error_under_rule( + ch,ch,inspect=True,false_grant_cost=false_grant_cost + )==after + cost_grid+=1 + crossover=Q(76,59) + assert crossover*(461-343)==644-492 + paths = ( "src/spiral_ln/evaluation_noisy_authorization.py", "tests/test_evaluation_noisy_authorization.py", @@ -74,6 +97,8 @@ def calculate() -> dict[str, object]: "noisy_channel_grid_checked": audited, "fixed_budget_bruteforce_checks": checked, "counterexample_fitted_rule_negative_value": str(bad_model), + "cost_weighted_channel_grid_checked": cost_grid, + "eca02_observed_frozen_action_cost_crossover": str(crossover), "source_sha256": {name: sha256((ROOT / name).read_bytes()).hexdigest() for name in paths}, } From 1d59e59e404abc70169d96cddabd177cae2a274b Mon Sep 17 00:00:00 2001 From: Patrick Dugan Date: Wed, 18 Nov 2026 01:32:11 +0800 Subject: [PATCH 9/9] EVAL-AUTH-04: weighted false-grant decision theory and registered next hypothesis --- paper/noisy_authorization_audit_budget.md | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/paper/noisy_authorization_audit_budget.md b/paper/noisy_authorization_audit_budget.md index 57f0952d..1aeaad68 100644 --- a/paper/noisy_authorization_audit_budget.md +++ b/paper/noisy_authorization_audit_budget.md @@ -71,3 +71,33 @@ The first [Control-Harness ECA-01](https://github.com/MoralityLabAI/Control-Harn ECA-02 should introduce **publicly known but imperfect authorization priors** and **noisy signed audits**. Fit each decision policy only on a distinct calibration cohort, select inspection targets under the same fixed budget without reading held-out hidden labels or audit reports, then evaluate on independent held-out roots. Use a registered equal-cost policy family: fixed-order random selection, public-uncertainty selection, fitted audit-value selection, and an oracle that knows the declared synthetic channel. Report false authorizations and missed permitted actions separately, alongside inspection cost and total error. Group repeated observations from the same root; protect an untouched second cohort from tuning. A model-based predictor is a separate future step. The original [MathCan AUTHQ-02](https://github.com/patrickdugan/MathCan/pull/140) remains a deterministic information-limit theorem. This new work analyzes the additional error caused by a *noisy* audit and by beliefs that misrepresent that audit. Neither independently authenticates external issuer authorities nor proves real-world safety. + + +## 6. EVAL-AUTH-04: specify the cost of unauthorized approval + +After ECA-02's first preregistered readout, a consequential objective difference emerged. Symmetric-error fitted-value auditing completed 3,143/4,096 heldout decisions correctly, versus 3,109/4,096 for public-uncertainty auditing at the same 1,024 audits per arm. The fitted rule missed 152 fewer genuinely authorized actions but made 118 more unauthorized approvals. For the **frozen, already-recorded decisions** the weighted loss `λ FP + FN` crosses over at the exact retrospective arithmetic ratio `λ=76/59≈1.288`. That comparison motivates a *new* cost-registered experiment; the original study remains a symmetric-risk test. + +Let `c_FP > 0` penalize granting forbidden authorization and `c_FN > 0` penalize denying a permitted authorization. The Bayes decision grants only when `c_FN p > c_FP(1-p)`, equivalently `p > c_FP/(c_FP+c_FN)`. The best expected loss with the public prior is + +``` +R0 = min(c_FN * p, c_FP * (1-p)). +``` + +After the binary audit report: + +``` +R1 = min(c_FN * p*t, c_FP * (1-p)*f) + + min(c_FN * p*(1-t), c_FP * (1-p)*(1-f)). +``` + +The exact nonnegative value `V=R0-R1` follows by the same finite minimum-mass argument. Cost weighting changes both the **post-report decision** and **which cases deserve audit**, because the expected reduction is recomputed from asymmetric losses. + +For example, with `c_FP=2,c_FN=1`, a balanced high-fidelity audit (`p=1/2,t=9/10,f=1/10`) has weighted value `7/20`, while a balanced weak audit (`p=1/2,t=3/5,f=2/5`) has weighted value zero. The latter can still change the output when a mismatched decoder misinterprets its evidence; the theorem applies to the true Bayes decoder. + +The exact `weighted_expected_error_under_rule` function evaluates a fixed fitted model against a different true channel, retaining the possibility of a **negative** realized audit gain under miscalibration. The tests enumerate 500 conditional-channel/cost configurations, verify the cost-aware decision threshold and check the exact observed crossover identity. + +**New prospective decision:** ECA-03 should register `c_FP=2,c_FN=1` before any new heldout roots are sampled. It should compare calibrated cost-weighted value targeting, cost-weighted public uncertainty, and the original symmetric policy at equal audit budget. Training labels can be reused only when the training policy permits it and the training data are distinct from the new sealed cohort. All scoring must preserve the original forbidden/authorized denominators. + +The [registered ECA-02 synthetic readout](https://github.com/MoralityLabAI/Control-Harness/actions/runs/44136694988) and its [full source-hashed artifact](https://github.com/MoralityLabAI/Control-Harness/actions/runs/44136694988/artifacts/14353225355) remain unchanged; [ECA-02 PR #50](https://github.com/MoralityLabAI/Control-Harness/pull/50) records the research boundaries. A separate independent replay reconstructed 20,480/20,480 rows, all policy choices and all six calibrated stratum parameters. Its compressed raw SHA-256 is `699c1746267eb13e1921d8a5b725e15412e640f102d529cfc45128e5c7d67162`. + +**Limits:** The probabilities and host audit signatures are synthetic. The theorem is an exact algebraic statement about an assumed binary channel, without external authority, policy-ethics or model-performance certification.