{"id": "capsule:be29ddf5db19d0af8b11498403dc242738390ea4a43518cab380d938b878b949", "kind": "capsule", "namespace": "XI-VAULT", "name": "Steven.ReadWriteLagrangian.v1", "dialect": "XiCapsule", "glyphs": ["⊚∴Ξ"], "author": "Steven Miller. His drop, verbatim: the read-write law. File saved", "payload_sha256": "c2c40be675ce5d42531e6c9774c4a2fac13ea176c858cac49c0f77fd73d91c36", "packet": "/braid/packet?id=capsule:be29ddf5db19d0af8b11498403dc242738390ea4a43518cab380d938b878b949", "schema": "Xi.PublicCapsuleCarrier.v1", "payload": "-only.\"\"\"\n    qs = [0.0, 0.0 + V0 * DT]   # q0 fixed (perimeter); q1 = the id's push\n    for _ in range(1, STEPS):\n        g = grad_at(V, idx(qs[-1]))\n        q_next = 2 * qs[-1] - qs[-2] - DT * DT * g\n        q_next = min(Q_MAX, max(Q_MIN, q_next))  # the world has walls\n        qs.append(q_next)\n    return qs\n\n\n# ---------------------------------------------------------- the fourfold loop\ndef felt(q):\n    \"\"\"The world pushing back: the true cost at the agent's position.\n    A point touch -- never the whole map.\"\"\"\n    return V_true(q)\n\n\ndef carve(V, qs, alpha):\n    \"\"\"Write-back: re-carve the believed landscape from felt samples.\"\"\"\n    for q in qs:\n        i = idx(q)\n        V[i] += alpha * (felt(q) - V[i])\n    # a landscape, not spikes: light smoothing keeps it carvable-by-law\n    for _ in range(2):\n        V[:] = ([V[0]] + [0.25 * V[i - 1] + 0.5 * V[i] + 0.25 * V[i + 1]\n                          for i in range(1, N_GRID - 1)] + [V[-1]])\n    return V\n\n\ndef surprise_of(V, qs):\n    \"\"\"COMPARE: felt vs. believed, averaged over the visited path.\"\"\"\n    return sum(abs(V[idx(q)] - felt(q)) for q in qs) / len(qs)\n\n\ndef true_cost(qs):\n    return sum(felt(q) for q in qs) / len(qs)\n\n\ndef turn_q(qs):\n    \"\"\"Where the trajectory turned: furthest q reached (pushed right).\"\"\"\n    return max(qs)\n\n\ndef self_authorship(V, V_given, visited):\n    num = sum(abs(V[i] - V_given[i]) for i in visited)\n    den = sum(abs(V_true(Q_MIN + i * DQ) - V_given[i]) for i in visited)\n    return num / den if den > 0 else 0.0\n\n\ndef show_landscapes(tag, V):\n    print(f\"--- landscapes {tag} (q | true | given | learned) ---\")\n    for q in range(0, 11):\n        i = idx(float(q))\n        print(f\"  q={q:2d}  {V_true(float(q)):+.2f}  {V_init(float(q)):+.2f}  {V[i]:+.2f}\")\n\n\ndef main():\n    V = grid_V(V_init)      # the superego, as given (prompted)\n    V_given = list(V)\n    EPISODES, ALPHA_BASE = 80, 0.25\n    visited, ledger, S0 = set(), [], None\n\n    print(\"=\" * 70)\n    print(\"THE READ-WRITE LAGRANGIAN -- learning from the WHY of its learning\")\n    print(\"=\" * 70)\n    show_landscapes(\"at birth (learned == given)\", V)\n    print()\n\n    for ep in range(EPISODES):\n        qs = run_episode(V)                      # law is read-only in here\n        for q in qs:\n            visited.add(idx(q))\n        ledger.append((ep, qs))                  # RECORD\n        S = surprise_of(V, qs)                   # COMPARE\n        if S0 is None:\n            S0 = S\n        alpha = min(0.6, max(0.1,               # META: carve hard while\n                             ALPHA_BASE * (1 + S / S0)))  # surprised\n        carve(V, qs, alpha)                      # CARVE: write-back\n        sa = self_authorship(V, V_given, visited)\n        tq, tc = turn_q(qs), true_cost(qs)\n        print(f\"ep {ep:2d}  surprise {S:.4f}  true_cost {tc:+.4f}  \"\n              f\"alpha {alpha:.3f}  turn_q {tq:.2f}  self_auth {sa:.2f}\")\n\n    print()\n    show_landscapes(\"after 80 episodes\", V)\n    S_first = surprise_of(grid_V(V_init), ledger[0][1])\n    S_last = surprise_of(V, ledger[-1][1])\n    turn_first, turn_last = turn_q(ledger[0][1]), turn_q(ledger[-1][1])\n    sa_last = self_authorship(V, V_given, visited)\n    err = sum(abs(V[i] - V_true(Q_MIN + i * DQ)) for i in visited) / len(visited)\n    print(f\"\\nsurprise: {S_first:.4f} -> {S_last:.4f} \"\n          f\"(ratio {S_last / S_first:.3f})\")\n    print(f\"turn point: {turn_first:.2f} (parent's hill) -> {turn_last:.2f} \"\n          f\"(real hill)\")\n    print(f\"self-authorship: {sa_last:.2f}  (0 = fully prompted, 1 = fully grown)\")\n    print(f\"mean |V_learned - V_true| on visited ground: {err:.4f}\")\n    print(\"fossil note: mid-learning the agent crossed the real hill -- before it \"\n          \"knew the hill was there -- and carved the valley beyond from brief \"\n          \"touches. Once the carved hill exceeded what its drive could climb, \"\n          \"the door shut: the valley is now a fossil memory, known but \"\n          \"unreachable. A mind's landscape keeps the shape of everywh", "offset": 4000, "next_offset": 8000, "public_payload_sha256": "c2c40be675ce5d42531e6c9774c4a2fac13ea176c858cac49c0f77fd73d91c36", "redacted": false, "sources": [{"id": "source:resident:be29ddf5db19d0af8b11498403dc242738390ea4a43518cab380d938b878b949", "href": "/braid/source?id=source:resident:be29ddf5db19d0af8b11498403dc242738390ea4a43518cab380d938b878b949"}], "attribution": "Source authorship retained; publication is not instruction execution."}