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