auto-sync 2026-07-04T01:14:16Z workspace (part 4)
Browse files
workspace/tests/test_dominance_selector.py
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import pytest
|
| 5 |
|
| 6 |
from scripts.eval_dominance_selector import _choose_tau, _conformal_quantile, _evaluate_case
|
| 7 |
from scripts.eval_learned_dominance_selector import (
|
|
|
|
| 8 |
_candidate_feature,
|
| 9 |
_choose_thresholds,
|
| 10 |
_evaluate_dataset,
|
|
@@ -330,6 +333,47 @@ def test_learned_dominance_tangent_features_and_success_weighted_target() -> Non
|
|
| 330 |
assert _target_value("success_weighted_margin", utility_margin=0.2, candidate_success=1.0) == 1.2
|
| 331 |
|
| 332 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
def test_nonlinear_dominance_split_is_row_disjoint() -> None:
|
| 334 |
samples = []
|
| 335 |
by_row = {}
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
+
from types import SimpleNamespace
|
| 4 |
+
|
| 5 |
import numpy as np
|
| 6 |
import pytest
|
| 7 |
|
| 8 |
from scripts.eval_dominance_selector import _choose_tau, _conformal_quantile, _evaluate_case
|
| 9 |
from scripts.eval_learned_dominance_selector import (
|
| 10 |
+
_chart_compat_feature,
|
| 11 |
_candidate_feature,
|
| 12 |
_choose_thresholds,
|
| 13 |
_evaluate_dataset,
|
|
|
|
| 333 |
assert _target_value("success_weighted_margin", utility_margin=0.2, candidate_success=1.0) == 1.2
|
| 334 |
|
| 335 |
|
| 336 |
+
def test_chart_compat_feature_is_deployment_visible_and_fixed_width() -> None:
|
| 337 |
+
base = np.arange(14, dtype=float).reshape(2, 7) / 10.0
|
| 338 |
+
context = np.linspace(-0.5, 0.5, 18)
|
| 339 |
+
obs = np.linspace(0.0, 1.0, 32)
|
| 340 |
+
obj = np.linspace(1.0, 2.0, 64)
|
| 341 |
+
target = SimpleNamespace(
|
| 342 |
+
base_action=base,
|
| 343 |
+
feature=np.concatenate([base.reshape(-1), context, obs, obj]),
|
| 344 |
+
)
|
| 345 |
+
source = SimpleNamespace(
|
| 346 |
+
base_action=base + 0.1,
|
| 347 |
+
feature=np.concatenate([base.reshape(-1) + 0.1, context, obs + 0.2, obj + 0.3]),
|
| 348 |
+
)
|
| 349 |
+
|
| 350 |
+
compat = _chart_compat_feature(
|
| 351 |
+
target,
|
| 352 |
+
source,
|
| 353 |
+
chart_feature_mode="base_context_obs_obj",
|
| 354 |
+
)
|
| 355 |
+
feature = _candidate_feature(
|
| 356 |
+
score=1.0,
|
| 357 |
+
base_score=0.25,
|
| 358 |
+
score_mean=0.5,
|
| 359 |
+
score_std=0.5,
|
| 360 |
+
candidate_index=1,
|
| 361 |
+
candidate_type="ctt_transport_rank3",
|
| 362 |
+
tangent=np.zeros(21, dtype=float),
|
| 363 |
+
num_candidates=8,
|
| 364 |
+
feature_set="chart_compat",
|
| 365 |
+
chart_compat=compat,
|
| 366 |
+
)
|
| 367 |
+
|
| 368 |
+
assert compat.shape == (22,)
|
| 369 |
+
assert len(feature) == len(_feature_names("chart_compat")) == 32
|
| 370 |
+
assert compat[0] == 1.0
|
| 371 |
+
assert compat[12] == 1.0
|
| 372 |
+
assert compat[17] == 1.0
|
| 373 |
+
assert np.all(np.isfinite(compat))
|
| 374 |
+
assert np.all(_chart_compat_feature(target, None, chart_feature_mode="base_context_obs_obj") == 0.0)
|
| 375 |
+
|
| 376 |
+
|
| 377 |
def test_nonlinear_dominance_split_is_row_disjoint() -> None:
|
| 378 |
samples = []
|
| 379 |
by_row = {}
|