Skip to content

Commit ffcbb91

Browse files
committed
feat: add comprehensive tests for reward functions in das/env/reward.py
1 parent 6db1e02 commit ffcbb91

2 files changed

Lines changed: 466 additions & 10 deletions

File tree

das/env/reward.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,7 @@ def _log_gap_orders(y_from: float, y_to: float, optimum: float) -> float:
3636

3737

3838
def _terminal_reward(final_y, initial_range, optimum) -> float:
39-
"""Full-magnitude terminal reward, clipped to [-10, 10].
40-
41-
With a known optimum: orders of magnitude of accuracy gained relative to the
42-
random-probe baseline — this does *not* saturate, so reaching gap 1e-8 is
43-
rewarded far more than gap 1e-2 (the probe-scaled version cannot tell them
44-
apart). Otherwise: probe-scaled total improvement (legacy behaviour).
45-
"""
39+
"""Full-magnitude terminal reward, clipped to [-10, 10]."""
4640
if optimum is not None:
4741
return float(np.clip(_log_gap_orders(initial_range[0], final_y, optimum), -10.0, 10.0))
4842
raw = _improvement_ratio(final_y, initial_range[0], initial_range)
@@ -91,7 +85,7 @@ def reward_hybrid_binary(new_best_y, old_best_y, initial_range, is_final=False,
9185
if is_final:
9286
return _terminal_reward(new_best_y, initial_range, optimum)
9387
ratio = _improvement_ratio(new_best_y, old_best_y, initial_range)
94-
return 0.1 if ratio > 1e-8 else 0
88+
return 0.1 if ratio > 1e-8 else 0.0
9589

9690

9791
# Probably the best
@@ -117,8 +111,6 @@ def gain(y_from, y_to):
117111
if step_gain > step_threshold:
118112
return float(base + slope * np.clip(step_gain, 0.0, 1.0))
119113

120-
# Already at the precision target: a stalled step is the goal state, not
121-
# stagnation, so don't penalise it (otherwise solving early is discouraged).
122114
if optimum is not None and (new_best_y - optimum) <= _GAP_FLOOR:
123115
return 0.0
124116

0 commit comments

Comments
 (0)