anhtld commited on
Commit
038c549
·
verified ·
1 Parent(s): 3c4e0ad

Update NCAR and rollout regression tests

Browse files
Files changed (1) hide show
  1. workspace/tests/test_metrics.py +53 -0
workspace/tests/test_metrics.py CHANGED
@@ -12,6 +12,7 @@ from cil.metrics import (
12
  candidate_diversity,
13
  collapse_rate,
14
  mean_nearest_distance_to_set,
 
15
  outcome_safety_violation,
16
  outcome_ptr_at_k,
17
  proxy_positive_tangent_coverage_at_k,
@@ -36,6 +37,11 @@ def test_selector_regret_refuses_unevaluated_candidates() -> None:
36
  selector_regret_at_k([0.5, 0.7], candidates_evaluated=False)
37
 
38
 
 
 
 
 
 
39
  def test_proxy_positive_tangent_coverage_is_not_outcome_ptr() -> None:
40
  generated = [[0.0, 0.1], [2.0, 2.0]]
41
  positives = [[0.0, 0.0]]
@@ -150,6 +156,10 @@ def test_eval_metrics_measured_exports_success_decomposition(tmp_path: Path) ->
150
  assert row["hidden_chart_oracle_success_at_3"] == 1.0
151
  assert row["success_support_gap_at_3"] == 0.0
152
  assert row["success_selector_gap_at_3"] == 1.0
 
 
 
 
153
  assert row["proposal_oracle_utility_gain_over_base_at_3"] == pytest.approx(0.8)
154
  assert row["base_safety_label_known"] == 1.0
155
  assert row["base_unsafe_known"] == 0.0
@@ -223,6 +233,49 @@ def test_eval_metrics_measured_exports_safety_coverage_without_false_zero(
223
  assert "proposal_oracle_unsafe_known_at_2" not in row
224
 
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  def test_eval_metrics_proxy_exports_json_and_latex(tmp_path: Path) -> None:
227
  input_path = tmp_path / "rows.json"
228
  input_path.write_text(
 
12
  candidate_diversity,
13
  collapse_rate,
14
  mean_nearest_distance_to_set,
15
+ normalized_causal_action_regret,
16
  outcome_safety_violation,
17
  outcome_ptr_at_k,
18
  proxy_positive_tangent_coverage_at_k,
 
37
  selector_regret_at_k([0.5, 0.7], candidates_evaluated=False)
38
 
39
 
40
+ def test_normalized_causal_action_regret() -> None:
41
+ assert normalized_causal_action_regret(2.0, 1.25, 1.0) == pytest.approx(0.75)
42
+ assert normalized_causal_action_regret(2.0, 0.5, 1.0) > 1.0
43
+
44
+
45
  def test_proxy_positive_tangent_coverage_is_not_outcome_ptr() -> None:
46
  generated = [[0.0, 0.1], [2.0, 2.0]]
47
  positives = [[0.0, 0.0]]
 
156
  assert row["hidden_chart_oracle_success_at_3"] == 1.0
157
  assert row["success_support_gap_at_3"] == 0.0
158
  assert row["success_selector_gap_at_3"] == 1.0
159
+ assert row["ncar_to_proposal_oracle_at_3"] == pytest.approx(1.125)
160
+ assert row["ncar_to_hidden_chart_oracle_at_3"] == pytest.approx(1.0833333333)
161
+ assert row["support_gap_fraction_to_hidden_at_3"] == pytest.approx(0.3333333333)
162
+ assert row["selector_gap_fraction_to_hidden_at_3"] == pytest.approx(0.75)
163
  assert row["proposal_oracle_utility_gain_over_base_at_3"] == pytest.approx(0.8)
164
  assert row["base_safety_label_known"] == 1.0
165
  assert row["base_unsafe_known"] == 0.0
 
233
  assert "proposal_oracle_unsafe_known_at_2" not in row
234
 
235
 
236
+ def test_eval_metrics_omits_unstable_ncar_when_oracle_matches_base(tmp_path: Path) -> None:
237
+ input_path = tmp_path / "rows.json"
238
+ input_path.write_text(
239
+ json.dumps(
240
+ {
241
+ "rows": [
242
+ {
243
+ "chart_id": "c0",
244
+ "task_id": "pick",
245
+ "seed": 0,
246
+ "candidates_evaluated": True,
247
+ "base_utility": 0.5,
248
+ "generated_utilities": [0.4, 0.5],
249
+ "selected_index": 0,
250
+ }
251
+ ]
252
+ }
253
+ )
254
+ )
255
+ out_dir = tmp_path / "measured_metrics_unstable_ncar"
256
+
257
+ assert (
258
+ eval_metrics.main(
259
+ [
260
+ "--input",
261
+ str(input_path),
262
+ "--out-dir",
263
+ str(out_dir),
264
+ "--mode",
265
+ "measured",
266
+ "--k",
267
+ "2",
268
+ "--bootstrap-samples",
269
+ "20",
270
+ ]
271
+ )
272
+ == 0
273
+ )
274
+
275
+ row = json.loads((out_dir / "metrics.json").read_text())["rows"][0]
276
+ assert "ncar_to_proposal_oracle_at_2" not in row
277
+
278
+
279
  def test_eval_metrics_proxy_exports_json_and_latex(tmp_path: Path) -> None:
280
  input_path = tmp_path / "rows.json"
281
  input_path.write_text(