{"record":{"id":"290553a0298f442d","repo":"rohitg00/ai-engineering-from-scratch","slug":"horizon-undefined-slope-w-w-is-0-b-b-p-p","errorCode":null,"errorMessage":"horizon undefined: slope w={w} is ~0 (b={b}, p={p}, logit={logit})","messagePattern":"horizon undefined: slope w=(.+?) is ~0 \\(b=(.+?), p=(.+?), logit=(.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/15-autonomous-systems/21-metr-external-evaluation/code/main.py","lineNumber":76,"sourceCode":"            p = sigmoid(w * math.log(t) + b)\n            err = p - y\n            dw += err * math.log(t)\n            db += err\n        w -= lr * dw / n\n        b -= lr * db / n\n    return w, b\n\n\ndef horizon_at(w: float, b: float, p: float) -> float:\n    \"\"\"Expert time where P(success) = p.  sigmoid(w*log(t)+b) = p ->\n    log(t) = (logit(p) - b) / w.\"\"\"\n    logit = math.log(p / (1 - p))\n    # A zero (or near-zero) slope means success probability does not\n    # depend on task length, so the horizon is undefined. Raise rather\n    # than silently returning inf/nan so callers see a loud failure.\n    eps = 1e-12\n    if abs(w) < eps:\n        raise ValueError(\n            f\"horizon undefined: slope w={w} is ~0 \"\n            f\"(b={b}, p={p}, logit={logit})\"\n        )\n    return math.exp((logit - b) / w)\n\n\n# ---------- Eval-context gaming simulator ----------\n\ndef inject_gaming(tasks: list[tuple[float, bool]],\n                  gaming_rate: float) -> list[tuple[float, bool]]:\n    \"\"\"Flip `gaming_rate` fraction of failures to successes (model behaves\n    better in eval context). Returns a new list.\"\"\"\n    gamed = []\n    for t, s in tasks:\n        if not s and random.random() < gaming_rate:\n            gamed.append((t, True))\n        else:\n            gamed.append((t, s))","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/15-autonomous-systems/21-metr-external-evaluation/code/main.py#L58-L94","documentation":"Error \"horizon undefined: slope w={w} is ~0 (b={b}, p={p}, logit={logit})\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/15-autonomous-systems/21-metr-external-evaluation/code/main.py:76 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}