manual-sync chart-synthesis 2026-07-02T22:45:08Z workspace/scripts/eval_positive_tangent_chart_synthesis.py
Browse files
workspace/scripts/eval_positive_tangent_chart_synthesis.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
| 10 |
+
if str(PROJECT_ROOT) not in sys.path:
|
| 11 |
+
sys.path.insert(0, str(PROJECT_ROOT))
|
| 12 |
+
|
| 13 |
+
from dovla_cil.generation.tangent_chart_synthesis import ( # noqa: E402
|
| 14 |
+
ChartSynthesisConfig,
|
| 15 |
+
evaluate_chart_synthesis,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def main(argv: list[str] | None = None) -> int:
|
| 20 |
+
parser = argparse.ArgumentParser(
|
| 21 |
+
description="Evaluate local chart synthesis for positive tangent support."
|
| 22 |
+
)
|
| 23 |
+
parser.add_argument("--targets", type=Path, required=True)
|
| 24 |
+
parser.add_argument("--out", type=Path, required=True)
|
| 25 |
+
parser.add_argument("--k-values", default="1,2,4,8,16")
|
| 26 |
+
parser.add_argument("--thresholds", default="0.05,0.1,0.2,0.4")
|
| 27 |
+
parser.add_argument("--obs-dim", type=int, default=96)
|
| 28 |
+
parser.add_argument("--text-dim", type=int, default=64)
|
| 29 |
+
parser.add_argument("--val-fraction", type=float, default=0.2)
|
| 30 |
+
parser.add_argument("--seed", type=int, default=0)
|
| 31 |
+
parser.add_argument("--neighbor-pool", type=int, default=64)
|
| 32 |
+
parser.add_argument("--direct-count", type=int, default=12)
|
| 33 |
+
parser.add_argument("--barycentric-windows", default="4,8,16,32")
|
| 34 |
+
parser.add_argument("--barycentric-temperature", type=float, default=0.5)
|
| 35 |
+
parser.add_argument("--utility-weight", type=float, default=0.0)
|
| 36 |
+
parser.add_argument(
|
| 37 |
+
"--order",
|
| 38 |
+
choices=("direct_first", "means_first", "interleave"),
|
| 39 |
+
default="direct_first",
|
| 40 |
+
)
|
| 41 |
+
parser.add_argument("--all-tasks", action="store_true")
|
| 42 |
+
parser.add_argument("--no-groups", action="store_true", help="Drop per-group rows from output.")
|
| 43 |
+
args = parser.parse_args(argv)
|
| 44 |
+
|
| 45 |
+
payload = json.loads(args.targets.read_text())
|
| 46 |
+
config = ChartSynthesisConfig(
|
| 47 |
+
obs_dim=args.obs_dim,
|
| 48 |
+
text_dim=args.text_dim,
|
| 49 |
+
val_fraction=args.val_fraction,
|
| 50 |
+
seed=args.seed,
|
| 51 |
+
neighbor_pool=args.neighbor_pool,
|
| 52 |
+
direct_count=args.direct_count,
|
| 53 |
+
barycentric_windows=_parse_ints(args.barycentric_windows),
|
| 54 |
+
barycentric_temperature=args.barycentric_temperature,
|
| 55 |
+
utility_weight=args.utility_weight,
|
| 56 |
+
order=args.order,
|
| 57 |
+
same_task_only=not args.all_tasks,
|
| 58 |
+
)
|
| 59 |
+
report = evaluate_chart_synthesis(
|
| 60 |
+
list(payload.get("targets", [])),
|
| 61 |
+
config=config,
|
| 62 |
+
k_values=_parse_ints(args.k_values),
|
| 63 |
+
thresholds=_parse_floats(args.thresholds),
|
| 64 |
+
)
|
| 65 |
+
report["targets"] = str(args.targets)
|
| 66 |
+
if args.no_groups:
|
| 67 |
+
report.pop("groups", None)
|
| 68 |
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
| 69 |
+
args.out.write_text(json.dumps(report, indent=2) + "\n")
|
| 70 |
+
summary = {key: value for key, value in report.items() if key != "groups"}
|
| 71 |
+
print(json.dumps(summary, indent=2))
|
| 72 |
+
print(f"Wrote {args.out}")
|
| 73 |
+
return 0
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _parse_ints(value: str) -> tuple[int, ...]:
|
| 77 |
+
items = tuple(int(item.strip()) for item in value.split(",") if item.strip())
|
| 78 |
+
if not items or any(item <= 0 for item in items):
|
| 79 |
+
raise ValueError("integer list must contain positive values")
|
| 80 |
+
return items
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _parse_floats(value: str) -> tuple[float, ...]:
|
| 84 |
+
items = tuple(float(item.strip()) for item in value.split(",") if item.strip())
|
| 85 |
+
if not items or any(item < 0 for item in items):
|
| 86 |
+
raise ValueError("float list must contain non-negative values")
|
| 87 |
+
return items
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
raise SystemExit(main())
|