文件输入输出目录为:F:\BP\
训练样本文件名:训练样本.txt
值为:
1
1
-1
1
-1
1
0
1
0
1
输出文件名为:阈值.txt 权值.txt
=========================
#include "stdlib.h"
#include "math.h"
#include "conio.h"
#include "stdio.h"
#define N 2 /*/学习样本个数*/
#define IN 3 /*/输入层神经元数目*/
#define HN 3 /*/隐层神经元数目*/
#define ON 2 /*/输出层神经元数目*/
#define Z 20 /*/旧权值保存-》每次study的权值都保存下来*/
double P[IN]; /*/单个样本输入数据*/
double T[ON]; /*/单个样本教师数据*/
double W[HN][IN]; /*/输入层至隐层权值*/
double V[ON][HN]; /*/隐层至输出层权值*/
double X[HN]; /*/隐层的输入*/
double Y[ON]; /*/输出层的输入*/
double H[HN]; /*/隐层的输出*/
double O[ON]; /*/输出层的输出*/
double YU_HN[HN]; /*/隐层的阈值*/
double YU_ON[ON]; /*/输出层的阈值*/
double err_m[N]; /*/第m个样本的总误差*/
double a; /*/输出层至隐层的学习效率*/
double b; /*/隐层至输入层学习效率*/
double alpha; /*/动量因子,改进型bp算法使用*/
double d_err[ON];
FILE *fp;
/*定义一个放学习样本的结构*/
struct {
double input[IN];
double teach[ON];
}Study_Data[N];
/*改进型bp算法用来保存每次计算的权值*/
struct {
double old_W[HN][IN];
double old_V[ON][HN];
}Old_WV[Z];
int Start_Show()
{
clrscr();
printf("\n ***********************\n");
printf(" * Welcome to
use *\n");
printf(" * this program
of *\n");
printf(" * calculating the BP *\n");
printf(" * model! *\n");
printf(" * Happy every
day! *\n");
printf(" ***********************\n");
printf("\n\nBefore starting,please read the follows
carefully:\n\n");
printf(" 1.Please ensure the Path of the '训练样本.txt'(xunlianyangben.txt)
is \ncorrect,like 'F:\BP\训练样本.txt'!\n");
printf(" 2.The calculating results will be saved in the Path of
'F:\\BP\\'!\n");
printf(" 3.The program will load 10 datas when running from
'F:\\BP\\训练样本.txt'!\n");
printf(" 4.The program of BP can study itself for no more than 30000
times.\nAnd surpassing the number,the program will be ended by
itself in\npreventing running infinitely because of
error!\n");
printf("\n\n\n");
printf("Now press any key to start...\n");
getch();
getch();
clrscr();