Datasets:
Download code/vcg_calibrate.py from spatial-evidence-bench/SpatialEvidenceBench: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/datasets/spatial-evidence-bench/SpatialEvidenceBench/resolve/main/code/vcg_calibrate.py
- Command line
-
hf download hf://datasets/spatial-evidence-bench/SpatialEvidenceBench/code/vcg_calibrate.py
-
curl -L -o vcg_calibrate.py https://huggingface.co/datasets/spatial-evidence-bench/SpatialEvidenceBench/resolve/main/code/vcg_calibrate.py
2.04 kB
| import argparse | |
| import itertools | |
| import json | |
| from pathlib import Path | |
| from vcg_gate import decide_witness | |
| GRID = { | |
| "margin_x": [0.010, 0.020, 0.030, 0.045], | |
| "margin_y": [0.010, 0.020, 0.030, 0.045], | |
| "margin_depth": [0.010, 0.025, 0.040, 0.060], | |
| "contact_gap": [0.020, 0.035, 0.050], | |
| "overlap_min": [0.15, 0.25, 0.40], | |
| } | |
| def decide(row, margin_x, margin_y, margin_depth, contact_gap, overlap_min): | |
| params = { | |
| "margin_x": margin_x, | |
| "margin_y": margin_y, | |
| "margin_depth": margin_depth, | |
| "contact_gap": contact_gap, | |
| "overlap_min": overlap_min, | |
| } | |
| return decide_witness(row, params) | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--witness", required=True) | |
| parser.add_argument("--out", required=True) | |
| parser.add_argument("--min-coverage", type=float, default=0.55) | |
| args = parser.parse_args() | |
| rows = [json.loads(line) for line in Path(args.witness).open(encoding="utf-8")] | |
| results = [] | |
| for values in itertools.product(*GRID.values()): | |
| params = dict(zip(GRID.keys(), values)) | |
| decided = sum(1 for row in rows if decide(row, **params) != "UNKNOWN") | |
| correct = sum( | |
| 1 for row in rows | |
| if decide(row, **params) != "UNKNOWN" | |
| and (decide(row, **params) == "SUPPORT") == (row["truth"] == "yes") | |
| ) | |
| coverage = decided / len(rows) if rows else 0.0 | |
| accuracy = correct / decided if decided else 0.0 | |
| penalty = 1.0 if coverage >= args.min_coverage else coverage / args.min_coverage | |
| results.append({**params, "coverage": coverage, "accuracy": accuracy, | |
| "score": accuracy * penalty}) | |
| results.sort(key=lambda r: -r["score"]) | |
| Path(args.out).parent.mkdir(parents=True, exist_ok=True) | |
| Path(args.out).write_text(json.dumps({"best": results[0], "top": results[:15]}, ensure_ascii=False, indent=2), encoding="utf-8") | |
| print(json.dumps(results[0], ensure_ascii=False)) | |
| if __name__ == "__main__": | |
| main() | |