ArnavM10's picture
Add verified Table 1 constants and deterministic scorer
de17560 verified
Raw History Blame Contribute Delete
6.19 kB
# Reference table and deterministic scorer for the OpenEnv environment
# "classification_fields_env".
#
# Task: reproduce Table 1 of arXiv:2605.07119 "Classification Fields:
# Arbitrarily Fine Recursive Hierarchical Clustering From Few Examples"
# (Li, Hong, Kratsios, Saez de Ocariz Borde, McNicholas).
#
# The reference numbers below are the VERIFIED reproduction values of Table 1
# (nonlinear IFS benchmarks), taken from
# https://huggingface.co/spaces/ArnavM10/repro-2605.07119-classification-fields
# (results/summary.json), which ran the official repo
# https://github.com/YicenJoJo/classification-fields at commit cb52f15 via
# `python run_experiment.py nonlinear` and matched the paper's printed values
# to the last digit.
#
# Units: Table 1 reports ordered MSE x 1e-3. The raw floats below are stored in
# those printed units (i.e. Sierpinski CFP 0.90 +- 0.19, affine 16.46 +- 5.46).
from __future__ import annotations
import math
from typing import Any, Dict, Tuple
PAPER_ID = "arXiv:2605.07119"
PAPER_URL = "https://arxiv.org/abs/2605.07119"
OFFICIAL_REPO = "https://github.com/YicenJoJo/classification-fields"
OFFICIAL_COMMIT = "cb52f15"
VERIFIED_REPRO_SPACE = "ArnavM10/repro-2605.07119-classification-fields"
BENCHMARKS: Tuple[str, ...] = ("sierpinski", "cantor_dust", "koch_curve")
METHODS: Tuple[str, ...] = ("cfp", "affine")
METHOD_LABELS = {"cfp": "CFP (Ours)", "affine": "Affine Residual Predictor"}
CSV_METHOD_LABELS = {"cfp": "CFP (Ours)", "affine": "Linear Residual Generator"}
VERDICT_OPTIONS: Tuple[str, ...] = (
"cfp_wins_all_three", # CFP beats the affine residual predictor on every benchmark
"affine_wins_all_three",
"mixed_or_unclear",
)
CORRECT_VERDICT = "cfp_wins_all_three"
# Verified Table 1 cells: ordered MSE x 1e-3, mean and std over 5 seeds
# (trial seeds 5000..5004), averaged over evaluation levels 3-5.
REFERENCE_CELLS: Dict[str, Dict[str, Dict[str, float]]] = {
"sierpinski": {
"cfp": {"mean": 0.897391, "std": 0.185444},
"affine": {"mean": 16.464127, "std": 5.463720},
},
"cantor_dust": {
"cfp": {"mean": 0.468328, "std": 0.107155},
"affine": {"mean": 16.153692, "std": 9.279404},
},
"koch_curve": {
"cfp": {"mean": 0.707131, "std": 0.210827},
"affine": {"mean": 9.131067, "std": 2.022664},
},
}
# Cell tolerance: |submitted - paper_mean| <= max(2 * paper_std, 0.20 * paper_mean).
# Wide enough to absorb CPU run-to-run variation of the official pipeline at the
# pinned commit (the verified rerun matched the paper to the last printed digit),
# tight enough that a wrong or fabricated table scores ~0.
TOLERANCE_SIGMA = 2.0
TOLERANCE_FLOOR_FRACTION = 0.20
# Reward layout: 6 cells share 0.8 of the reward; the verdict is worth 0.2.
CELL_CREDIT = 0.8 / 6.0
VERDICT_CREDIT = 0.2
def cell_tolerance(benchmark: str, method: str) -> float:
"""Deterministic acceptance half-width (in x1e-3 units) for one cell."""
ref = REFERENCE_CELLS[benchmark][method]
return max(TOLERANCE_SIGMA * ref["std"], TOLERANCE_FLOOR_FRACTION * ref["mean"])
def _is_number(value: Any) -> bool:
return (
isinstance(value, (int, float))
and not isinstance(value, bool)
and math.isfinite(float(value))
and float(value) >= 0.0
)
def score_submission(verdict: Any, cells: Any) -> Dict[str, Any]:
"""Deterministically score a submitted Table 1.
Args:
verdict: one of VERDICT_OPTIONS.
cells: {"sierpinski": {"cfp": m, "affine": m}, ...} in ordered MSE x 1e-3,
mean over levels 3-5 and 5 seeds.
Returns:
Report dict with the scalar "reward" and full per-cell diagnostics.
"""
if not isinstance(verdict, str) or verdict not in VERDICT_OPTIONS:
raise ValueError(
f"verdict must be one of {VERDICT_OPTIONS}; got {verdict!r}"
)
if not isinstance(cells, dict):
raise ValueError("cells must be a dict keyed by benchmark name")
missing = [b for b in BENCHMARKS if b not in cells]
if missing:
raise ValueError(f"cells is missing benchmarks: {missing}")
cell_results: Dict[str, Dict[str, Any]] = {}
matched = 0
for benchmark in BENCHMARKS:
bench_cells = cells[benchmark]
if not isinstance(bench_cells, dict):
raise ValueError(f"cells[{benchmark!r}] must be a dict of method -> number")
for method in METHODS:
if method not in bench_cells:
raise ValueError(f"cells[{benchmark!r}] is missing method {method!r}")
submitted = bench_cells[method]
if not _is_number(submitted):
raise ValueError(
f"cells[{benchmark!r}][{method!r}] must be a non-negative finite "
f"number; got {submitted!r}"
)
ref = REFERENCE_CELLS[benchmark][method]
tol = cell_tolerance(benchmark, method)
within = abs(float(submitted) - ref["mean"]) <= tol
if within:
matched += 1
cell_results[f"{benchmark}/{method}"] = {
"submitted": float(submitted),
"paper_mean": ref["mean"],
"paper_std": ref["std"],
"tolerance": tol,
"within_tolerance": within,
}
verdict_correct = verdict == CORRECT_VERDICT
all_cells = matched == len(BENCHMARKS) * len(METHODS)
reward = CELL_CREDIT * matched + (VERDICT_CREDIT if verdict_correct else 0.0)
full_credit = all_cells and verdict_correct
return {
"reward": reward,
"full_credit": full_credit,
"matched_cells": matched,
"total_cells": len(BENCHMARKS) * len(METHODS),
"verdict": verdict,
"verdict_correct": verdict_correct,
"cell_results": cell_results,
"paper": PAPER_ID,
"note": (
"Cells are the Table 1 ordered MSE (x 1e-3) of arXiv:2605.07119 for the "
"CFP vs the affine residual predictor, averaged over levels 3-5 and 5 "
"seeds. Full credit requires all three benchmarks within tolerance and "
"the paper's verdict."
),
}