-
Notifications
You must be signed in to change notification settings - Fork 39
/
rank_based_test.py
63 lines (51 loc) · 1.4 KB
/
rank_based_test.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
58
59
60
61
62
#!/usr/bin/python
# -*- encoding=utf-8 -*-
# author: Ian
# e-mail: [email protected]
# description:
import rank_based
def test():
conf = {'size': 50,
'learn_start': 10,
'partition_num': 5,
'total_step': 100,
'batch_size': 4}
experience = rank_based.Experience(conf)
# insert to experience
print('test insert experience')
for i in range(1, 51):
# tuple, like(state_t, a, r, state_t_1, t)
to_insert = (i, 1, 1, i, 1)
experience.store(to_insert)
print(experience.priority_queue)
print(experience._experience[1])
print(experience._experience[2])
print('test replace')
to_insert = (51, 1, 1, 51, 1)
experience.store(to_insert)
print(experience.priority_queue)
print(experience._experience[1])
print(experience._experience[2])
# sample
print('test sample')
sample, w, e_id = experience.sample(51)
print(sample)
print(w)
print(e_id)
# update delta to priority
print('test update delta')
delta = [v for v in range(1, 5)]
experience.update_priority(e_id, delta)
print(experience.priority_queue)
sample, w, e_id = experience.sample(51)
print(sample)
print(w)
print(e_id)
# rebalance
print('test rebalance')
experience.rebalance()
print(experience.priority_queue)
def main():
test()
if __name__ == '__main__':
main()