Home | Develop | Download | Contact
example.c
1 
2 #include <stdlib.h>
3 
4 #include <pds/pdsra.h>
5 #include <pds/pdsnn.h>
6 
7 int main(int argc, char** argv)
8 {
9  PdsNnNatural i,id,Iter0,Iter1,Iter2;
10  PdsNnNatural Ntraining=150;
11 
12  // Creating the neural network
13  PdsNnNatural Larray[]={128,256,96,48,16,3};
14  PdsNnNatural Nel=6;
15  PdsNeuronML *MLayer=pds_neuronml_new_from_array(Larray,Nel);
16  if(MLayer==NULL) return EXIT_FAILURE;
17 
18  // Configuring the neural network
19  PdsNnReal Alpha=0.6; pds_neuronml_set_alpha(MLayer,Alpha);
20  PdsNnReal Error=0.1; pds_neuronml_set_max_error(MLayer,Error);
21  PdsNnNatural MaxIter=8192; pds_neuronml_set_max_iterations(MLayer,MaxIter);
22 
23  // Creating temporal vectors X and Y.
24  PdsVector *X = pds_vector_new(Larray[0]);
25  PdsVector *Y = pds_vector_new(Larray[Nel-1]);
26  if( (X==NULL)||(Y==NULL) ) return EXIT_FAILURE;
27 
28  // Training the neural network
29  id=0;
30  for(i=0;id<Ntraining;i++)
31  {
32  printf("\nTraining %4d: id=%4d\n",i,id);
33 
34  // Training with data type 0.
37  pds_neuronml_training(MLayer,X,Y);
38  Iter0=pds_neuronml_training_results_printf(MLayer,"100");
39 
40  // Training with data type 1.
43  pds_neuronml_training(MLayer,X,Y);
44  Iter1=pds_neuronml_training_results_printf(MLayer,"010");
45 
46  // Training with data type 2.
49  pds_neuronml_training(MLayer,X,Y);
50  Iter2=pds_neuronml_training_results_printf(MLayer,"001");
51 
52  if( (Iter0==0)&&(Iter1==0)&&(Iter2==0) )
53  id++;
54  else
55  id=0;
56  }
57 
58  pds_neuronml_save_data(MLayer,"data_example.mlayer");
59  printf("\nNeural network saved in data_example.mlayer\n\n");
60 
61  pds_neuronml_free(MLayer);
62 
63  pds_vector_free(X);
64  pds_vector_free(Y);
65 
66  return EXIT_SUCCESS;
67 }
68 
int pds_neuronml_set_max_error(PdsNeuronML *NeuronML, PdsNnReal MaxError)
Coloca el maximo margen error RMS aceptado en la salida de la estructura PdsNeuronML.
PdsNeuronML * pds_neuronml_new_from_array(const PdsNnNatural *L, PdsNnNatural Nel)
Crea una estructura de tipo PdsNeuronML.
int pds_neuronml_set_alpha(PdsNeuronML *NeuronML, PdsNnReal Alpha)
Coloca el valor del factor de aprendizaje Alpha.
int pds_generate_data_output_mspace(PdsVector *Y, PdsRaNatural M)
Genera un vector con +1 en la posición M del vector Y, los otros valores son -1.
La estructura tipo PdsNeuronML . Esta estructura genera una red neuronal multi capa. Para usar incluir pds/pdsnn.h.
Definition: pdsneuronml.h:74
void pds_neuronml_free(PdsNeuronML *NeuronML)
Libera una neurona de tipo puntero PdsNeuronML.
int pds_generate_data_input_rand(PdsVector *X, PdsNnReal A)
double pds_generate_data_func1(double x)
Genera una funcion de periodo 2*pi y dominio entre -1 y 1.
int pds_neuronml_set_max_iterations(PdsNeuronML *NeuronML, PdsNnNatural MaxIter)
Coloca el máximo numero de iteraciones aceptado, cualquier valor mayor provoca que se detenga el algo...
unsigned int PdsNnNatural
Definition: pdsnnglobal.h:62
float PdsNnReal
Definition: pdsnnglobal.h:52
int pds_neuronml_save_data(const PdsNeuronML *NeuronML, const char *mlayer_filename)
Salva una estructura de tipo PdsNeuronML en un archivo de texto.
int pds_neuronml_training(PdsNeuronML *NeuronML, const PdsVector *Input, PdsVector *Output)
Entrena la red neuronal multicapa NeuronML. Usa el valor de Output como entrenamiento, para finalizar carga el nuevo valor de salida en Output.
int pds_generate_data_input_func2pi(PdsVector *X, double(*func)(double), PdsNnReal C, PdsNnReal OffsetError)
Genera un vector con C ciclos de la función func() con un error de offset de valor OffsetError...
PdsNnNatural pds_neuronml_training_results_printf(PdsNeuronML *MLayer, const char *Type)
Muestra los resultados del entrenamiento de la red neuronal multicapa NeuronML.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed