-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimal_double_pool_testing.py
121 lines (81 loc) · 2.3 KB
/
optimal_double_pool_testing.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import random
def double_pooling(batch_size,data):
# create sub_batches
test_numbers_in_sub_batch=0
double_batches=[]
for i in range(0,batch_size+1):
double_batches.append([])
counter=0
for i in range(0,batch_size):
j=i+1
while(len(double_batches[i])<batch_size):
double_batches[i].append(data[counter])
double_batches[j].append(data[counter])
counter=counter+1
j=j+1
#print(double_batches)
test_numbers_in_sub_batch=test_numbers_in_sub_batch+batch_size+1
result=[]
for sub_double_batch in double_batches:
result.append(run_batch(sub_double_batch))
faild_builds=0
#print(result)
for flag in result:
if(flag==False):
faild_builds=faild_builds+1
if(faild_builds<=2):
return test_numbers_in_sub_batch
else:
num=faild_builds-1
#print(num)
addition=(num*(num+1)/2)
return (test_numbers_in_sub_batch+addition)
def run_batch(batch):
for element in batch:
if element==False:
return False
break
return True
def assign_pooling(batch_size,data):
total_test=0
sub_batch_size=int((batch_size*(batch_size+1))/2)
batch_numbers=(int)(len(data)/sub_batch_size)
counter=0
for i in range(0,batch_numbers):
upper_bound=(counter+sub_batch_size)
sub_batch=data[counter:upper_bound]
a=double_pooling(batch_size,sub_batch)
total_test=total_test+a
#print(a,"salam")
counter=counter+sub_batch_size
return total_test
import numpy as np
import pandas as pd
import math
import random
import os
optimum_batch_sizes=[]
results=[]
for i in range(0,50):
results.append([])
for i in range(1,50):
min=100000000
min_size=1
print(i)
p=i/100
data=[]
for k in range(0,100000):
a=random.uniform(0, 1)
if(a<p):
data.append(False)
else:
data.append(True)
for k in range(1,21):
test_number = assign_pooling(k, data)
results[i-1].append(test_number)
if(test_number<min):
min=test_number
min_size=k
optimum_batch_sizes.append(min_size)
for i in range(0,len(optimum_batch_sizes)):
print(i,optimum_batch_sizes[i])