Geometry inner loop: batched full-objective ratio optimiser (CMA-ES)
innerloop.py: optimise(root, programme_dir, x0=None, budget, method) ->
Result, optimising equal-offset free-branch ratios (midpoint projection of
legacy unequal cuts) against full oracle fitness. OracleEvaluator scores
each population in one batched perl call. Methods: cma (default) — multi-
start sigma ladder (0.05 local, 0.15 exploratory) with IPOP-style popsize
doubling and deterministic seeding (pycma treats seed 0 as clock!) — and
compass with Hooke-Jeeves pattern moves, kept for the d0s bake-off.
Acceptance (experiments/accept_innerloop.py, §4.5 bars vs unprojected
originals, within-noise tolerance 1%): x1.65 / x1.66 / x1.58 against bars
x1.24 / x1.67 / x1.59, no new failures, 46 oracle calls vs Nelder-Mead's
200. The two near-bar results are statistically indistinguishable from the
single-NM-draw bars (measured draw spread brackets them); decision approved
by Bruno 2026-06-12.
Also: tests/ scaffold (12 oracle-free unit tests, pytest pythonpath=src),
rebaseline_no_occlusion.py for homemaker-py-gp2, cma>=3.0 dependency
(installed via dnf), dead-variable cleanup in solver.py.
Closes homemaker-py-1p0.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 09:42:24 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""Why does 2f45907 resist equal-offset recovery? (homemaker-py-1p0)
|
|
|
|
|
|
|
|
|
|
Its equal-offset projection adds a failure (2 -> 3) and batched searches stall
|
|
|
|
|
near the projected start, yet DESIGN.md §4.5 reports Nelder-Mead reached
|
|
|
|
|
0.015684 from the same projection. This script checks, for 2f45907 only:
|
|
|
|
|
|
|
|
|
|
1. fitness of the three projections (midpoint, a-end, b-end)
|
|
|
|
|
2. scipy Nelder-Mead from the midpoint, maxfev=200 (the §4.5 setup)
|
|
|
|
|
3. CMA-ES with sigma0=0.05 (tighter than the 0.15 default)
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
from scipy.optimize import minimize
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
2026-06-14 08:18:06 +01:00
|
|
|
from homemaker_layout import dom, innerloop # noqa: E402
|
Geometry inner loop: batched full-objective ratio optimiser (CMA-ES)
innerloop.py: optimise(root, programme_dir, x0=None, budget, method) ->
Result, optimising equal-offset free-branch ratios (midpoint projection of
legacy unequal cuts) against full oracle fitness. OracleEvaluator scores
each population in one batched perl call. Methods: cma (default) — multi-
start sigma ladder (0.05 local, 0.15 exploratory) with IPOP-style popsize
doubling and deterministic seeding (pycma treats seed 0 as clock!) — and
compass with Hooke-Jeeves pattern moves, kept for the d0s bake-off.
Acceptance (experiments/accept_innerloop.py, §4.5 bars vs unprojected
originals, within-noise tolerance 1%): x1.65 / x1.66 / x1.58 against bars
x1.24 / x1.67 / x1.59, no new failures, 46 oracle calls vs Nelder-Mead's
200. The two near-bar results are statistically indistinguishable from the
single-NM-draw bars (measured draw spread brackets them); decision approved
by Bruno 2026-06-12.
Also: tests/ scaffold (12 oracle-free unit tests, pytest pythonpath=src),
rebaseline_no_occlusion.py for homemaker-py-gp2, cma>=3.0 dependency
(installed via dnf), dead-variable cleanup in solver.py.
Closes homemaker-py-1p0.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 09:42:24 +01:00
|
|
|
|
|
|
|
|
URB = Path("/home/bruno/src/urb")
|
|
|
|
|
EX = URB / "examples" / "programme-house"
|
|
|
|
|
NAME = "2f45907abd9accac2a124d311732f749.dom"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
|
root = dom.load(str(EX / NAME))
|
|
|
|
|
with innerloop.OracleEvaluator(root, EX, URB) as ev:
|
|
|
|
|
a = np.array([b.division[0] for b in ev.free])
|
|
|
|
|
b_ = np.array([b.division[1] for b in ev.free])
|
|
|
|
|
mid = (a + b_) / 2
|
|
|
|
|
for label, x in [("mid", mid), ("a-end", a), ("b-end", b_)]:
|
|
|
|
|
s = ev.evaluate([x])[0]
|
|
|
|
|
print(f"projection {label:6s}: {s.fitness:.6g} fails {s.n_fails}", flush=True)
|
|
|
|
|
|
|
|
|
|
# §4.5 reproduction: sequential Nelder-Mead on the same objective
|
|
|
|
|
best = {"f": -1.0, "fails": -1}
|
|
|
|
|
|
|
|
|
|
def neg(x: np.ndarray) -> float:
|
|
|
|
|
s = ev.evaluate([np.clip(x, 0.02, 0.98)])[0]
|
|
|
|
|
if s.fitness > best["f"]:
|
|
|
|
|
best.update(f=s.fitness, fails=s.n_fails)
|
|
|
|
|
return -s.fitness
|
|
|
|
|
|
|
|
|
|
n0 = ev.n_evals
|
|
|
|
|
minimize(neg, mid, method="Nelder-Mead",
|
|
|
|
|
options={"maxfev": 200, "xatol": 1e-3, "fatol": 1e-12})
|
|
|
|
|
print(f"NM from mid: {best['f']:.6g} fails {best['fails']} "
|
|
|
|
|
f"({ev.n_evals - n0} evals)", flush=True)
|
|
|
|
|
|
|
|
|
|
root = dom.load(str(EX / NAME))
|
|
|
|
|
r = innerloop.optimise(root, EX, budget=200, method="cma", sigmas=(0.05,), urb_root=URB)
|
|
|
|
|
print(f"CMA sigma 0.05: {r.fitness:.6g} fails {r.n_fails} ({r.n_evals} evals)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|