-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_batching_double_pooling.py
More file actions
108 lines (74 loc) · 2.84 KB
/
dynamic_batching_double_pooling.py
File metadata and controls
108 lines (74 loc) · 2.84 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from batching_techniques import batch_stop4,batch_divide4,batch_bisect,back_to_one,pool_testing
from math import log
class WeigtedSmoothing():
def __init__(self,batch,batching_technique='back_to_one',smoothing_function='normal'):
self.batch=batch
self.batching_technique=batching_technique
self.smoothing_function=smoothing_function
self.disspatcher_batching_technique={'batch_stop4':batch_stop4,'batch_bisect':batch_bisect,'batch_divide4':batch_divide4,'back_to_one':back_to_one, 'pool_testing':pool_testing}
def optimal_size_based_on_failure_rate(self,failure_rate): #pool_testing
if (failure_rate < 0.02):
return 10
elif (failure_rate < 0.03):
return 8
elif (failure_rate < 0.5):
return 6
elif (failure_rate < 0.07):
return 5
elif (failure_rate < 0.12):
return 4
elif (failure_rate < 0.30):
return 3
else:
return 1
def weighted_failure_rate_devide_to_location(self,sub_batch):
denom = 0
number = 0
sub_batch = sub_batch[::-1]
for i in range(0, len(sub_batch)):
denom = denom + (1 / (i + 1))
if (sub_batch[i] == False):
number = number + (1 / (i + 1))
failure_rate = number / denom
try:
failure_rate = failure_rate
except:
failure_rate = 0.07
return self.optimal_size_based_on_failure_rate(failure_rate)
def weighted_failure_rate_devide_to_log_location(self,sub_batch):
failure_count = 0
denom = 0
number = 0
# print(sub_batch)
for i in range(0, len(sub_batch)):
denom = denom + log(i + 1)
if (sub_batch[i] == False):
number = number + log(i + 1)
try:
failure_rate = number / denom
except:
failure_rate = 0.07
return self.optimal_size_based_on_failure_rate(failure_rate)
@staticmethod
def runbatch(batch):
for test in batch:
if (test == False):
return False
return True
def run(self):
test_number=0
batch_size = 4
counter = 100
flag = True
i = 0
while (flag):
i = i + 1
test_number = test_number + 1
slicebatch = self.batch[counter:(counter + batch_size)]
counter = counter + batch_size
if (self.runbatch(slicebatch) == False and batch_size != 1):
test_number+=self.disspatcher_batching_technique[self.batching_technique](slicebatch)
batch_size = self.weighted_failure_rate_devide_to_location(self.batch[counter - 100:(counter)])
if (counter >= len(self.batch)):
flag = False
return test_number