Files
sim-numerics/diag_fun9_flank.py
T

56 lines
2.4 KiB
Python

"""Why the translation limit did not fire on the exp(x) flank of fun9.5 ([2e-4, 81]).
Every state the gate sees (trace hook) under a prestep, in order, with what the analogy
reads there:
flag r = f/f_prev >= 1/4 (sign kept) - the entry also needs the last step to be the model's
xi, phi the configuration
ratio d_past / d_line (< 1: analogous to the nearest past configuration)
lx, lf the pair's x-scale and f-scale ratios (translation: lf < 1 <= lx)
m the order read with translation=True
Nothing in the method changes.
python -u diag_fun9_flank.py [problem] [prestep]
"""
from __future__ import annotations
import math
import sys
from simroot.pure import _analogy_order, _config3, pure_root
from sweep_full import MAXFEV, XTOL, load_problems
def main(pid_want="fun9.5", pre="defect+flatanalogmempt+exp"):
for s, pid, f, a, b, _root in load_problems():
if pid != pid_want:
continue
st = {"trace": []}
pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3",
guard="project", prestep=pre, stats=st)
print(f"== {pid} {pre} entries {st.get('stick_entries', 0)}")
past = []
for k, t in enumerate(st["trace"]):
cur = _config3(t["x"], t["fx"], t["xp"], t["fp"], t["xp2"], t["fp2"])
flag = t["fp"] != 0.0 and t["fx"] / t["fp"] >= 0.25
head = f" {k:3d} x {t['x']:9.4f} f {t['fx']:+9.2e} {'F' if flag else '.'}"
if cur is None:
print(head + " (no configuration)")
continue
line = abs(cur[1] - cur[0]) / math.sqrt(2.0)
if past:
q = min(past, key=lambda p: math.hypot(cur[0] - p[0], cur[1] - p[1]))
ratio = math.hypot(cur[0] - q[0], cur[1] - q[1]) / line if line > 0 else math.inf
lx = cur[2] / q[2] if q[2] > 0 else math.nan
lf = cur[3] / q[3] if q[3] > 0 else math.nan
m = _analogy_order(cur, past, translation=True)
ms = "none" if m is None else ("inf" if math.isinf(m) else f"{m:.2f}")
print(head + f" xi {cur[0]:+8.3f} phi {cur[1]:+8.3f} ratio {ratio:7.3f}"
f" lx {lx:7.3f} lf {lf:9.3e} m {ms}")
else:
print(head + f" xi {cur[0]:+8.3f} phi {cur[1]:+8.3f} (no memory)")
past.append(cur)
if __name__ == "__main__":
main(*sys.argv[1:3])