-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelta_rule.m
79 lines (59 loc) · 1.26 KB
/
delta_rule.m
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
77
78
clearvars
x1 = [0 0 1 1];
x2 = [0 1 0 1];
p = [x1;x2];
x = p';
w = rand(2,1)'
%w = [0.1 0.0]
disp('Initial_weight:')
%d = [0 0 0 0]
%d = [0 0 0 1]
%d = [0 0 1 0]
%d = [0 0 1 1]
%d = [0 1 0 0]
%d = [0 1 0 1]
%d = [0 1 1 0] Failed!
%d = [0 1 1 1]
d = [0 1 0 0]
%th = 0.5;
th = 0.1;
eta = 0.01;
d1 = 1;
d2 = -1;
update = 1;
iterate = 0;
while update == 1
iterate = iterate+1
s1 = w(1)*x1;
s2 = w(2)*x2 ;
s3 = s1+ s2;
for j = 1:4
if s3(j) <= th
y(j) = 0 ;
else
y(j) = 1 ;
end
end
for i = 1:4
Actual_Output_Set = y
Desired_Output = d
%-------------Adapt Weight------------------
if (y(i) == d(i))
Current_Input = x(i,:)
w = w+0
elseif ( y(i) == 0 && d(i) == 1 )
Current_Input = x(i,:)
w = w + d1*eta*x(i,:)
elseif ( y(i) == 1 && d(i) == 0 )
Current_Input = x(i,:)
w = w + d2*eta*x(i,:)
%z = w
end
%-----------------------------------------
end
if y == d
update = 0;
else
update = 1;
end
end % end of while