-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·63 lines (51 loc) · 1.81 KB
/
main.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
#!/usr/bin/env python
import sys
import getopt
import numpy as np
from tictactoe import TicTacToe
from adaboost import AdaBoost
from plot import plot
def getArgs(argv):
nIterations = 0
inputFile = ''
outputFile = ''
try:
opts, args = getopt.getopt(argv, 'ht:i:o:')
except getopt.GetoptError:
print('Usage: python main.py <args>')
print('-t <integer>: number of iterations')
print('-i <string>: input file name')
print('-o <string>: output file name')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('Usage: python main.py <args>')
print('-t <integer>: number of iterations')
print('-i <string>: input file name')
print('-o <string>: output file name')
sys.exit()
elif opt == "-t":
nIterations = int(arg)
elif opt == '-i':
inputFile = arg
elif opt == '-o':
outputFile = arg
return inputFile, outputFile, nIterations
def crossValidateAdaboost(inputFile, outputFile, nIterations):
ticTacToe = TicTacToe(inputFile)
avgEin = np.zeros(nIterations)
avgEout = np.zeros(nIterations)
for k in range(ticTacToe.N_FOLDS):
ticTacToe.createTrainAndTestSets(k)
adaboost = AdaBoost(ticTacToe)
Ein, Eout = adaboost.train(ticTacToe, nIterations)
avgEin = np.sum([avgEin, Ein], axis=0)
avgEout = np.sum([avgEout, Eout], axis=0)
print('--------------------------------------')
return avgEin / ticTacToe.N_FOLDS, avgEout / ticTacToe.N_FOLDS
def main(argv):
inputFile, outputFile, nIterations = getArgs(argv)
Ein, Eout = crossValidateAdaboost(inputFile, outputFile, nIterations)
plot(nIterations, Ein, Eout, outputFile)
if __name__ == "__main__":
main(sys.argv[1:])