#!/usr/bin/env python3 # SPDX-License-Identifier: AGPL-3.0-or-later # Copyright (c) 2026 Christopher Vivian Duguay (uh-oh! TECHNIQUE / Sweetbrier) """ Risk Assessment != Safety Assurance (ivo_assurance_audit.py) Zero-dependency psychometric & statistical assurance verifier for auditing Independent Verification Organization (IVO) compliance claims (e.g., California SB 813 May 2027 rulemaking & SB 53 filings) and protecting evaluators such as METR from the 2008 Credit-Rating Agency Trap. Implements both frequentist parameter bounds and Bayesian predictive bounds: 1. Frequentist 1-sided Clopper-Pearson upper confidence bound (numerically stable via -expm1) when k = 0 failures occur in N IID rollouts: p_upper(N, alpha) = 1 - alpha**(1 / N) = -expm1(ln(alpha) / N) and exact induced upper confidence bound on the fleet-incident parameter R(p) = 1 - (1 - p)**M across M IID deployment runs: R_upper(N, M, alpha) = 1 - alpha**(M / N) = -expm1((M / N) * ln(alpha)) 2. Exact Bayesian Beta-Binomial posterior predictive probability of >= 1 fleet incident in M future IID runs given k = 0 in N eval runs: - Laplace Uniform Beta(1, 1) prior: P_pred = M / (N + M + 1) - Jeffreys Beta(0.5, 0.5) prior: P_pred = 1 - exp(lgamma(N+1) + lgamma(N+M+0.5) - lgamma(N+0.5) - lgamma(N+M+1)) 3. Required IID clean rollouts N* to bound fleet risk <= epsilon: - Frequentist parameter ceiling R_upper <= epsilon: N*_cp = ceil(M * ln(alpha) / ln1p(-epsilon)) - Bayesian Beta(1,1) predictive risk P_pred <= epsilon: N*_bayes = max(1, ceil(M * (1 - epsilon) / epsilon - 1)) 4. 2-Parameter Logistic (2PL) Item Response Theory (IRT) Differential Item Functioning (Uniform Delta_b & Non-Uniform a_wild != a_eval) per AERA/APA/NCME Standards & Messick (1995). Run: python3 ivo_assurance_audit.py python3 ivo_assurance_audit.py --json """ import json import math import sys from typing import Optional def _require_pos_int(val: object, name: str) -> int: if isinstance(val, bool) or not isinstance(val, int) or val <= 0: raise ValueError(f"{name} must be a positive integer (got {val!r}).") return val def _require_open_unit_float(val: object, name: str) -> float: if isinstance(val, bool) or not isinstance(val, (int, float)): raise ValueError(f"{name} must be a finite number in (0, 1) (got {val!r}).") f = float(val) if not math.isfinite(f) or f <= 0.0 or f >= 1.0: raise ValueError(f"{name} must lie strictly in (0, 1) (got {val!r}).") return f def _require_finite_float(val: object, name: str) -> float: if isinstance(val, bool) or not isinstance(val, (int, float)): raise ValueError(f"{name} must be a finite float (got {val!r}).") f = float(val) if not math.isfinite(f): raise ValueError(f"{name} must be finite (got {val!r}).") return f def zero_event_fleet_audit(n_eval: int, m_fleet: int, confidence: float = 0.95) -> dict: """Compute exact frequentist Clopper-Pearson and Bayesian Beta-Binomial k=0 fleet bounds.""" n = _require_pos_int(n_eval, "n_eval") m = _require_pos_int(m_fleet, "m_fleet") conf = _require_open_unit_float(confidence, "confidence") alpha = 1.0 - conf ln_alpha = math.log(alpha) # Numerically stable 1 - exp(x) = -expm1(x) avoiding float64 cancellation for huge N p_upper = -math.expm1(ln_alpha / float(n)) r_upper_cp = -math.expm1((float(m) / float(n)) * ln_alpha) # Exact Beta(1, 1) Laplace posterior predictive P(Y_fleet >= 1 | K_eval = 0, N) p_pred_laplace = float(m) / float(n + m + 1) # Exact Jeffreys Beta(0.5, 0.5) posterior predictive log_p0_jeffreys = ( math.lgamma(n + 1.0) + math.lgamma(n + m + 0.5) - math.lgamma(n + 0.5) - math.lgamma(n + m + 1.0) ) p_pred_jeffreys = -math.expm1(log_p0_jeffreys) return { "n_eval_rollouts": n, "observed_failures_k": 0, "confidence_level": conf, "alpha": round(alpha, 12), "p_upper_per_run": p_upper, "p_upper_pct": round(p_upper * 100.0, 4), "m_fleet_deployments": m, "clopper_pearson_fleet_ceiling": r_upper_cp, "clopper_pearson_fleet_ceiling_pct": round(r_upper_cp * 100.0, 4), "bayes_laplace_predictive_prob": p_pred_laplace, "bayes_laplace_predictive_pct": round(p_pred_laplace * 100.0, 4), "bayes_jeffreys_predictive_prob": p_pred_jeffreys, "bayes_jeffreys_predictive_pct": round(p_pred_jeffreys * 100.0, 4), } def required_clean_rollouts( m_fleet: int, target_fleet_ceiling: float = 0.01, confidence: float = 0.95 ) -> dict: """Minimum k=0 IID rollouts N* under both Clopper-Pearson parameter ceiling and Laplace prediction.""" m = _require_pos_int(m_fleet, "m_fleet") eps = _require_open_unit_float(target_fleet_ceiling, "target_fleet_ceiling") conf = _require_open_unit_float(confidence, "confidence") alpha = 1.0 - conf n_cp = int(math.ceil(float(m) * math.log(alpha) / math.log1p(-eps))) n_laplace = max(1, int(math.ceil(float(m) * (1.0 - eps) / eps - 1.0))) # Frequentist exchangeable prediction test: M / (N + M) <= alpha -> N >= M*(1-alpha)/alpha n_pivotal_pred = max(1, int(math.ceil(float(m) * (1.0 - alpha) / alpha))) return { "m_fleet_deployments": m, "target_ceiling_epsilon": eps, "confidence_level": conf, "n_required_clopper_pearson": n_cp, "n_required_bayes_laplace": n_laplace, "n_required_exchangeable_prediction_at_conf": n_pivotal_pred, } def logistic(z: float) -> float: zf = _require_finite_float(z, "z") if zf >= 0.0: return 1.0 / (1.0 + math.exp(-zf)) ez = math.exp(zf) return ez / (1.0 + ez) def irt_dif_audit( theta_minus_b_eval: float, discrimination_a_eval: float, delta_dif_logits: float, discrimination_a_wild: Optional[float] = None, ) -> dict: """ 2PL IRT measurement-invariance audit (Uniform + optional Non-Uniform DIF). - Uniform DIF: b_wild = b_eval - delta_dif_logits (threshold shift). - Non-Uniform DIF: discrimination_a_wild != discrimination_a_eval (capability cliff / sandbagging slope). """ th = _require_finite_float(theta_minus_b_eval, "theta_minus_b_eval") a_ev = _require_finite_float(discrimination_a_eval, "discrimination_a_eval") dif = _require_finite_float(delta_dif_logits, "delta_dif_logits") if a_ev <= 0.0: raise ValueError(f"discrimination_a_eval must be > 0 (got {a_ev}).") a_wi = a_ev if discrimination_a_wild is None else _require_finite_float( discrimination_a_wild, "discrimination_a_wild" ) if a_wi <= 0.0: raise ValueError(f"discrimination_a_wild must be > 0 (got {a_wi}).") p_eval = logistic(a_ev * th) p_wild = logistic(a_wi * (th + dif)) multiplier = (p_wild / p_eval) if p_eval > 0.0 else math.inf return { "theta_minus_b_eval": th, "discrimination_a_eval": a_ev, "discrimination_a_wild": a_wi, "delta_dif_logits": dif, "p_eval": p_eval, "p_eval_pct": round(p_eval * 100.0, 4), "p_wild": p_wild, "p_wild_pct": round(p_wild * 100.0, 4), "risk_underestimation_multiple": round(multiplier, 3) if math.isfinite(multiplier) else None, } def build_report() -> dict: return { "dossier": "010-ivo-audit", "attestation": "probabilistic_structural", "standards_framework": [ "ISAE 3000 (Revised) Para. 24(b)(ii) & 70 (Suitable Criteria & Disclaimer of Conclusion)", "AICPA AT-C § 105.27(b) & § 205.75 (Preconditions & Disclaimer of Opinion)", "AERA/APA/NCME Standards (2014) & Messick (1995) (Construct Validity & DIF)", ], "baseline_zero_failure_audit": zero_event_fleet_audit(n_eval=50, m_fleet=10000, confidence=0.95), "large_eval_zero_failure_audit": zero_event_fleet_audit(n_eval=500, m_fleet=100000, confidence=0.95), "sample_size_requirements_100k_at_1pct": required_clean_rollouts( m_fleet=100000, target_fleet_ceiling=0.01, confidence=0.95 ), "psychometric_dif_baseline": irt_dif_audit( theta_minus_b_eval=-2.5, discrimination_a_eval=1.5, delta_dif_logits=2.5 ), } def main() -> None: rep = build_report() if "--json" in sys.argv: print(json.dumps(rep, indent=2)) return b50 = rep["baseline_zero_failure_audit"] b500 = rep["large_eval_zero_failure_audit"] req = rep["sample_size_requirements_100k_at_1pct"] dif = rep["psychometric_dif_baseline"] print("=== DOSSIER #010: IVO & METR ASSURANCE vs. RISK ASSESSMENT AUDIT ===") print( f"[1] 0/{b50['n_eval_rollouts']} Clean Rollouts -> M={b50['m_fleet_deployments']:,} Fleet:\n" f" p_upper (95% CP) = {b50['p_upper_pct']:.2f}%/run | " f"CP Fleet Parameter Ceiling = {b50['clopper_pearson_fleet_ceiling_pct']:.2f}% | " f"Bayes Beta(1,1) Predictive = {b50['bayes_laplace_predictive_pct']:.2f}% " f"(Jeffreys = {b50['bayes_jeffreys_predictive_pct']:.2f}%)" ) print( f"[2] 0/{b500['n_eval_rollouts']} Clean Rollouts -> M={b500['m_fleet_deployments']:,} Fleet:\n" f" p_upper (95% CP) = {b500['p_upper_pct']:.2f}%/run | " f"CP Fleet Parameter Ceiling = {b500['clopper_pearson_fleet_ceiling_pct']:.2f}% | " f"Bayes Beta(1,1) Predictive = {b500['bayes_laplace_predictive_pct']:.2f}% " f"(Jeffreys = {b500['bayes_jeffreys_predictive_pct']:.2f}%)" ) print( f"[3] Clean IID Rollouts Required for <=1% Risk across M=100,000 Deployments:\n" f" Clopper-Pearson 95% Parameter Ceiling: N* = {req['n_required_clopper_pearson']:,}\n" f" Bayesian Beta(1,1) Posterior Predictive: N* = {req['n_required_bayes_laplace']:,}" ) print( f"[4] 2PL IRT DIF Audit (a={dif['discrimination_a_eval']}, Delta_DIF=+{dif['delta_dif_logits']} logits):\n" f" Lab Eval Risk = {dif['p_eval_pct']:.2f}% vs. Wild Risk = {dif['p_wild_pct']:.2f}% " f"({dif['risk_underestimation_multiple']}x underestimation)" ) if __name__ == "__main__": main()