-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrec_env.py
57 lines (48 loc) · 1.84 KB
/
rec_env.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import sys
import random
class Env(object):
def __init__(self):
self.state_space = 1000000
self.action_dim = 1
self.timestep_limit = 10
pass
def read_data(self, f):
'''parse training data, generate recommendataion sequence'''
pass
def reset(self):
'''select the next recommendation sequence'''
pass
def step(self):
'''return one sample'''
dim = random.randint(4,20)
state = [random.randint(0, self.state_space) for i in range(dim)]
dim = random.randint(4,20)
next_state = [random.randint(0, self.state_space) for i in range(dim)]
action = random.random() - 0.5
reward = random.random() - action
done = random.randint(0,1)
return state, action, reward, next_state, done
def pretrained_step(self):
state = [random.uniform(-1.0, 1.0) for i in range(self.state_space)]
next_state = [random.uniform(-1.0, 1.0) for i in range(self.state_space)]
action = random.random() - 0.5
reward = random.random() - 0.5
next_state[0] += action
reward += random.uniform(1.0, 0.2) * action
done = random.randint(0,1)
return state, action, reward, next_state, done
def rand(self):
'''random select one recommendation sequence sample'''
state = [random.uniform(-1.0, 1.0) for i in range(self.state_space)]
return state
def search(self, state, action):
'''knn find the possible reward'''
reward = random.random() - 0.5
reward += random.uniform(1.0, 0.2) * action
next_state = [random.uniform(-1.0, 1.0) for i in range(self.state_space)]
next_state[0] += action
return next_state, reward
if __name__ == '__main__':
e = Env()
for i in range(4):
print (e.pretrained_step())