update projects
This commit is contained in:
30
projects/codes/SoftActorCritic/env_wrapper.py
Normal file
30
projects/codes/SoftActorCritic/env_wrapper.py
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
'''
|
||||
Author: JiangJi
|
||||
Email: johnjim0816@gmail.com
|
||||
Date: 2021-04-29 12:52:11
|
||||
LastEditor: JiangJi
|
||||
LastEditTime: 2021-12-22 15:36:36
|
||||
Discription:
|
||||
Environment:
|
||||
'''
|
||||
import gym
|
||||
import numpy as np
|
||||
|
||||
class NormalizedActions(gym.ActionWrapper):
|
||||
def action(self, action):
|
||||
low = self.action_space.low
|
||||
high = self.action_space.high
|
||||
|
||||
action = low + (action + 1.0) * 0.5 * (high - low)
|
||||
action = np.clip(action, low, high)
|
||||
|
||||
return action
|
||||
|
||||
def reverse_action(self, action):
|
||||
low = self.action_space.low
|
||||
high = self.action_space.high
|
||||
action = 2 * (action - low) / (high - low) - 1
|
||||
action = np.clip(action, low, high)
|
||||
return action
|
||||
Reference in New Issue
Block a user