📄 bptest.cpp
字号:
#include "bpnet.hpp"
//#include "keyread.hpp"
//#include <bios.h>
#include <iomanip.h>
#include <math.h>
#include <process.h>
void main()
{
int lrncom(const long,BPNet&,const Matrix&,double **,double **,const int);
double o[4], *ii[5],*oo[5];
double f(double);
double f1(double);
double s[5][5] = { {0,.671,1,.94,1},
{.638,.671,.382,.95,.75},
{1,0,0,.98,.444},
{1,1,.619,.8,.222} };
double so[5][4] = { {1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1} };
int k[]={5,11,4};
//BPNet b(3,k,"tt");
BPNet b("tt");
int smp;
b.SetLrnCom(lrncom);
b.SetP(20);
/* b.SetStepLrn(5.7);
b.SetRushLrn(3.9);*/
b.SetLrnNum(10000);
b.SetErrAllow(0.001);
// b.SetNdFun(f);
// b.SetDifFun(f1);
if((b.GetErr() & 0x4)==NT_INITERR)
{
cout<<"Network setup failure!";
exit(1);
}
cout<<"\n Do you want to learning(y/n)?";
char an;
cin>>an;
if(an=='y' || an=='Y')
{
ii[0]=s[0]; ii[1]=s[1]; ii[2]=s[2]; ii[3]=s[3]; ii[4]=s[4];
oo[0]=so[0]; oo[1]=so[1]; oo[2]=so[2]; oo[3]=so[3]; oo[4]=so[4];
cout<<"\nInput sample number: ";
cin>>smp;
cout<<"\n\t\tPress ESC to exit, Waiting......\n\n";
cout<<"\nLearn Number="<<b.Learn(ii,oo,smp);
}
cout<<"\n Do you want to calculate(y/n)?";
cin>>an;
while(an=='y' || an=='Y')
{
cout<<"\nInput the input of network:\n";
for(int i=0; i<5; i++) { cout<<"input no. "<<i<<": "; cin>>s[0][i]; }
b.Run(s[0],o);
cout<<"\nThe result: ";
for(i=0; i<4; i++) cout<<o[i]<<" ";
cout<<"\n Do you want to calculate another(y/n)?";
cin>>an;
}
}
//#pragma argsused
int lrncom(const long count,BPNet& b,const Matrix& m,
double **in,double** out,const int sn)
{
double o[4];
cout<<"\r count="<<count<<"\tresult:";
for(int i=0; i<sn; i++)
{
b.Run((double*)in[i],o);
// cout<<"\n sample "<<i+1<<": ";
// for(int io=0; io<4; io++)
cout<<setw(13)<<setiosflags(ios::left)<<o[i];
}
cout<<"\r";
// if(bioskey(1))
// if(keyvl()==ESC) return 1;
return 0;
}
//#pragma argsused
double f(double x)
{
return 1./(1+exp(-x/2));
// return x;
}
//#pragma argsused
double f1(double x)
{
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -