#include <stdio.h>
#include <math.h>
#include <local/simu.h>
#define Rlow -0.30
#define Rhigh 0.30
#define urand() (drand48() * (Rhigh - Rlow) + Rlow)
double drand48();
main(argc, argv)
int argc;
char **argv;
{
int i, l, l1, ip, data, datb, co, study, d[40];
double avra, avrb;
double te, j0, j1, j2, j3, o[40];
Layer Layer1;
Layer Layer2;
Layer Layer3;
Layer Layer4;
Layer Layer5;
srand48(1);
Layer1 = Neurons(1);
Coefficient_of_Layer(Layer1, 0.0, 0.0, 0.0, 1.0);
Layer2 = Neurons(4);
Coefficient_of_Layer(Layer2, 0.0, 0.0, 0.0, 1.0);
Layer3 = Neurons(1);
Coefficient_of_Layer(Layer3, 0.0, 0.0, 0.0, 1.0);
Layer4 = Neurons(4);
Coefficient_of_Layer(Layer4, 0.0, 0.0, 0.0, 1.0);
Layer5 = Neurons(1);
Coefficient_of_Layer(Layer5, 0.0, 0.0, 0.0, 1.0);
Teach_Signal_Manager(Layer3);
for(l = 0 ; l <= 3 ; l++){
Connect(Layer1, 0, Layer2, l, urand());
Connect(Layer2, l, Layer3, 0, urand());
}
for(l = 0 ; l <= 3 ; l++)
for(l1 = 0 ; l1 <= 3 ; l1++)
Connect(Layer4, l, Layer2, l1, urand());
for(l = 0 ; l <= 3 ; l++)
Connect(Layer5, 0, Layer2, l, urand());
Connect(Layer5, 0, Layer3, 0, urand());
Change_Coefficient_W(0.4, 0.35);
for(l1=0 ; l1<=1 ; l1++){
srand(1);
study = 9999;
if(l1==0) study = 4999;
datb = 0; j0 = 0.0; j1 = 0.0; j2 = 0.0; j3 = 0.0; co = 0;
for(i=1 ; i<=study ; i++){
ip = rand()%10;
data = 0; avrb = 0;
if(ip <= 5) data = 1;
te = 0.0;
if(data==1 && datb==1) te = 1.0;
Put_Output(Layer5, 0, 1.0);
Put_Output(Layer1, 0, (double)data);
Put_Output(Layer4, 0, j0);
Put_Output(Layer4, 1, j1);
Put_Output(Layer4, 2, j2);
Put_Output(Layer4, 3, j3);
Output_Calculation(Layer2);
Put_Teach_Signal(Layer3, te);
Output_Calculation(Layer3);
avrb = Error_Calculation(Layer3);
Error_Calculation(Layer2);
Change_Weight(Layer3);
Change_Weight(Layer2);
j0 = Get_Output(Layer2, 0);
j1 = Get_Output(Layer2, 1);
j2 = Get_Output(Layer2, 2);
j3 = Get_Output(Layer2, 3);
datb = data;
avra = avrb;
}
printf(" Study... %d turn Avr... %f", i, avrb);
printf(" O.K.\n");
srand(atoi(argv[1]));
for(i=0 ; i<=39 ; i++){
ip = rand()%10;
d[i] = 0;
if(ip <= 4) d[i] = 1;
if(i <= 2) d[i] = 0;
Put_Output(Layer5, 0, 1.0);
Put_Output(Layer1, 0, (double)d[i]);
Put_Output(Layer4, 0, j0);
Put_Output(Layer4, 1, j1);
Put_Output(Layer4, 2, j2);
Put_Output(Layer4, 3, j3);
Output_Calculation(Layer2);
Output_Calculation(Layer3);
j0 = Get_Output(Layer2, 0);
j1 = Get_Output(Layer2, 1);
j2 = Get_Output(Layer2, 2);
j3 = Get_Output(Layer2, 3);
o[i] = Get_Output(Layer3, 0);
}
for(l=0 ; l<=19 ; l++)
printf(" %d %f %d %f\n", d[l], o[l], d[l+20], o[l+20]);
printf(" Push return key.\n");
fgetc(stdin);
printf(" O.K.\n");
}
}