def obFixer(observation_space,observation): # fixes observation ranges, uses hyperbolic tangent for infinite values
newObservation = []
if observation_space.__class__ == gym.spaces.box.Box:
for space in range(observation_space.shape[0]):
high = observation_space.high[space]
low = observation_space.low[space]
if high == numpy.finfo(numpy.float32).max or high == float('Inf'):
newObservation.append(math.tanh(observation[space]))
else:
dif = high - low
percent = (observation[space]+abs(low))/dif
newObservation.append(((percent * 2)-1).tolist())
if observation_space.__class__ == gym.spaces.discrete.Discrete:
c = 0
for neuron in range(observation_space.n):
if observation == neuron:
newObservation.append(1)
else:
newObservation.append(0)
return newObservation
评论列表
文章目录