-
Notifications
You must be signed in to change notification settings - Fork 2
/
testCardChoosing.py
55 lines (47 loc) · 1.68 KB
/
testCardChoosing.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
import random
import time
import sys, json, math, os, collections, ast
import util
fPretend = open('pretend.json')
line = fPretend.read().replace("\\", '')
pCard = json.loads(line)
fWeights = open('weightsWL.json')
weights = collections.Counter(ast.literal_eval(json.loads(fWeights.read())))
#fTestData = open('./trainsets/trainset4.json')
fTestData = open('./trainsets/testsetWarlock.json')
#fTestData = open('./trainsets/trainsetHunterCombined.txt')
testData = ast.literal_eval(json.loads(fTestData.read()))
#Complete random choices
# threeCards = {}
# for _ in range(0,3):
# thisChoice = random.choice(pCard.keys())
# threeCards[thisChoice] = util.extract(thisChoice,pCard)
# #print pCard[thisChoice], util.dotProduct(weights,threeCards[thisChoice])
# print util.dotProduct(weights,threeCards[thisChoice])
#Compare data
# threeCards = {}
# for _ in range(0,3):
# thisChoice = random.choice(pCard.keys())
# threeCards[thisChoice] = util.extract(thisChoice,pCard)
# modelValue = util.dotProduct(weights,threeCards[thisChoice])
# oracleValue =
correctCount = 0
totalCount = 0
for key,value in testData.iteritems():
totalCount += 1
compareResults = []
myChoice = (0,0)
trueChoice = (0,0)
for i in range(0,3):
if value[i] > trueChoice[1]: trueChoice = (key[i],value[i])
thisValue = []
modelValue = util.dotProduct(weights,util.extract(key[i],pCard))
if modelValue > myChoice[1]: myChoice = (key[i],modelValue)
thisValue.append((key[i],value[i],modelValue))
compareResults.append(thisValue)
if trueChoice[0] == myChoice[0]:
compareResults.append((trueChoice,True))
correctCount += 1
else: compareResults.append(False)
print compareResults
print correctCount/float(totalCount)