-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.py
93 lines (74 loc) · 3.63 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
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
from Activations import actF
from Parser import *
from Validator import *
# ---------------------- GRID SEARCH PARAMETERS ----------------------
configuration = {
"lr": np.array([0.043]),
"tau": np.array([350]),
"nesterov": np.array([True]),
"momentum": np.array([0.65]),
"lambda": np.array([0.00005]),
"patience": np.array([7]),
"epoch": np.array([20]),
"batchSize": np.array([1]),
"af_out": np.array([actF["linear"]]),
"af_ho": np.array([actF["tan"]]),
"hiddenUnit": np.array([25])
}
# ---------------------- GRID SEARCH PARAMETERS ----------------------
def taskCup(tr, vl, config):
"""
This method is user for train a neural network give a specific training and validation set, works only for
Cup regression task, config represents the hyperparameters
:param tr: Training set
:param vl: Validation set
:param config: Combination of hyperparameters
:return: pointer to trainer instance
"""
trainer = Trainer(tr=tr, vl=vl, l_rate=tau_linear_decay(config[1], etaS=float(config[0])), metric=mee)
trainer.set(features=10, lmd=float(config[4]), alfa=float(config[3]), batch_size=int(config[7]),
max_epochs=int(config[6]), patience=config[5], nesterov=config[2])
# Oss. config 8 and 9 are both objects that contains information to activation functions
# with "dPhi" we refer "derivative of activation function"
trainer.addLayer(int(config[10]), phi=config[9].phi, d_phi=config[9].dPhi)
trainer.addLayer(2, phi=config[8].phi, d_phi=config[8].dPhi)
trainer.compile() # initialize weights
trainer.fit() # training phase
return trainer
def taskMonk(tr, vl, config):
"""
This method is user for train a neural network give a specific training and validation set, works only for
Monk classification task, config represents the hyperparameters
:param tr: Training set
:param vl: Validation set
:param config: Combination of hyperparameters
:return: pointer to trainer instance
"""
trainer = Trainer(tr=tr, vl=vl, l_rate=fixed_lr(float(config[0])), metric=mse)
trainer.set(features=17, lmd=float(config[4]), alfa=float(config[3]), batch_size=int(config[7]),
max_epochs=int(config[6]), patience=config[5], nesterov=config[2])
# Oss. config 8 and 9 are both objects that contains information to activation functions
# with "dPhi" we refer "derivative of activation function"
trainer.addLayer(int(config[10]), phi=config[9].phi, d_phi=config[9].dPhi)
trainer.addLayer(1, phi=config[8].phi, d_phi=config[8].dPhi)
trainer.compile() # initialize weights
trainer.fit() # training phase
return trainer
def Monk():
# monk_tr = importMonk("datasets/Monk3/monks-3.train")
# monk_vl = importMonk("datasets/Monk3/monks-3.test")
# monk_tr = importMonk("datasets/Monk2/monks-2.train")
# monk_vl = importMonk("datasets/Monk2/monks-2.test")
monk_tr = importMonk("datasets/Monk2/monks-1.train")
monk_vl = importMonk("datasets/Monk2/monks-1.test")
# Starting the validation phase
Validation(confg=configuration, cpu=20, task=taskMonk).monkValidation(tr=monk_tr, vl=monk_vl)
def Cup():
cup_tr = importCUP("datasets/Cup/ML-CUP21-TR.csv")
cup_ts = importCUP("datasets/Cup/ML-CUP21-TS.csv")
pathBlindTS = "datasets/Cup/ML-CUP21-BLIND-TS.csv"
# Starting the validation phase
v = Validation(confg=configuration, cpu=16, task=taskCup)
v.cupValidation(trainSet=cup_tr, testSet=cup_ts, blind=True, lastTrain=True, blindTS=pathBlindTS)
if __name__ == '__main__':
Cup()