homemaker-layout/experiments/diag_2f45907.py

60 lines
2.1 KiB
Python
Raw Permalink Normal View History

#!/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"))
from homemaker_layout import dom, innerloop # noqa: E402
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))
Remove the Perl oracle Owner's decision: "we need to abandon the perl oracle, this was only useful when initially porting, but I suspect many of the remaining problems have been carried in from the perl (such as the weird scoring of outdoor and circulation space, which definitely needs fixing)". 39 supports that second clause. Every defect the section found is inherited, not introduced: the two-sided crinkliness gaussian that double-charges surplus daylight (39.14), quality as a product over a variable number of factors (39.18), value_supported priced as value_inside so a terrace was worth more per m2 than a room (39.19), and circulation returning 0.07 per unit cost (hxi). So parity with the oracle was never a safety net -- it was a commitment to reproduce those defects. Each of 39.14, 39.18 and 39.19 would have been a parity failure had parity ever been checked, and keeping the tests would have meant reverting the fixes or explaining the failures away. Removed: oracle.py, test_oracle.py, the two parity tests and their fixture machinery in test_dom_corpus.py, innerloop.OracleEvaluator with its use_native and urb_root plumbing, the same plumbing through driver, and fourteen experiments/ scripts that could only run against Perl. Several of those are cited in earlier DESIGN sections; the citations now point into git history, which is the honest state -- they had been unrunnable since the oracle root (/home/bruno/src/urb) stopped being present. run_search is superseded by run_search_scaled, which does the same job natively. Kept: dump_areas.pl/.py, which validate GEOMETRY against Urb (4.1) rather than fitness, and the prose in fitness_cmd.py and dom.py explaining why the .score/.fails formats are shaped as they are. Provenance is worth keeping; a dead code path is not. CLAUDE.md updated: fitness.py is the only evaluator, and "Urb did it this way" is no longer an argument that a constant is right. 39.16 is the standing counterweight in the other direction -- the crinkliness target WAS right and twice looked wrong only because the code reading it was misunderstood. Inheritance is neither evidence for nor against. 410 passed. The 69 removed cases account exactly: 64 parity (all skipped, since no oracle .score was ever committed), 4 in test_oracle.py, and the guard test 39.20 added as a stopgap. Closes homemaker-py-118. Files homemaker-py-bk9 for the re-baseline that 39.19 made necessary. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MJ84Feep79Hhm3E4zZJmnB
2026-09-06 07:56:24 +00:00
r = innerloop.optimise(root, EX, budget=200, method="cma", sigmas=(0.05,))
print(f"CMA sigma 0.05: {r.fitness:.6g} fails {r.n_fails} ({r.n_evals} evals)")
if __name__ == "__main__":
main()