Skip to content

Commit 82f84af

Browse files
committed
Search conservative hard-iron boundary
1 parent c66f5d3 commit 82f84af

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/env python3
2+
"""Search the conservative edge of refinement-stage hard-iron shrinkage.
3+
4+
The broad sweep showed that the lowest-information calm JONSWAP record is the
5+
first failure when every record is allowed to fit. This follow-up holds the
6+
information floor at 0.25 (just above the observed minimum 0.244) and searches
7+
small shrinkage gains where a regularized estimate might help without turning
8+
that weak record on.
9+
"""
10+
from __future__ import annotations
11+
12+
import ou_iii_mag_hard_iron_shrinkage as exp
13+
14+
15+
def install_patches():
16+
originals = (
17+
exp.FUSION.read_text(), exp.MAG_TUNER.read_text(),
18+
exp.SIM.read_text(), exp.COMMON_H.read_text(),
19+
)
20+
f0, m0, s0, h0 = originals
21+
22+
m = exp.replace_once(m0, exp.MAG_CFG_OLD, exp.MAG_CFG_NEW, "MagAutoTuner config")
23+
m = exp.replace_once(m, exp.MAG_SOLVE_OLD, exp.MAG_SOLVE_NEW, "MagAutoTuner shrink")
24+
exp.MAG_TUNER.write_text(m)
25+
26+
f = exp.replace_once(f0, exp.CFG_OLD, exp.CFG_NEW, "OU-III config")
27+
f = exp.replace_once(f, exp.BEGIN_OLD, exp.BEGIN_NEW, "initial hard-iron disable")
28+
f = exp.replace_once(f, exp.REFINE_CFG_OLD, exp.REFINE_CFG_NEW, "refinement config")
29+
f = exp.replace_once(f, exp.REFINE_USE_OLD, exp.REFINE_USE_NEW, "refinement hard-iron use")
30+
f = exp.replace_once(f, exp.PUBLIC_OLD, exp.PUBLIC_NEW, "public diagnostics")
31+
exp.FUSION.write_text(f)
32+
33+
sim = exp.replace_once(s0, exp.ENV_OLD, exp.ENV_NEW, "sim env")
34+
sim = exp.replace_once(sim, exp.REFINE_DIAG_OLD, exp.REFINE_DIAG_NEW, "refinement diagnostics")
35+
exp.SIM.write_text(sim)
36+
37+
h = h0
38+
if "#include <cstdlib>" not in h:
39+
h = h.replace("#include <cstdint>\n", "#include <cstdint>\n#include <cstdlib>\n", 1)
40+
h = exp.replace_once(h, exp.SIG_OLD, exp.SIG_NEW, "mag sigma")
41+
exp.COMMON_H.write_text(h)
42+
return originals
43+
44+
45+
def restore(originals):
46+
f0, m0, s0, h0 = originals
47+
exp.FUSION.write_text(f0)
48+
exp.MAG_TUNER.write_text(m0)
49+
exp.SIM.write_text(s0)
50+
exp.COMMON_H.write_text(h0)
51+
52+
53+
def main():
54+
originals = install_patches()
55+
try:
56+
exp.build()
57+
base, _ = exp.run()
58+
ranking = []
59+
60+
# Search the transition where seven records are identifiable while the
61+
# weakest calm-sea fit remains suppressed. Include nearby thresholds
62+
# because the second-weakest record may itself be harmful.
63+
candidates = []
64+
for info in (0.25, 0.50, 1.0):
65+
for shrink in (0.005, 0.010, 0.020, 0.030, 0.040, 0.050, 0.075, 0.100):
66+
candidates.append((info, shrink))
67+
68+
for info, shrink in candidates:
69+
cand, hi = exp.run(
70+
enable=True, min_info=info, shrink=shrink,
71+
mag_scale=1.02, rs_coeff=0.3475,
72+
)
73+
mx, n, geo, rows = exp.report(
74+
f"BOUNDARY min_info={info:.3f} shrink={shrink:.3f}",
75+
base, cand, hi,
76+
)
77+
ranking.append((mx, geo, -n, info, shrink, rows, hi))
78+
if mx < 1.0 and n == 56:
79+
print(
80+
f"STRICT_WIN min_info={info:.6f} shrink={shrink:.6f} "
81+
f"max={mx:.9f} geo={geo:.9f}", flush=True,
82+
)
83+
print("STRICT_DOMINANCE=PASS", flush=True)
84+
return
85+
86+
print("=== BOUNDARY RANKING ===", flush=True)
87+
for row in sorted(ranking)[:15]:
88+
print(
89+
f"min_info={row[3]:.3f} shrink={row[4]:.3f} "
90+
f"max={row[0]:.9f} geo={row[1]:.9f} improved={-row[2]}/56",
91+
flush=True,
92+
)
93+
best = sorted(ranking)[0]
94+
print(
95+
f"BOUNDARY_BEST min_info={best[3]:.6f} shrink={best[4]:.6f} "
96+
f"max={best[0]:.9f} geo={best[1]:.9f} improved={-best[2]}/56",
97+
flush=True,
98+
)
99+
print("STRICT_DOMINANCE=FAIL", flush=True)
100+
finally:
101+
restore(originals)
102+
103+
104+
if __name__ == "__main__":
105+
main()

0 commit comments

Comments
 (0)