File size: 5,037 Bytes
a45b7c9 8e80498 a45b7c9 02cbb89 a45b7c9 02cbb89 a45b7c9 02cbb89 a45b7c9 8e80498 a45b7c9 02cbb89 a45b7c9 02cbb89 a45b7c9 02cbb89 8e80498 02cbb89 a45b7c9 02cbb89 a45b7c9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | """Evaluate one hypothesis with the existing deterministic symbolic scorer."""
from __future__ import annotations
import argparse
import json
from pathlib import Path
import sys
WORKSPACE_ROOT = Path(__file__).resolve().parent.parent
if str(WORKSPACE_ROOT) not in sys.path:
sys.path.insert(0, str(WORKSPACE_ROOT))
from experiments import config # noqa: E402
from symbolic import launch as symbolic_launch # noqa: E402
def configure_symbolic_evaluation(
hypothesis,
depth="metric",
tracking="tracking",
input_selection="uniform",
frame_count=64,
spatial_code_format="explicit",
):
"""Point symbolic reads and writes at one isolated experiment selection."""
codes = config.spatial_code_directory(
hypothesis, depth, tracking, input_selection, frame_count, spatial_code_format
)
results = config.result_directory(
hypothesis,
"symbolic",
depth,
tracking,
input_selection,
frame_count,
spatial_code_format,
)
symbolic_run = symbolic_launch.symbolic_run
symbolic_run.SPATIAL_CODES_DEPTH = depth
symbolic_run.SPATIAL_CODES_INPUT = input_selection
symbolic_run.SPATIAL_CODES_TRACKING = tracking
symbolic_run.SPATIAL_CODES_FRAMES = frame_count
symbolic_run.SPATIAL_CODES_FORMAT = spatial_code_format
symbolic_run.SPATIAL_CODES_DIR = str(codes)
symbolic_run.RESULTS_DIR = str(results)
symbolic_run.results_dir_for_selection = lambda results_dir=None: str(
results_dir or results
)
return codes, results
def evaluate(
hypothesis,
depth="metric",
tracking="tracking",
input_selection="uniform",
frame_count=64,
scene_ids=None,
quiet=False,
errors=False,
spatial_code_format="explicit",
):
"""Score every available experiment code, or an explicit scene subset."""
codes, results = configure_symbolic_evaluation(
hypothesis,
depth,
tracking,
input_selection,
frame_count,
spatial_code_format,
)
available = symbolic_launch.scenes_with_spatial_codes()
selected = available if scene_ids is None else list(scene_ids)
missing = [scene for scene in selected if scene not in available]
if missing:
raise FileNotFoundError(
f"scene(s) have no hypothesis spatial code under {codes}: {missing}"
)
if not selected:
raise FileNotFoundError(f"no hypothesis spatial codes found under {codes}")
per_scene, combined = symbolic_launch.run_all(selected, quiet=quiet)
summary = {
"hypothesis": hypothesis,
"depth": depth,
"input": input_selection,
"tracking": tracking,
"frames": frame_count,
"spatial_code_format": spatial_code_format,
"scenes_run": list(per_scene),
"combined_aggregate": combined,
}
if errors:
summary["error_analysis"] = {
question_type: symbolic_launch.error_analysis(per_scene, question_type)
for question_type in symbolic_launch._ANALYZABLE_TYPES
}
symbolic_launch.print_error_analysis(per_scene)
symbolic_launch.print_mca_breakdown(per_scene)
results.mkdir(parents=True, exist_ok=True)
summary_path = results / "_summary.json"
with summary_path.open("w", encoding="utf-8") as stream:
json.dump(summary, stream, indent=1)
return summary, summary_path
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--hypothesis", required=True)
parser.add_argument("--depth", default="metric", choices=("relative", "metric"))
parser.add_argument(
"--input",
default="uniform",
choices=("uniform", "selective"),
dest="input_selection",
)
parser.add_argument(
"--tracking", default="tracking", choices=("tracking", "no tracking")
)
parser.add_argument("--frames", type=int, default=64)
parser.add_argument(
"--format",
default="explicit",
choices=config.SPATIAL_CODE_FORMATS,
dest="spatial_code_format",
)
parser.add_argument(
"--scenes", default="", help="optional comma-separated scene IDs"
)
parser.add_argument("--quiet", action="store_true")
parser.add_argument("--errors", action="store_true")
args = parser.parse_args()
if args.frames < 1:
parser.error("--frames must be positive")
scenes = (
[scene.strip() for scene in args.scenes.split(",") if scene.strip()]
if args.scenes
else None
)
summary, path = evaluate(
args.hypothesis,
args.depth,
args.tracking,
args.input_selection,
args.frames,
scenes,
args.quiet,
args.errors,
args.spatial_code_format,
)
print("\nCOMBINED AGGREGATE")
for key, value in summary["combined_aggregate"].items():
print(f" {key}: {value}")
print(f"\nwrote experiment summary to {path}")
if __name__ == "__main__":
main()
|