forked from aman-raza/Friends_Hack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hebbLearning.cpp
76 lines (60 loc) · 1.33 KB
/
hebbLearning.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
using namespace std;
int main()
{
int m,n;
cout<<"enter no.of features and no.of training datasets: \n";
cin>> m>>n;
int wt1[m], wt2[m];
int input[n][m];
cout<<"enter the input matrix row wise "<<endl;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>input[i][j];
}
}
int target1[n], target2[n];
cout<<" Enter the target in binary : "<<endl;
for(int i=0;i<n;i++)
{
cin>>target1[i];
}
cout<<"Enter the target in bipolar: "<<endl;
for(int i=0;i<n;i++)
{
cin>>target2[i];
}
for(int i=0;i<m;i++)
{
wt1[i]=0; //step 1: initialise all wts to 0
wt2[i]=0;
}
for(int j=0;j<n;j++) //step 2: for each training vector on target pair do steps 3 to 5
{//step 3: x_0 = 1 and xi = si
cout<<"###########j="<<j<<endl;
for(int i=0; i<m;i++)
{
//step 4: y_out = T_i
//step 5: adjust the weights as WT_new= WT_old + (x_i*y_out)
wt1[i]+= (input[j][i]*target1[j]);
cout<<"weight1 at i="<<i<<" is "<<wt1[i]<<endl;
wt2[i]+= (input[j][i]*target2[j]);
cout<<"wt2 at i="<<i<<" is "<<wt2[i]<<endl;
}
}
cout<<"************OUTPUT**************\nafter 1 epoch: binary weights: "<<endl;
for (int i = 0; i < m; ++i)
{
/* code */
cout<<wt1[i]<<" ";
}
cout<<"\nafter 1 epoch: bipolar weights: "<<endl;
for (int i = 0; i < m; ++i)
{
/* code */
cout<<wt2[i]<<" ";
}
return 0;
}