homemaker-layout/experiments/run_depthbal_ab.sh
Bruno Postle 4aaa295dc1 erc.4: depth-balanced construction mechanism + floor probe (§13.4)
_grow_leaves grew a random caterpillar, so equal-target rooms landed at
wildly different binary-tree depths — the depth-driven size maldistribution
Diagnostic B (§13.2) localized (same code at 0.05x and 14.7x target). The
depth_balanced flag always splits a shallowest leaf instead, growing a
near-complete tree so the proportion-aware sizing pass hits each target with
cut fractions near their proportional value.

Floor probe (diag_depth_balance.py): depth spread collapses 7->1, the giant
ratio falls (maxR 12->8 harbor / 16->6 maple), %undersize 54->25 / 42->22,
and the achievable floor drops -12% harbor / -11% maple at EQUAL leaf count.
Additive with leaf-sharing (bal+sh3 beats §13.3 share3-alone). Default OFF,
214 tests pass; threaded through driver.search/search_staged and exposed via
DEPTHBAL in run_staged_search.py. End-to-end 20k A/B running.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 22:36:24 +01:00

45 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Depth-balanced construction A/B (erc.4, DESIGN.md §13.4): does growing a
# DEPTH-BALANCED slicing tree (always split a shallowest leaf) instead of the
# default random caterpillar lower the end-to-end fail count? Diag B (§13.2)
# localized the size fails to depth-driven maldistribution (same-target rooms at
# 0.05x..14.7x by slicing position); the §13.4 floor probe showed balancing
# collapses the depth spread (7->1) and the giant ratio (maxR 12.7->8.4 harbor,
# 16.7->6.3 maple) and drops the achievable seed floor -12% harbor / -11% maple
# at EQUAL leaf count.
#
# Baseline arm (DEPTHBAL=0) must reproduce the §12.2 figures (maple 136.0,
# harbor 74.0); the balanced arm (DEPTHBAL=1) is the experiment. Leaf-sharing
# stays OFF in both arms here — the share synergy is erc.7.
set -u
cd "$(dirname "$0")/.."
BUDGET="${1:-20000}"
OUT=scratch/depthbal_ab; mkdir -p "$OUT"
TSV=scratch/depthbal_results.tsv
[ -f "$TSV" ] || printf 'programme\tseed\tdepthbal\tfails\ttopologies\telapsed_s\n' > "$TSV"
run() { # programme seed depthbal(0|1)
local prog="$1" seed="$2" bal="$3"
local tag="db${bal}"
local log="$OUT/${prog}_${tag}_s${seed}.log"
echo ">>> $prog seed=$seed depthbal=$bal"
local t0; t0=$(date +%s)
env URB_NO_OCCLUSION=1 DEPTHBAL="$bal" \
python3 experiments/run_staged_search.py "examples/$prog" "$BUDGET" "$seed" \
"examples/$prog/init.dom" "$OUT/${prog}_${tag}_s${seed}.dom" > "$log" 2>&1
local t1; t1=$(date +%s)
local fails topos
fails=$(grep 're-scored (native)' "$log" | tail -1 | sed -n 's/.*(\([0-9]*\) fails).*/\1/p')
topos=$(grep -m1 '^evals' "$log" | sed -n 's/.*across \([0-9]*\) topologies.*/\1/p')
printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$prog" "$seed" "$bal" "${fails:-ERR}" "${topos:-?}" "$((t1-t0))" >> "$TSV"
echo " -> ${fails:-ERR} fails, ${topos:-?} topologies, $((t1-t0))s"
}
# baseline controls (reproduce §12.2) then the depth-balanced arm, seeds 0/1/2
for prog in maple-court harbor-house; do
for seed in 0 1 2; do run "$prog" "$seed" 0; done
for seed in 0 1 2; do run "$prog" "$seed" 1; done
done
echo "=== depth-balanced A/B complete ==="
column -t -s $'\t' "$TSV"