From 9e782d036fd9ea09a747c2dd49313b3de5345c67 Mon Sep 17 00:00:00 2001 From: LI Yunxiang <39279048+Banmahhhh@users.noreply.github.com> Date: Mon, 11 May 2020 10:17:59 +0800 Subject: [PATCH] Update utils.py (#261) * Update utils.py * Update utils.py --- parl/utils/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/parl/utils/utils.py b/parl/utils/utils.py index c52a568..225323e 100644 --- a/parl/utils/utils.py +++ b/parl/utils/utils.py @@ -13,6 +13,7 @@ # limitations under the License. import sys +import numpy as np __all__ = [ 'has_func', 'action_mapping', 'to_str', 'to_byte', 'is_PY2', 'is_PY3', @@ -45,9 +46,12 @@ def action_mapping(model_output_act, low_bound, high_bound): Returns: action: np.array, which value is in [low_bound, high_bound] """ + assert np.all(((model_output_act<=1.0), (model_output_act>=-1.0))), \ + 'the action should be in range [-1.0, 1.0]' assert high_bound > low_bound action = low_bound + (model_output_act - (-1.0)) * ( (high_bound - low_bound) / 2.0) + action = np.clip(action, low_bound, high_bound) return action -- GitLab