-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.py
50 lines (27 loc) · 1.2 KB
/
archive.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
import numpy as np
from recordclass import recordclass
archive_record = recordclass("archive_record", "state tolerance counter")
def in_tolerance(state, state2, threshold):
for i in range(state.size):
if abs(state[i]-state2[i]) < threshold:
return True
return False
class State_classifier(object):
def __init__(self, tolerance = 0.01, counter_treshold = 100):
self.archive = []
self.tolerance = tolerance
self.counter = 0
self.counter_treshold = counter_treshold
def check_state(self, current_state):
# return "explore" ## uncomment to see the difference :-)
for item in self.archive:
if in_tolerance(item.state, current_state, item.tolerance):
item.counter += 1
if (item.counter > self.counter_treshold):
item.tolerance *= 0.5
item.counter = 0
return "return"
self.archive.append(archive_record(state=current_state, tolerance=0.1, counter=0))
return "explore"
def clear(self):
self.archive = []