-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
228 lines (215 loc) · 7.56 KB
/
main.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include "./Neurone/NeuroneB.h"
#include "./Common/fonctions.h"
#include "./Option/OptionTab.h"
#include "./Neurone/FonctionActivation.h"
#include "./Neurone/Neurone.h"
#include "./Reseau/Reseau.h"
#include "./Option/Option.h"
#include "./Layer/Layer.h"
#include <exception>
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <cctype>
#include <time.h>
#include <string>
#include <cmath>
/**
* @method main
* @param argc Nombre d'argument
* @param argv Tableaux des arguments
* @return Code de sortie : 0 si sortie normal
*/
int main (int argc, char **argv) {
/* Initialisation des options */
OptionTab opts;
enum Options {HELP,VERSION,DEVS,INPUT,OFF,ARCHI,EPOCH,ETA,GRAD,FCT};
opts.addOption(Option( HELP, "--help","-h", Type::NONE, "show help"));
opts.addOption(Option( VERSION, "--version","-v", Type::NONE, "show the Neurone version"));
opts.addOption(Option( DEVS, "--devs","-d", Type::NONE, "display author's names"));
opts.addOption(Option( INPUT, "--input","-i", Type::NONE, "configure the network to run a specific trainingSet"));
opts.addOption(Option( OFF, "--autooff","-o", Type::FLOAT, "set the percentage of error to stop (can slow the learning)"));
opts.addOption(Option( ARCHI, "--archi","-a", Type::NONE, "display the architecture of the current configuration"));
opts.addOption(Option( EPOCH, "--epoch","-e", Type::INT, "Configure the max number of epoch"));
opts.addOption(Option( ETA, "--eta","-lr", Type::FLOAT, "Configure the learning rate"));
opts.addOption(Option( GRAD, "--gradiant","-gr",Type::INT, "Configure the number of epoch before doing the backpropagation (error average)"));
opts.addOption(Option( FCT, "--function","-f", Type::INT, "Configure the activation function"));
/* Configuration par défaut */
std::string filename = "iris.data";
bool archi = false;
double eta = 0.01;
int epoch = 5000;
unsigned int gradiant = 1;
float auto_off = 0;
FonctionActivation::EnumFonctionActivation fct = FonctionActivation::SIGMOID;
/* Reconfiguration du réseau selon les arguments */
for(int i = 1; i < argc; i++) {
switch(opts.getOptionID(argv[i])) {
case HELP :
std::cout << "Usage : ./launcher [OPTIONS] " << std::endl;
std::cout << "Available options :" << std::endl;
opts.printOptions();
return 0;
break;
case VERSION :
std::cout << "Neural Network : version 1.0 " << std::endl;
return 0;
break;
case DEVS :
std::cout << "This tool was created by: [in alpabetic order]"<<std::endl<<"Gaspard Coulet"<<std::endl<<"Félix Guyard"<<std::endl<<"Areski Himeur"<<std::endl<<"Lucas Picasarri-Arrieta"<<std::endl<<"Jean Maurice Raboude"<<std::endl;
return 0;
break;
case INPUT :
{
int choice;
if (argc>i+1&&isdigit(*argv[i+1])) {
choice = atoi(argv[i+1]);
i++;
}
else{
std::cout << "Please chose a file from the following list [more information in trainingSet directory] : "<<std::endl;
std::cout << "\033[1;36m | [1] Wisconsin Diagnostic Breast Cancer Data Set \033[0m"<<std::endl;
std::cout << "\033[1;36m | [2] Iris Plants Data Set \033[0m"<<std::endl;
std::cout << "\033[1;36m | [3] Genuine and forged banknotes Data Set \033[0m"<<std::endl;
std::cout << "\033[1;36m | [4] Spambase Data Set \033[0m"<<std::endl;
std::cout << "\033[1;33m | [5] Select a file...\033[0m "<<std::endl;
std::cout << "Choice : ";
std::cin>>choice;
}
while(choice < 1 || choice > 5){
std::cout << "\033[1;31m Wrong input, please make a valid choice :\033[0m ";
std::cin>>choice;
}
switch(choice) {
case 1 :
filename = "cancer.data";
break;
case 2 :
filename = "iris.data";
break;
case 3 :
filename = "bank.data";
break;
case 4 :
filename = "spam.data";
break;
case 5 :
std::cout << "Enter filename (has to be in trainingSet/ ) :";
std::cin>>filename;
break;
}
}
break;
case OFF :
if (argc>i+1&&isdigit(*argv[i+1])) {
auto_off = atof(argv[i+1]);
std::cout << "Auto_off percentage has been set to " << auto_off << std::endl;
i++;
}
else {
std::cout << "Please specify Auto_off percentage : ";
std::cin >> auto_off;
}
break;
case ARCHI :
archi = true;
break;
case EPOCH :
if (argc>i+1&&isdigit(*argv[i+1])) {
epoch = atoi(argv[i+1]);
std::cout << "Epoch has been set to " << epoch << std::endl;
i++;
}
else {
std::cout << "Please specify number of epoch : ";
std::cin >> epoch;
}
break;
case ETA :
if (argc>i+1&&isdigit(*argv[i+1])) {
eta = atof(argv[i+1]);
std::cout<<"The learning rate has been set to "<<eta<<std::endl;
i++;
}
else {
std::cout << "Please specify ETA : ";
std::cin >> eta;
}
break;
case GRAD :
if(argc>i+1&&isdigit(*argv[i+1])) {
gradiant = atoi(argv[i+1]);
std::cout<<"The gradient descent as been set to "<<gradiant<<std::endl;
i++;
}
else {
std::cout << "Please specify the gradiant : ";
std::cin >> gradiant;
}
break;
default :
std::cout << "\033[1;31mAn argument could not be recognized. Please use "<<argv[0]<<" --help"<<std::endl;
return 1;
break;
case FCT :
{
int choice;
if (argc>i+1&&isdigit(*argv[i+1])) {
choice = atoi(argv[i+1]);
i++;
}
else{
std::cout << "Please chose a function from the following list : "<<std::endl;
std::cout << "\033[1;36m | [1] IDENTITY \033[0m"<<std::endl;
std::cout << "\033[1;36m | [2] BINARYSTEP \033[0m"<<std::endl;
std::cout << "\033[1;36m | [3] SIGMOID \033[0m"<<std::endl;
std::cout << "\033[1;36m | [4] TAN \033[0m"<<std::endl;
std::cout << "\033[1;36m | [5] SIN \033[0m"<<std::endl;
std::cout << "\033[1;36m | [6] RELU \033[0m"<<std::endl;
std::cout << "\033[1;36m | [7] LRELU \033[0m"<<std::endl;
std::cout << "\033[1;36m | [8] PRELU \033[0m"<<std::endl;
std::cout << "\033[1;36m | [9] ELU \033[0m"<<std::endl;
std::cout << "Choice : ";
std::cin>>choice;
}
while(choice < 1 || choice > 9){
std::cout << "\033[1;31m No function, please make a valid choice :\033[0m ";
std::cin>>choice;
}
switch(choice) {
case 1 :
fct = FonctionActivation::IDENTITY;
break;
case 2 :
fct = FonctionActivation::BINARYSTEP;
break;
case 3 :
fct = FonctionActivation::SIGMOID;
break;
case 4 :
fct = FonctionActivation::TAN;
break;
case 5 :
fct = FonctionActivation::SIN;
break;
case 6 :
fct = FonctionActivation::RELU;
break;
case 7 :
fct = FonctionActivation::LRELU;
break;
case 8 :
fct = FonctionActivation::PRELU;
break;
case 9 :
fct = FonctionActivation::ELU;
break;
}
}
break;
}
}
/* Lancement */
startLauncher(filename,archi,epoch,eta,gradiant,fct,auto_off);
return 0;
}