70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
"""Consequence check for diag_analogy_sequence.py: the flag rises in the phases of the
|
|
period-4 cycle whose configuration does NOT recur (the undershoot whose relative step
|
|
shrinks every cycle, the crossing), while the recurring phases are the ones with the flag
|
|
down. The entry demands both AT THE SAME STATE, so it waits until a flag state happens
|
|
to recur.
|
|
|
|
Candidate (not in the method): the analogy is a property of the RUN, the flag of the
|
|
MOMENT - once any state has been analogous to its past with m >= 2, enter at the next
|
|
flag. Per problem, on traces of the proposed rule with NO regime (so both rules see the
|
|
same states): the state of entry under 'same state' and under 'analogy remembered', and
|
|
how many problems would enter at all, per group. Nothing in the method changes.
|
|
|
|
python -u diag_analogy_decoupled.py
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from collections import defaultdict
|
|
|
|
from simroot.pure import _analogous_and_steep, _config3, pure_root
|
|
from sweep_full import MAXFEV, XTOL, load_problems
|
|
|
|
FLAT = ("fun3", "fun4", "fun5", "fun6")
|
|
|
|
|
|
def entries(trace):
|
|
past, seen = [], False
|
|
same = remembered = None
|
|
for k, s in enumerate(trace):
|
|
cur = _config3(s["x"], s["fx"], s["xp"], s["fp"], s["xp2"], s["fp2"])
|
|
flag = s["fp"] != 0.0 and s["fx"] / s["fp"] >= 0.25
|
|
ana = _analogous_and_steep(cur, past)
|
|
if flag and ana and same is None:
|
|
same = k
|
|
if flag and (seen or ana) and remembered is None:
|
|
remembered = k
|
|
seen = seen or ana
|
|
if cur is not None:
|
|
past.append(cur)
|
|
return same, remembered
|
|
|
|
|
|
def main():
|
|
per = defaultdict(lambda: [0, 0, 0, 0, 0]) # problems, same, remembered, sum same, sum rem
|
|
for s, pid, f, a, b, _root in load_problems():
|
|
st = {"trace": []}
|
|
pure_root(f, a, b, XTOL, MAXFEV, similarity="ratio", scale="derived3",
|
|
guard="project", stats=st)
|
|
fam = pid.split(".")[0]
|
|
g = "APS" if s == "APS" else ("CHA-flat" if fam in FLAT else f"CHA-{fam}")
|
|
same, rem = entries(st["trace"])
|
|
p = per[g]
|
|
p[0] += 1
|
|
p[1] += same is not None
|
|
p[2] += rem is not None
|
|
if g == "CHA-flat" and same is not None and rem is not None:
|
|
p[3] += same
|
|
p[4] += rem
|
|
print(f"{'group':<10} {'problems':>8} {'enter: same state':>18} {'analogy remembered':>19}")
|
|
for g in sorted(per):
|
|
n, a_, b_, s1, s2 = per[g]
|
|
print(f"{g:<10} {n:8d} {a_:18d} {b_:19d}")
|
|
fl = per["CHA-flat"]
|
|
print(f"\nflat: mean entry state {fl[3] / fl[1]:.1f} (same state) -> "
|
|
f"{fl[4] / fl[1]:.1f} (analogy remembered)")
|
|
print("diag done")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|