## BP_Algorithm.cpp in BP_Algorithm.rar

``````
#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>
#include <math.h>

#define input_Num 6
#define hidden_Num 4
#define output_Num 1
#define high 0.999
#define low 0.001

double f(double x)
{
double d;
//	d=0.5*(1.0+tanh(x));
d=1.0/(1.0+exp(-(x)));
if(d>high)
d=high;
if(d<low)
d=low;
return d;
}
struct inputNeuro
{
double input[6];
double teacher[1];
}indata[64];
double output_IL[input_Num];
double output_HL[hidden_Num];
double output_OL[output_Num];
double input_HL[hidden_Num];
double input_OL[output_Num];
double weight_IH[input_Num][hidden_Num];
double weight_HO[hidden_Num][output_Num];
double var_weight_IH[input_Num][hidden_Num];
double var_weight_HO[hidden_Num][output_Num];

double error;
double errorlimit;
double error_HL[hidden_Num];
double error_OL[output_Num];
double yita;
double alpha;
double beta;
double threshold_HL[hidden_Num];
double threshold_OL[output_Num];

void main()
{
int i,j,k,loop;
void save();//函数声明

/*网络初始化*/
errorlimit=0.01;
for(i=0;i<64;i++)
{
if(i<32)
indata[i].input[5]=0;
else
indata[i].input[5]=1;
if(i<16||(i<48&&i>31))
indata[i].input[4]=0;
else
indata[i].input[4]=1;
if(i<8||(i>15&&i<24)||(i<40&&i>31)||(i<56&&i>47))
indata[i].input[3]=0;
else
indata[i].input[3]=1;
if(i<4||(i<12&&i>7)||(i<20&&i>15)||(i<28&&i>23)||
(i<36&&i>31)||(i<44&&i>39)||(i<52&&i>47)||(i<60&&i>55))
indata[i].input[2]=0;
else
indata[i].input[2]=1;
if(i<2||(i<6&&i>3)||(i<10&&i>7)||(i<14&&i>11)||
(i<18&&i>15)||(i<22&&i>19)||(i<26&&i>23)||
(i<30&&i>27)||(i<34&&i>31)||(i<38&&i>35)||(i<42&&i>39)||
(i<46&&i>43)||(i<50&&i>47)||(i<54&&i>51)||(i<58&&i>55)||
(i<62&&i>59))
indata[i].input[1]=0;
else
indata[i].input[1]=1;
if(!(i%2))
indata[i].input[0]=0;
else
indata[i].input[0]=1;

switch(i)
{
case 0:
case 12:
case 18:
case 30:
cas

...
...
... to be continued.

This is a preview. To get the complete source file,

```
```