Support source-evidence nonlinear dominance diagnostics
Browse files
workspace/scripts/eval_nonlinear_dominance_selector.py
CHANGED
|
@@ -30,11 +30,15 @@ from scripts.eval_dominance_selector import ( # noqa: E402
|
|
| 30 |
_rows,
|
| 31 |
)
|
| 32 |
from scripts.eval_learned_dominance_selector import ( # noqa: E402
|
|
|
|
| 33 |
_candidate_dataset,
|
| 34 |
_evaluate_predictions,
|
| 35 |
_feature_names,
|
| 36 |
_group_means,
|
|
|
|
| 37 |
_simple_summary,
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
|
|
@@ -49,6 +53,15 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 49 |
parser.add_argument("--calibration-target-index", type=Path, required=True)
|
| 50 |
parser.add_argument("--eval-input", type=Path, required=True)
|
| 51 |
parser.add_argument("--eval-target-index", type=Path, required=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
parser.add_argument(
|
| 53 |
"--checkpoint-template",
|
| 54 |
default="runs/ctt_residual_full_seed{seed}/model.pt",
|
|
@@ -61,7 +74,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 61 |
parser.add_argument("--k", type=int, default=8)
|
| 62 |
parser.add_argument(
|
| 63 |
"--feature-set",
|
| 64 |
-
choices=
|
| 65 |
default="context_tangent",
|
| 66 |
)
|
| 67 |
parser.add_argument(
|
|
@@ -104,6 +117,10 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 104 |
args.eval_target_index,
|
| 105 |
chart_feature_mode=chart_feature_mode,
|
| 106 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
dataset_target = (
|
| 108 |
"utility_margin" if args.target == "positive_margin" else args.target
|
| 109 |
)
|
|
@@ -114,6 +131,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 114 |
k=args.k,
|
| 115 |
feature_set=args.feature_set,
|
| 116 |
target=dataset_target,
|
|
|
|
| 117 |
)
|
| 118 |
eval_dataset = _candidate_dataset(
|
| 119 |
eval_rows,
|
|
@@ -122,6 +140,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 122 |
k=args.k,
|
| 123 |
feature_set=args.feature_set,
|
| 124 |
target=dataset_target,
|
|
|
|
| 125 |
)
|
| 126 |
fit_rows, select_rows = _split_rows(
|
| 127 |
calibration_dataset,
|
|
@@ -182,12 +201,15 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 182 |
"chart_feature_mode": chart_feature_mode,
|
| 183 |
"calibration_input": str(args.calibration_input),
|
| 184 |
"eval_input": str(args.eval_input),
|
|
|
|
| 185 |
"data_hash": eval_index.get("content_hash"),
|
| 186 |
"split_hash": eval_index.get("split_hash"),
|
| 187 |
"calibration_target_content_hash": calibration_index.get("content_hash"),
|
| 188 |
"calibration_target_split_hash": calibration_index.get("split_hash"),
|
| 189 |
"eval_target_content_hash": eval_index.get("content_hash"),
|
| 190 |
"eval_target_split_hash": eval_index.get("split_hash"),
|
|
|
|
|
|
|
| 191 |
"num_calibration_rows": len(calibration_rows),
|
| 192 |
"num_fit_rows": fit_dataset["num_rows"],
|
| 193 |
"num_selection_rows": select_dataset["num_rows"],
|
|
@@ -508,10 +530,12 @@ def _write_provenance(out_dir: Path, args: argparse.Namespace) -> None:
|
|
| 508 |
(out_dir / "git_hash.txt").write_text(_run(["git", "rev-parse", "HEAD"]) + "\n")
|
| 509 |
hashes = {
|
| 510 |
"calibration_input": _sha256(args.calibration_input),
|
| 511 |
-
"calibration_target_index": _sha256(args.calibration_target_index),
|
| 512 |
"eval_input": _sha256(args.eval_input),
|
| 513 |
-
"eval_target_index": _sha256(args.eval_target_index),
|
| 514 |
}
|
|
|
|
|
|
|
| 515 |
(out_dir / "data_hash.txt").write_text(json.dumps(hashes, indent=2, sort_keys=True) + "\n")
|
| 516 |
(out_dir / "split_hash.txt").write_text(
|
| 517 |
json.dumps(
|
|
@@ -527,7 +551,7 @@ def _write_provenance(out_dir: Path, args: argparse.Namespace) -> None:
|
|
| 527 |
|
| 528 |
|
| 529 |
def _index_hash(path: Path) -> dict[str, Any]:
|
| 530 |
-
payload = json.loads(path.read_text())
|
| 531 |
return {
|
| 532 |
"split": payload.get("split"),
|
| 533 |
"content_hash": payload.get("content_hash"),
|
|
|
|
| 30 |
_rows,
|
| 31 |
)
|
| 32 |
from scripts.eval_learned_dominance_selector import ( # noqa: E402
|
| 33 |
+
FEATURE_SET_CHOICES,
|
| 34 |
_candidate_dataset,
|
| 35 |
_evaluate_predictions,
|
| 36 |
_feature_names,
|
| 37 |
_group_means,
|
| 38 |
+
_resolve_index_path,
|
| 39 |
_simple_summary,
|
| 40 |
+
_source_evidence_map,
|
| 41 |
+
_uses_source_evidence,
|
| 42 |
)
|
| 43 |
|
| 44 |
|
|
|
|
| 53 |
parser.add_argument("--calibration-target-index", type=Path, required=True)
|
| 54 |
parser.add_argument("--eval-input", type=Path, required=True)
|
| 55 |
parser.add_argument("--eval-target-index", type=Path, required=True)
|
| 56 |
+
parser.add_argument(
|
| 57 |
+
"--source-index",
|
| 58 |
+
type=Path,
|
| 59 |
+
default=None,
|
| 60 |
+
help=(
|
| 61 |
+
"Train split chart index used for source-evidence features. "
|
| 62 |
+
"Defaults to --calibration-target-index."
|
| 63 |
+
),
|
| 64 |
+
)
|
| 65 |
parser.add_argument(
|
| 66 |
"--checkpoint-template",
|
| 67 |
default="runs/ctt_residual_full_seed{seed}/model.pt",
|
|
|
|
| 74 |
parser.add_argument("--k", type=int, default=8)
|
| 75 |
parser.add_argument(
|
| 76 |
"--feature-set",
|
| 77 |
+
choices=FEATURE_SET_CHOICES,
|
| 78 |
default="context_tangent",
|
| 79 |
)
|
| 80 |
parser.add_argument(
|
|
|
|
| 117 |
args.eval_target_index,
|
| 118 |
chart_feature_mode=chart_feature_mode,
|
| 119 |
)
|
| 120 |
+
source_index_path = _resolve_index_path(args.source_index or args.calibration_target_index)
|
| 121 |
+
source_evidence, source_index = (
|
| 122 |
+
_source_evidence_map(source_index_path) if _uses_source_evidence(args.feature_set) else ({}, {})
|
| 123 |
+
)
|
| 124 |
dataset_target = (
|
| 125 |
"utility_margin" if args.target == "positive_margin" else args.target
|
| 126 |
)
|
|
|
|
| 131 |
k=args.k,
|
| 132 |
feature_set=args.feature_set,
|
| 133 |
target=dataset_target,
|
| 134 |
+
source_evidence=source_evidence,
|
| 135 |
)
|
| 136 |
eval_dataset = _candidate_dataset(
|
| 137 |
eval_rows,
|
|
|
|
| 140 |
k=args.k,
|
| 141 |
feature_set=args.feature_set,
|
| 142 |
target=dataset_target,
|
| 143 |
+
source_evidence=source_evidence,
|
| 144 |
)
|
| 145 |
fit_rows, select_rows = _split_rows(
|
| 146 |
calibration_dataset,
|
|
|
|
| 201 |
"chart_feature_mode": chart_feature_mode,
|
| 202 |
"calibration_input": str(args.calibration_input),
|
| 203 |
"eval_input": str(args.eval_input),
|
| 204 |
+
"source_index": str(source_index_path) if _uses_source_evidence(args.feature_set) else None,
|
| 205 |
"data_hash": eval_index.get("content_hash"),
|
| 206 |
"split_hash": eval_index.get("split_hash"),
|
| 207 |
"calibration_target_content_hash": calibration_index.get("content_hash"),
|
| 208 |
"calibration_target_split_hash": calibration_index.get("split_hash"),
|
| 209 |
"eval_target_content_hash": eval_index.get("content_hash"),
|
| 210 |
"eval_target_split_hash": eval_index.get("split_hash"),
|
| 211 |
+
"source_content_hash": source_index.get("content_hash"),
|
| 212 |
+
"source_split_hash": source_index.get("split_hash"),
|
| 213 |
"num_calibration_rows": len(calibration_rows),
|
| 214 |
"num_fit_rows": fit_dataset["num_rows"],
|
| 215 |
"num_selection_rows": select_dataset["num_rows"],
|
|
|
|
| 530 |
(out_dir / "git_hash.txt").write_text(_run(["git", "rev-parse", "HEAD"]) + "\n")
|
| 531 |
hashes = {
|
| 532 |
"calibration_input": _sha256(args.calibration_input),
|
| 533 |
+
"calibration_target_index": _sha256(_resolve_index_path(args.calibration_target_index)),
|
| 534 |
"eval_input": _sha256(args.eval_input),
|
| 535 |
+
"eval_target_index": _sha256(_resolve_index_path(args.eval_target_index)),
|
| 536 |
}
|
| 537 |
+
if getattr(args, "source_index", None) is not None:
|
| 538 |
+
hashes["source_index"] = _sha256(_resolve_index_path(args.source_index))
|
| 539 |
(out_dir / "data_hash.txt").write_text(json.dumps(hashes, indent=2, sort_keys=True) + "\n")
|
| 540 |
(out_dir / "split_hash.txt").write_text(
|
| 541 |
json.dumps(
|
|
|
|
| 551 |
|
| 552 |
|
| 553 |
def _index_hash(path: Path) -> dict[str, Any]:
|
| 554 |
+
payload = json.loads(_resolve_index_path(path).read_text())
|
| 555 |
return {
|
| 556 |
"split": payload.get("split"),
|
| 557 |
"content_hash": payload.get("content_hash"),
|