-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
46 lines (36 loc) · 968 Bytes
/
utils.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
class Averager():
def __init__(self):
self.n = 0
self.v = 0
def add(self, x):
self.v = (self.v * self.n + x) / (self.n + 1)
self.n += 1
def item(self):
return self.v
class Stoper():
def __init__(self, early_step):
self.max = 0
self.cur = 0
self.maxindex = 0
self.curindex = 0
self.early_step = early_step
def add(self, x):
self.cur = x
self.curindex += 1
def judgesave(self):
if self.cur > self.max:
return True
else:
return False
def judge(self):
if self.cur > self.max:
self.max = self.cur
self.maxindex = self.curindex
if self.curindex - self.maxindex >= self.early_step:
return True
else:
return False
def showfinal(self):
result = "AUC {}\n".format(self.max)
print(result)
return self.max