-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
51 lines (44 loc) · 1.47 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
import os
import model as ml
import functions.activitions as act
from functions.cost import mse
from sklearn import datasets
import numpy as np
import matplotlib.pyplot as plt
from test import configs
def file_to_dataset(file):
text_file = open(file, "r")
lines = text_file.readlines()
text_file.close()
X = []
Y = []
for line in lines:
val = line.split()
if len(val) == 2:
X.append(float(val[0]))
Y.append(float(val[1]))
elif len(val) == 3:
X.append([float(val[0]), float(val[1])])
Y.append(float(val[2]))
return X, Y
path = "Data/"
files = os.listdir(path)
for datafile in files:
print(datafile)
X, Y = file_to_dataset("Data/" + datafile)
X_shape = 1 if len(np.asarray(X).shape) == 1 else np.asarray(X).shape[1]
best_config = None
best_mse = 1
for indx, config in enumerate(configs):
ann = ml.MultiANN(X, Y)
ann.add_layer(ml.Layer(X_shape, config["shape"][0], config["activations"][0]))
for idx, (shp, act) in enumerate(zip(config["shape"][:-1], config["activations"][1:])):
ann.add_layer(ml.Layer(config["shape"][idx], config["shape"][idx + 1], act))
mse = ann.train(config, 1)
if mse < best_mse:
config["idx"] = indx + 1
best_config = config
best_mse = mse
print("\tBEST CONFIG n°%d with %.3f loss" % (best_config["idx"], best_mse))
# exit()
# TODO refacto code