-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathej1_1.cpp
65 lines (53 loc) · 1.63 KB
/
ej1_1.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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <unistd.h>
#include "simulator.h"
#include "util.h"
using namespace std;
//usage
//program <train epoch(N)> gamma(R) success(R)
int main(int argc, char **argv){
//Entrada n p
//n = cantidad de ejemplos
//p = cantidad de percepciones
srand(0);
//ofstream out("recta.txt");
//out << "plot [-2:2] [-2:2] \"input.txt\" using 1:2 with points";
int n,p,epoch=1;
float success=0.8,gamma=0.01;
cin>>n>>p;
int option;
while( (option=getopt(argc, argv, "t:g:s:")) != -1 ){
switch(option){
case 't':
epoch=convert<int>(optarg); break;
case 'g': gamma=convert<float>(optarg); break;
case 's': success=convert<float>(optarg); break;
default: cerr << "Unhandled option " << option << ' ' << (char)option;
cerr << "\nUsage program [options]";
cerr << "\noptions: <t epoch(N)> <g(R)> <e(N)> <s(R [0..1])>\n";
return EXIT_FAILURE;
}
}
cout << "Perceptron simple ";
cout << "Parametros " << endl;
cout << "Ejemplos " << n << endl;
cout << "Percepciones " << p << endl;
cout << "Gamma " << gamma << endl;
cout << "epocas " << epoch << endl;
cout << "Expected success rate %" << success*100 << endl;
simulator benchmark(n, p, gamma);
benchmark.read(cin);
cerr << "lectura de entrenamiento\n";
int cant = benchmark.train(epoch, success);
//benchmark.read(cin);
cerr << "lectura de prueba\n";
float rate = benchmark.test();
if(cant == -1)
cout << "No hubo convergencia" <<endl;
else
cout << "Convergencia en " << cant << " epocas" << endl;
//benchmark.print(cout);
cout << "Con los datos de prueba se obtuvo %" << rate*100 << " de acierto" <<endl;
}