56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
"""What is fun7, and is it a method wall or a budget wall?
|
|
|
|
fun7.1/7.3/7.5 are solved by NO configuration in any sweep — baselines included. Either the
|
|
family is genuinely hard for every method, or MAXFEV = 200 is simply too small for it, and
|
|
those are very different facts. This asks with a larger budget.
|
|
|
|
python -u diag_fun7.py
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import math
|
|
|
|
from scipy.optimize._tstutils import _CHANDRUPATLA_TESTS_DICTS
|
|
|
|
from simroot.baselines import best_of, chandrupatla, chandrupatla_scipy, toms748
|
|
from simroot.pure import pure_root
|
|
from sweep_full import ACC, XTOL
|
|
|
|
CHA = best_of(chandrupatla, chandrupatla_scipy)
|
|
|
|
|
|
def main():
|
|
print(f"{'problem':<10} {'bracket':>28} {'root':>14} {'decades':>8}")
|
|
probs = []
|
|
for d in _CHANDRUPATLA_TESTS_DICTS:
|
|
if not str(d["ID"]).startswith("fun7"):
|
|
continue
|
|
a, b = (float(v) for v in d["bracket"])
|
|
root = float(d["root"])
|
|
f = d["f"]
|
|
probs.append((d["ID"], f, a, b, root))
|
|
print(f"{d['ID']:<10} [{a:11.4g}, {b:11.4g}] {root:14.6g} "
|
|
f"{math.log2(abs(b - a) / XTOL):8.1f}")
|
|
for nm, val in (("f(a)", f(a)), ("f(b)", f(b)), ("f(root)", f(root)),
|
|
("f(root+1e-9)", f(root + 1e-9))):
|
|
print(f" {nm:<14} = {val:+.6e}")
|
|
|
|
for budget in (200, 2000, 20000):
|
|
print(f"\nbudget {budget}:")
|
|
for pid, f, a, b, root in probs:
|
|
x_o, n_o, ok_o = pure_root(f, a, b, XTOL, budget, similarity="ratio",
|
|
scale="derived3", guard="safe", prestep="slope",
|
|
direction="dissimilar")
|
|
x_c, n_c, ok_c = CHA(f, a, b, XTOL, budget)
|
|
x_t, n_t, ok_t = toms748(f, a, b, XTOL, budget)
|
|
good = lambda x, ok: bool(ok and math.isfinite(float(x)) # noqa: E731
|
|
and abs(float(x) - root) <= ACC)
|
|
print(f" {pid:<8} ours n={n_o:5d} {'OK' if good(x_o, ok_o) else 'fail':<4} "
|
|
f"(x={x_o:+.8g}) | CH n={n_c:5d} {'OK' if good(x_c, ok_c) else 'fail':<4} "
|
|
f"| TOMS n={n_t:5d} {'OK' if good(x_t, ok_t) else 'fail':<4}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|