?? a.cpp
字號:
#include<iostream.h>
void main()
{
double p[2][3]={{-0.4,-0.5,0.6},{0.9,0,0.1}};
int t[3]={1,1,0};
int y[3]={-1,-1,-1};
int count=20;
double w[2]={0.01,0.01};
double b=0.01;
int i=0;
double e=0;
for( i=0;i<count;i++)
{
int x=i%3;
double v=b+p[0][x]*w[0]+p[1][x]*w[1];
if(v>=0)
y[x]=1;
else y[x]=0;
if((y[0]==t[0])&(y[1]==t[1])&(y[2]==t[2]))break;
/*int n=0;
for(int m=0;m<3;m++)
{
n=n+(t[m]-y[m])*(t[m]-y[m]);
}
e=n/3;
if(e=0)
break;*/
else
{
w[0]=w[0]+(t[x]-y[x])*p[0][x];
w[1]=w[1]+(t[x]-y[x])*p[1][x];
b=b+(t[x]-y[x])*b;
}
}
cout<<i<<endl;
cout<<"y="<<endl;
for(int j=0;j<3;j++)
cout<<y[j]<<" ";
cout<<endl;
cout<<"e="<<e<<endl;
//使用測試數據檢測
double q[2][3]={{0.6,0.9,-0.1},{-0.1,-0.5,0.5}};
int y1[3]={0,0,0};
double e1=0;
for(int k=0;k<3;k++)
{
double v=b+q[0][k]*w[0]+q[1][k]*w[1];
if(v>=0)
y1[k]=1;
else y1[k]=0;
}
cout<<"y1="<<endl;
for( j=0;j<3;j++)
cout<<y1[j]<<" ";
cout<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -