Home | Develop | Download | Contact
testprog2.c
1 /*
2  * testprog2.c
3  *
4  * Copyright 2011 Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  *
21  */
22 
32 #include <stdlib.h>
33 #include <pds/pdssn.h>
34 
35 int main(int argc, char** argv)
36 {
37  PdsNeuron *Neuron=NULL;
38  PdsSnReal m,r=0.9;
39  PdsNInput *A[4];
40  int i;
41 
43 
44  Neuron=pds_neuron_new(4);
45  if(Neuron==NULL) printf("ERROR: La neurona no ha podido crearse.\n");
46  else
47  {
48  A[0]=pds_ninput_new(); pds_ninput_set_input(A[0], 1.0);
49  A[1]=pds_ninput_new(); pds_ninput_set_input(A[1], 0.5);
50  A[2]=pds_ninput_new(); pds_ninput_set_input(A[2],-0.3);
51  A[3]=pds_ninput_new(); pds_ninput_set_input(A[3],-1.7);
52 
57 
58 
59  i=0;
60  pds_neuron_init_weight_rand(Neuron,-0.1,0.1);
61  do{
62  printf("Try <<%3d>>\n",i);
63  printf("X{:}=\n%f\t%f\t%f\t%f\n",*(Neuron->X[0]),*(Neuron->X[1]),*(Neuron->X[2]),*(Neuron->X[3]));
64  printf("W{:}=\n%f\t%f\t%f\t%f\n",Neuron->W[0],Neuron->W[1],Neuron->W[2],Neuron->W[3]);
65 
66  pds_neuron_iterate(Neuron);
67 
68  pds_neuron_get_output(Neuron,&m);
69  printf("Y=%f\n",m);
70 
72  printf("e=%f\n\n",Neuron->Y[1]);
73 
74  if((r-m)>0.01)
75  {
77  }
78  else break;
79  i++;
80 
81  }while(1);
82 
83  pds_ninput_destroy(&A[0]);
84  pds_ninput_destroy(&A[1]);
85  pds_ninput_destroy(&A[2]);
86  pds_ninput_destroy(&A[3]);
87 
88  pds_neuron_destroy(&Neuron);
89  if(Neuron==NULL) printf("\nLa neurona Neuron ha sido liberado y limpiada.\n");
90  }
92 
93  printf("\n");
94 
95  return EXIT_SUCCESS;
96 }
int pds_neuron_init_weight_rand(PdsNeuron *Neuron, PdsSnReal min, PdsSnReal max)
Inicia el vector de pesos de la Neurona con valores aleatorios uniformemente distribuido entre min y ...
PdsSnReal ** X
Definition: pdsneuron.h:80
PdsSnReal * W
Definition: pdsneuron.h:83
int pds_ninput_set_input(PdsNInput *NInput, PdsSnReal m)
Escribe el valor en la entrada de la neurona NInput.
PdsNInput * pds_ninput_new(void)
Crea una neurona de tipo PdsNInput e inicia con cero todos los elementos.
La estructura tipo PdsNInput . Esta estructura genera una neurona de entrada.
Definition: pdsninput.h:69
PdsSnReal Y[2]
Definition: pdsneuron.h:101
int pds_neuron_get_output(const PdsNeuron *Neuron, PdsSnReal *m)
Devuelve el valor de la salida Y de la Neurona.
void pds_neuron_destroy(PdsNeuron **Neuron)
Libera una neurona de tipo puntero PdsNeuron, y limpia el puntero con NULL.
int pds_neuron_iterate(PdsNeuron *Neuron)
Itera la Neurona Neuron. Adicionalmente (Neuron->Y[1]=0) .
void pds_ninput_destroy(PdsNInput **NInput)
Libera una neurona de tipo puntero PdsNInput, y limpia el puntero con NULL.
int pds_neuron_connect_input_with_ninput(PdsNeuron *Neuron, PdsSnNatural id, PdsNInput *NInput)
Conecta el valor de salida Y de la neurona de entrada NInput con la entrada X[id] de la neurona Neuro...
int pds_neuron_update_u_and_weight_normalized(PdsNeuron *Neuron, PdsSnReal Alpha)
Actualiza los pesos W[i] de la neurona (using the Delta rule). "e" es el error de la salida de la ...
int pds_neuron_evaluate_diff_error(PdsNeuron *Neuron, PdsSnReal y)
Compara el valor de salida de la neurona, con "y", luego lo carga en la variable Y[1] de la neurona ...
La estructura tipo PdsNeuron . Esta estructura genera una neurona de Nel entradas.
Definition: pdsneuron.h:77
float PdsSnReal
Definition: pdssnglobal.h:50
PdsNeuron * pds_neuron_new(PdsSnNatural Nel)
Crea una neurona de tipo PdsNeuron de Nel entradas.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed