31 lines
861 B
Python
31 lines
861 B
Python
#!/usr/bin/env python
|
|
# coding=utf-8
|
|
'''
|
|
@Author: John
|
|
@Email: johnjim0816@gmail.com
|
|
@Date: 2020-06-10 15:28:30
|
|
@LastEditor: John
|
|
@LastEditTime: 2020-06-12 22:49:18
|
|
@Discription:
|
|
@Environment: python 3.7.7
|
|
'''
|
|
import gym
|
|
import numpy as np
|
|
|
|
class NormalizedActions(gym.ActionWrapper):
|
|
|
|
def action(self, action):
|
|
|
|
low_bound = self.action_space.low
|
|
upper_bound = self.action_space.high
|
|
action = low_bound + (action + 1.0) * 0.5 * (upper_bound - low_bound)
|
|
action = np.clip(action, low_bound, upper_bound)
|
|
|
|
return action
|
|
|
|
def reverse_action(self, action):
|
|
low_bound = self.action_space.low
|
|
upper_bound = self.action_space.high
|
|
action = 2 * (action - low_bound) / (upper_bound - low_bound) - 1
|
|
action = np.clip(action, low_bound, upper_bound)
|
|
return action |