-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPerformance.py
More file actions
45 lines (36 loc) · 1.2 KB
/
Performance.py
File metadata and controls
45 lines (36 loc) · 1.2 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
from imageImplementation import CommonApp
import logging
import sys
def getScoresWLandY(w, example):
return example.findScoreAllClasses(w), example.whiteList,example.trueY
def printStrongAndWeakTrainError(params, wBest):
numCorrect = 0.0
exampleScoresList = CommonApp.accessExamples(params,wBest,getScoresWLandY, None)
for scores,whiteList,trueY in exampleScoresList:
bestLabel = -1
maxScore = -1e100
for l in range(params.numYLabels):
if (scores[l] >= maxScore) and l not in whiteList:
maxScore = scores[l]
bestLabel = l
assert(bestLabel >= 0)
if bestLabel == trueY:
numCorrect+=1
trainingError = 1.0 - (numCorrect/float(params.numExamples))
logging.debug("\nEvaluation error: %f"%(trainingError))
def getScoresandUUID(w,example):
return example.findScoreAllClasses(w), example.fileUUID
def writePerformance(params, w, resultFile):
fh= open(resultFile, 'w')
exampleScoresList = CommonApp.accessExamples(params,w,getScoresandUUID, None)
UUIDs = {}
for exampleScores,UUID in exampleScoresList:
if UUID in UUIDs:
continue
else:
UUIDs[UUID] = 1
fh.write("%s " %UUID)
for key in exampleScores:
fh.write("%d %f " %(key, exampleScores[key]))
fh.write("\n")
fh.close()