SecureCodeEnv / graders /clamp.py
vishaldhakad's picture
change in reward system to strict it between the 0-1
791664b
Raw
History Blame Contribute Delete
514 Bytes
"""
Shared epsilon-clamping utility.
Validator requires scores strictly between 0 and 1: (0.001 … 0.999)
"""
EPSILON = 0.001
SCORE_MIN = EPSILON # 0.001
SCORE_MAX = 1.0 - EPSILON # 0.999
def clamp(score: float) -> float:
"""Clamp any score to (0.001, 0.999) — never exactly 0 or 1."""
try:
v = float(score)
except (TypeError, ValueError):
return 0.5 # safe default for bad inputs
if v != v: # NaN guard
return 0.5
return max(SCORE_MIN, min(SCORE_MAX, v))