-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhermecio.c
119 lines (98 loc) · 2.86 KB
/
hermecio.c
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
/*
Fast Artificial Neural Network Library (fann)
Copyright (C) 2003 Steffen Nissen (lukesky@diku.dk)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include "fann.h"
int FANN_API test_callback(struct fann *ann, struct fann_train_data *train,
unsigned int max_epochs, unsigned int epochs_between_reports,
float desired_error, unsigned int epochs)
{
printf("Epochs %8d. MSE: %.5f. Desired-MSE: %.5f\n", epochs, fann_get_MSE(ann), desired_error);
return 0;
}
#define N 3
#define PORTE_MAPA ((N)*(N))
#define NUM_SALIDAS 4
#define NUM_OCULTAS ((PORTE_MAPA + NUM_SALIDAS)>>1)
void entrena()
{
const unsigned int num_input = PORTE_MAPA;
const unsigned int num_output = NUM_SALIDAS;
const unsigned int num_layers = 3;
const unsigned int num_neurons_hidden = NUM_OCULTAS;
const float desired_error = (const float) 0.001;
const unsigned int max_epochs = 500000;
const unsigned int epochs_between_reports = 1000;
struct fann *ann = fann_create_standard(num_layers, num_input,num_neurons_hidden, num_output);
fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);
fann_train_on_file(ann, "vale.data", max_epochs,epochs_between_reports, desired_error);
fann_save(ann, "vale_float.net");
fann_destroy(ann);
}
const char* salidas[]=
{
"arriba",
"abajo",
"izquierda",
"derecha"
};
const char* get_direccion(fann_type *direcciones)
{
unsigned int i;
int direccion = 0;
float value = -1000.0f;
for(i=0;i<4;i++)
{
if(direcciones[i]>value)
{
value = direcciones[i];
direccion = i;
}
}
return salidas[direccion];
}
void prueba()
{
fann_type *calc_out;
fann_type input[PORTE_MAPA];
unsigned int i,j;
struct fann *ann = fann_create_from_file("vale_float.net");
for(i=0;i<PORTE_MAPA;i++)
{
printf("%u:",i);
scanf("%f",&input[i]);
}
printf("\n");
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
printf("%.0f\t",input[i*N + j]);
}
printf("\n");
}
calc_out = fann_run(ann, input);
printf("ir a la %s",get_direccion(calc_out));
fann_destroy(ann);
return 0;
}
int main()
{
//entrena();
prueba();
getchar();
return 0;
}