-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessData.py
281 lines (258 loc) · 8.39 KB
/
processData.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import sys
import os
import re
from collections import defaultdict
TEST_COUNT = 75
inputPath = sys.argv[1]
methods={
"angel" : {"deep" : 0.4, "dog" : 0.425},
"bricks" : {"deep" : 0.5 , "dog" : 0.005},
"buddha" : {"deep" : 0.545 , "dog" : 0.45},
"cars" : {"deep" : 0.31, "dog" : 0.485},
"cat" : {"deep" : 0.47, "dog" : 0.49},
"class" : {"deep" : 0.19 , "dog" : 0.409},
"cubes" : {"deep" : 0.5, "dog" : 0.409},
"knight" : {"deep" : 0.475, "dog" : 0.47},
"layers" : {"deep" : 0.495, "dog" : 0.47},
"rock" : {"deep" : 0.5, "dog" : 0.13},
"room" : {"deep" : 0.395, "dog" : 0.3349},
"table" : {"deep" : 0.48, "dog" : 0.475}
}
refRange={
"00":0.5,
"01" : 0.489879 ,
"02" : 0.473684 ,
"03" : 0.453441 ,
"04" : 0.445344 ,
"05" : 0.421053 ,
"06" : 0.417004 ,
"07" : 0.425101 ,
"08" : 0.396761 ,
"09" : 0.380567 ,
"10" : 0.384615 ,
"11" : 0.384615 ,
"12" : 0.364372 ,
"13" : 0.34413 ,
"14" : 0.352227 ,
"15" : 0.368421 ,
"16" : 0.336032 ,
"17" : 0.340081 ,
"18" : 0.315789 ,
"19" : 0.311741 ,
"20" : 0.303644 ,
"21" : 0.315789 ,
"22" : 0.295547 ,
"23" : 0.283401 ,
"24" : 0.283401 ,
"25" : 0.279352 ,
"26" : 0.275304 ,
"27" : 0.279352 ,
"28" : 0.263158 ,
"29" : 0.267206 ,
"31" : 0.259109 ,
"32" : 0.251012 ,
"33" : 0.251012 ,
"34" : 0.234818 ,
"35" : 0.242915 ,
"36" : 0.246964 ,
"37" : 0.234818 ,
"38" : 0.234818 ,
"39" : 0.218624 ,
"40" : 0.226721
}
count=0
sessionTime=0
dofResults=dict()
warpResults=dict()
warpResultsExt=dict()
rangeResults=dict()
focusResults=dict()
startFocusCount=0
endFocusCount=0
dogCloser=0
deepCloser=0
def addToSelectionDict(inDict, indexA, indexB):
try:
inDict[indexA][indexB] += 1
except:
A = int(indexB== "A")
B = int(indexB == "B")
inDict[indexA] = {'A' : A, 'B' : B}
def addToFocusDict(inDict, index, value):
global dogCloser, deepCloser
try:
inDict[index]["avg"] += float(value)
inDict[index]["min"] = min(float(value),inDict[index]["min"])
inDict[index]["max"] = max(float(value),inDict[index]["max"])
except:
inDict[index] = {"avg" : float(value), "min" : float(value), "max" : float(value)}
if abs(methods[test]["deep"]-float(value)) < abs(methods[test]["dog"]-float(value)):
deepCloser +=1
else:
dogCloser +=1
def addToRangeDict(inDict, index, value):
try:
inDict[index].append(value)
except:
inDict[index] = [value]
def getVariance(values):
count = len(values)
if count == 0:
return 0
avg = sum(values)/count
deviations = [(x - avg) ** 2 for x in values]
variance = sum(deviations)/count
return variance
def clusterRange(index):
global startFocusCount
global endFocusCount
start = 0.5
end = refRange[index]
startValues = []
endValues = []
for val in rangeResults[index]:
startDistance = abs(val-start)
endDistance = abs(val-end)
if startDistance < endDistance:
startValues.append(val)
startFocusCount += 1
else:
endValues.append(val)
endFocusCount += 1
return getVariance(rangeResults[index]), 0.5*(getVariance(startValues)+getVariance(endValues))
def rangeToTimes(ranges):
rangeA = int(1/float(ranges[0][:1]+"."+ranges[0][1:]))
rangeB = int(1/float(ranges[1][:1]+"."+ranges[1][1:]))
return [str(rangeA), str(rangeB)]
for measurement in os.listdir(inputPath):
count += 1
f = os.path.join(inputPath, measurement)
with open(f+"/times.txt") as file:
line = file.readline()
while line:
sessionTime += float(line)
line = file.readline()
with open(f+"/selectResults.txt") as file:
line = file.readline()
while line:
selection = re.search('select/(.*)/', line).group(1)
if "Warping" in line:
if "h.png" in line:
test = re.search('a0(.*)h\\.png', line).group(1)
addToSelectionDict(warpResultsExt, test, selection)
else:
test = re.search('a0(.*)\\.png', line).group(1)
addToSelectionDict(warpResults, test, selection)
else:
scene = re.search('b0(.*)\\.png', line).group(1)
addToSelectionDict(dofResults, scene, selection)
line = file.readline()
with open(f+"/focusResults.txt") as file:
line = file.readline()
while line:
if "Range" in line:
test = re.search('Range(.*)\\.png', line).group(1)
val = float(line.split(' ')[1])
#if test == "39":
# print("a"+str(val))
addToRangeDict(rangeResults, test, val)
else:
test = re.search('Scene(.*)\\.png', line).group(1)
addToFocusDict(focusResults, test, line.split(' ')[1])
line = file.readline()
print("DoF results: \nscene nodof dof")
dof=0
nodof=0
for scene, results in dofResults.items():
print(scene.lower() + " " + str((results['A']/count)*100) + " " + str((results['B']/count)*100))
nodof += results['A']
dof += results['B']
total=nodof+dof
print("Total nodof: " + str((nodof/total)*100))
print("Total dof: " + str((dof/total)*100))
print()
print("Warping results:")
print("Neigbours: \ntest upperVal lowerVal")
for rangeName, results in sorted(warpResults.items()):
rangeNames=rangeName.split('-')
rangeNames[0] = rangeNames[0].replace("Warping","")
times = rangeToTimes(rangeNames)
print(times[0] + "/" + times[1] + " " + str((results['A']/count)*100) + " " + str((results['B']/count)*100))
print()
print("Extremes: \ntest upperVal lowerVal")
for rangeName, results in sorted(warpResultsExt.items()):
rangeNames=rangeName.split('-')
rangeNames[0] = rangeNames[0].replace("Warping","")
times = rangeToTimes(rangeNames)
print(times[0] + "/" + times[1] + " " + str((results['A']/count)*100) + " " + str((results['B']/count)*100))
print()
print("Focusing results:")
print("Range: \ndistance globalvariance clusteredvariance")
for rangeName, vals in sorted(rangeResults.items()):
variances = clusterRange(rangeName)
rangeVal = float(rangeName[:1]+"."+rangeName[1:])
if rangeVal == 0:
continue
print(str(rangeVal) + " " + str(variances[0]) + " " + str(variances[1]))
print()
print("Total focusing range clustered")
totalCount = startFocusCount+endFocusCount
print("Start: " + str((startFocusCount/totalCount)*100))
print("End: " + str((endFocusCount/totalCount)*100))
print()
print("Focusing: \nscene avg min max dog deep")
dogDiff=0
deepDiff=0
for scene, result in focusResults.items():
print(scene+ " " + str(result["avg"]/count) + " " + str(result["min"]) + " " + str(result["max"]) + " " + str(methods[scene]["dog"]) + " " + str(methods[scene]["deep"]))
dogDiff += abs(methods[scene]["dog"]-result["avg"]/count)
deepDiff += abs(methods[scene]["deep"]-result["avg"]/count)
print()
print("DoG difference: " + str(dogDiff/len(methods)))
print("Deep difference: " + str(deepDiff/len(methods)))
print()
totalCloserCount = deepCloser + dogCloser
print("DoG closer: " + str(100*dogCloser/totalCloserCount))
print("Deep closer: " + str(100*deepCloser/totalCloserCount))
print("Total: " + str(totalCloserCount))
print()
sessionTime /= count
print("One session time: " + str(sessionTime) + " s = " + str(sessionTime/60) + " m" )
print("One test time: " + str(sessionTime/TEST_COUNT) + " s")
def stats(values, title):
average = 0
count = 0
var = 0
maxima = -999999999999
minima = 999999999999
for t, c in values.items():
#print(c)
print(t + " " + str(c['avg']) + " " + str(c['min']) + " " + str(c['max']))
continue
#print(t + " " + str(v['A']) + " " + str(v['B']))
for v in c:
print(v)
average += v
count += 1
if v > maxima:
maxima = v
if v < minima:
minima = v
average = average/count
averageNorm = (average-minima)/(maxima-minima)
for t, c in values.items():
for v in c:
v = (v-minima)/(maxima-minima)
var += (v - averageNorm)**2
var = var/count
print(title)
print("Average: " + str(average))
print("Variance: " + str(var))
print("Maxima: " + str(maxima))
print("Minima: " + str(minima))
#print("Statistics:")
#stats(dofResults, "Nodof vs dof")
#stats(rangeResults, "Range")
#stats(warpResults, "Warp")
#stats(rangeResults.values(), "Range")
#stats(focusResults, "Focusing")