-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ6.cpp
59 lines (50 loc) · 1.15 KB
/
Q6.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
using namespace std;
int main()
{
int x[4][3],t[4][1],z[4][3],i,j,p;
float alpha,yin[4],e[4],dw[4][3],w[5][3],zin[4][2];
cout<<"Enter the learning rate(0-1):";
cin>>alpha;
cout<<"\n";
for(i=0;i<=2;i++)
{
w[0][i]=0.1;
}
for(p=1;p<=4;p++)
{
x[p][2]=1;
yin[p]=0;
}
for(p=1;p<=4;p++)
{
cout<<"Enter the input Pattern number "<<p<<" : \n";
for(i=0;i<=1;i++)
{
cout<<"x"<<i+1<<":";
cin>>x[p][i];
}
cout<<"Enter the corresponding target \n";
cin>>t[p][1];
yin[p]=x[p][0]*w[p-1][0]+x[p][1]*w[p-1][1]+w[p-1][2];
for(i=0;i<=1;i++)
{
dw[p][i]=alpha*(t[p][1]-yin[p])*x[p][i];
w[p][i]=w[p-1][i]+dw[p][i];
}
dw[p][2]=alpha*(t[p][1]-yin[p]);
w[p][2]=w[p-1][2]+dw[p][2];
e[p]=(t[p][1]-yin[p])*(t[p][1]-yin[p]);
}
for(p=1;p<=4;p++)
{
cout<<e[p];
// cout<<yin[p];
for(i=0;i<=2;i++)
{
// cout<<w[p][i]<<" ";
}
cout<<"\n";
}
return 0;
}