Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/69596681-3f7c-8006-b9fd-01d9d8191763
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: python === <syntaxhighlight lang="python"># ============================================================================= === ANF_SCALED_REFERENCE_IMPLEMENTATION.py === === Single-file, fail-closed, deterministic ANF interpreter === === Scales experiments and executes 100 independent runs (sealed ensemble) === === Any deviation, nondeterminism, schema drift, or semantic violation => INVALID === === ============================================================================= === import hashlib import json import math import copy import sys from typing import Any, Dict, List, Tuple === ============================================================================= === === GLOBAL CONSTANTS / ENUMS === === ============================================================================= === STAND = 0 COLLAPSE = 1 PASS = "PASS" FAIL = "FAIL" SKIP = "SKIP" INVALID = "INVALID" === ============================================================================= === === HARD FAIL-CLOSED CORE === === ============================================================================= === def abort(msg: str): raise RuntimeError("INVALID|" + msg) def sha256(b: bytes) -> str: return hashlib.sha256(b).hexdigest() def canon(obj: Any) -> bytes: try: return json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=True).encode("utf-8") except Exception: abort("CANONICALIZATION_FAIL") def require(cond: bool, msg: str): if not cond: abort(msg) === ============================================================================= === === AXIOMS (BLOCK 1) === === ============================================================================= === def axioms(spec: Dict[str, Any]): for k in [ "A0_empirical_authority", "A1_no_synthetic_data", "A2_structure_frozen", "A3_binary_irreversible", "A4_monotone_falsification", "A5_no_optimization", "A6_no_hidden_state", "A7_reproducibility" ]: require(spec.get(k, False) is True, "AXIOM_FAIL_" + k) === ============================================================================= === === DATA VALIDITY (BLOCK 9) === === ============================================================================= === def data_valid(D: Dict[str, Any]) -> bool: require("data" in D and isinstance(D["data"], list) and len(D["data"]) > 0, "DATA_EMPTY") for d in D["data"]: require("y" in d and "Sigma" in d and "meta" in d, "DATA_SCHEMA") require(d["meta"].get("synthetic", False) is False, "SYNTHETIC_DATA") require("calibration_hash" in d["meta"], "NO_CAL_HASH") require("provenance_hash" in d["meta"], "NO_PROV_HASH") return True === ============================================================================= === === MODEL MAP (BLOCK 3) β FROZEN === === ============================================================================= === def P(theta: List[float], baseline: List[float]) -> List[float]: return [theta[i] + baseline[i] for i in range(len(theta))] === ============================================================================= === === RESIDUALS + STRUCTURE (BLOCKS 4,5) === === ============================================================================= === def residuals(D, theta, baseline): r = [] pred = P(theta, baseline) for i, d in enumerate(D["data"]): r.append(d["y"] - pred[i]) return r def structural(r, tau): for ri in r: if abs(ri) > tau: return True return False === ============================================================================= === === FEASIBILITY + IDENTIFIABILITY (BLOCKS 6,7) === === ============================================================================= === def feasible(theta_space, D, baseline, tau): for th in theta_space: if not structural(residuals(D, th, baseline), tau): return True return False def identifiable(theta_space): k = len(theta_space[0]) return (k if k > 0 else 0) === ============================================================================= === === LIKELIHOOD (BLOCK 8) === === ============================================================================= === def likelihood(r, eps, nu): v = 1.0 for ri in r: g = math.exp(-0.5 '' ri '' ri) t = (1 + (ri * ri) / nu) ** (-(nu + 1) / 2) v ''= (1 - eps) '' g + eps * t return v === ============================================================================= === === EVIDENCE (BLOCKS 10,11) === === ============================================================================= === def evidence(theta_space, D, baseline, eps, nu): Z = 0.0 for th in theta_space: Z += likelihood(residuals(D, th, baseline), eps, nu) return Z === ============================================================================= === === MONTE CARLO ROBUSTNESS (BLOCK 13) === === ============================================================================= === def monte_carlo(D, theta_space, baseline, tau, eps, nu, N, f_c): fails = 0 for j in range(N): Dj = copy.deepcopy(D) idx = j % len(Dj["data"]) Dj["data"][idx]["y"] *= -1 Zj = evidence(theta_space, Dj, baseline, eps, nu) if Zj <= 0.0: fails += 1 if fails / (j + 1) >= f_c: return True return False === ============================================================================= === === PRECISION SCALING (BLOCK 14) === === ============================================================================= === def precision(D, theta_space, baseline, tau): for p in range(1, 8): tau_p = tau / (2 ** p) for th in theta_space: if structural(residuals(D, th, baseline), tau_p): return True return False === ============================================================================= === === ATTRIBUTION (BLOCK 15) === === ============================================================================= === def attribution(flags): order = ["ValidityFail","V_struct","FeasibleFail","EvidenceFailure","PrecisionFailure"] trigger = None for k in order: if flags.get(k, 0) == 1: trigger = k break return {"trigger": trigger, "flags": flags} === ============================================================================= === === AUDIT (BLOCK 19) === === ============================================================================= === def audit(method_hash, data_hash, run_artifacts, verdict): return sha256(canon({ "MethodHash": method_hash, "DataHash": data_hash, "Artifacts": run_artifacts, "Verdict": verdict })) === ============================================================================= === === SINGLE RUN (ANF SMALL-STEP COLLAPSED) === === ============================================================================= === def run_once(spec, D): artifacts = {} flags = {} verdict = None # BLOCK 0 mh = sha256(canon(spec)) require(mh == spec["embedded_hash"], "METHOD_HASH_MISMATCH") artifacts["B0"] = PASS # BLOCK 1 axioms(spec) artifacts["B1"] = PASS # BLOCK 2 + 9 data_valid(D) artifacts["B9"] = PASS # BLOCK 4 + 5 theta_space = spec["theta_space"] baseline = spec["baseline"] tau = spec["tau_struct"] r0 = residuals(D, theta_space[0], baseline) if structural(r0, tau): flags["V_struct"] = 1 verdict = COLLAPSE else: flags["V_struct"] = 0 artifacts["B5"] = FAIL if verdict == COLLAPSE else PASS if verdict == COLLAPSE: goto_attr = True else: goto_attr = False # BLOCK 6 if not goto_attr: if not feasible(theta_space, D, baseline, tau): flags["FeasibleFail"] = 1 verdict = COLLAPSE goto_attr = True else: flags["FeasibleFail"] = 0 artifacts["B6"] = FAIL if goto_attr else PASS # BLOCK 7 if not goto_attr: if identifiable(theta_space) == 0: flags["FeasibleFail"] = 1 verdict = COLLAPSE goto_attr = True artifacts["B7"] = FAIL if goto_attr else PASS # BLOCK 8β11 if not goto_attr: eps = spec["epsilon"] nu = spec["nu"] Z = evidence(theta_space, D, baseline, eps, nu) if Z < spec["Lambda"]: flags["EvidenceFailure"] = 1 verdict = COLLAPSE goto_attr = True else: flags["EvidenceFailure"] = 0 artifacts["B10"] = FAIL if goto_attr else PASS # BLOCK 13 if not goto_attr: if monte_carlo(D, theta_space, baseline, tau, eps, nu, spec["N_MC"], spec["f_c"]): flags["PrecisionFailure"] = 1 verdict = COLLAPSE goto_attr = True artifacts["B13"] = FAIL if goto_attr else PASS # BLOCK 14 if not goto_attr: if precision(D, theta_space, baseline, tau): flags["PrecisionFailure"] = 1 verdict = COLLAPSE artifacts["B14"] = FAIL if verdict == COLLAPSE else PASS if verdict is None: verdict = STAND # BLOCK 15 attr = attribution(flags) artifacts["B15"] = attr return verdict, artifacts, flags === ============================================================================= === === SCALED EXPERIMENT EXECUTION (100Γ SEALED RUNS) === === ============================================================================= === def run_scaled(spec, base_dataset, runs=100): ensemble = [] for k in range(runs): Dk = copy.deepcopy(base_dataset) # deterministic scaling: shift kth datum by +k*Ξ΄ idx = k % len(Dk["data"]) Dk["data"][idx]["y"] += spec["scale_delta"] * k verdict, artifacts, flags = run_once(spec, Dk) ensemble.append({ "run": k, "verdict": verdict, "flags": flags, "artifact_hash": sha256(canon(artifacts)) }) return ensemble === ============================================================================= === === ENTRYPOINT (REFERENCE USAGE) === === ============================================================================= === def main(spec, dataset): ensemble = run_scaled(spec, dataset, runs=100) collapsed = sum(1 for e in ensemble if e["verdict"] == COLLAPSE) return { "runs": 100, "collapsed": collapsed, "stand": 100 - collapsed, "ensemble_hash": sha256(canon(ensemble)), "ensemble": ensemble } === ============================================================================= === === END OF FILE === === ============================================================================= === </syntaxhighlight> Β© Robert R. Frost 2026-01-03
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)