-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathutil.py
23 lines (21 loc) · 812 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import numpy as np
from rl.core import Processor
from rl.util import WhiteningNormalizer
from sklearn.preprocessing import MinMaxScaler, StandardScaler
ADDITIONAL_STATE = 4
class NormalizerProcessor(Processor):
def __init__(self):
self.scaler = StandardScaler()
self.normalizer = None
def process_state_batch(self, batch):
batch_len = batch.shape[0]
k = []
for i in range(batch_len):
observe = batch[i][..., :-ADDITIONAL_STATE]
observe = self.scaler.fit_transform(observe)
agent_state = batch[i][..., -ADDITIONAL_STATE:]
temp = np.concatenate((observe, agent_state),axis=1)
temp = temp.reshape((1,) + temp.shape)
k.append(temp)
batch = np.concatenate(tuple(k))
return batch