Ejemplo n.º 1
0
int main(){
	BpNet bp;
	int times=0;
	bp.init();
	while (bp.error>Minerror)
	{
		bp.e=0.0;
		times++;
		bp.train(XX,YY);
		//bp.error--;
		if (times>MAXNUM)//如果训练次数超过一定的范围则停止
			break;
		cout<<"times="<<times<<"errors="<<bp.error<<endl;
	}
	cout<<"training complete..."<<endl;
	//double m[innode]={0.203,-1.375,0.212};
	double m[innode]={0.0124,0.0089,0.013};
	double *r=bp.recongnize(m);
	//for (int i =0;i<outnode;i++)
	//	cout<<*r++<<endl;
	for (int i =0;i<outnode;i++)
		cout<<bp.result[i]<<endl;
	system("pause");
	return 0;
}
Ejemplo n.º 2
0
int main()
{
    BpNet bp;
    bp.init();
    int times=0;
    while(bp.error>0.0001)
    {
        bp.e=0.0;
        times++;
        bp.train(X,Y);
        cout<<"Times="<<times<<" error="<<bp.error<<endl;
    }
    cout<<"trainning complete..."<<endl;
    double m[innode]={1,1,1};
    double *r=bp.recognize(m);
    for(int i=0;i<outnode;++i)
       cout<<bp.result[i]<<" ";
    double cha[trainsample][outnode];
    double mi=100;
    double index;
    for(int i=0;i<trainsample;i++)
    {
        for(int j=0;j<outnode;j++)
        {
            
            cha[i][j]=(double)(fabs(Y[i][j]-bp.result[j]));
            if(cha[i][j]<mi)
            {
                mi=cha[i][j];
                index=i;
            }
        }
    }
    for(int i=0;i<innode;++i)
       cout<<m[i];
    cout<<" is "<<index<<endl;
    cout<<endl;
    return 0;
}