-
Notifications
You must be signed in to change notification settings - Fork 0
/
it_perceptron.m
42 lines (42 loc) · 1006 Bytes
/
it_perceptron.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
function opt=it_perceptron(input_vector_train,output_vector_train,input_vector_test)
input =input_vector_train;
desired_out =output_vector_train;
[numPat, numIn] = size(input);
[r, numOut]=size(desired_out);
bias = -1; coeff = 0.7; a = -2; b= 2;
weights = a + (b-a).*rand(numIn,numOut+1);
iterations = 200;
for i = 1:iterations
out = zeros(numPat,numOut);
for j = 1:1:numPat
for k = 1:1:numOut
y=bias*weights(k,numOut+1);
for L = 1:1:numIn
y = y+input(j,L)*weights(L,k);
end
out(j,k) = 1/(1+exp(-y));
delta = desired_out(j,k)-out(j,k);
for L=1:numIn
weights(L,k)=weights(L,k)+coeff*input(j,L)*delta;
end
weights(k,numOut+1)=weights(k,numOut+1)+coeff*bias*delta;
end
end
end
input1 = input_vector_test;
[numPat, numIn] = size(input1);
out1 = zeros(numPat,numOut);
for j = 1:numPat
for k = 1:numOut
y1=bias*weights(k,numOut+1);
for L = 1:numIn
y1 = y1+input1(j,L)*weights(L,k);
end
out1(j,k) = 1/(1+exp(-y1));
end
end
out2=int8(out1);
out3=int2str(out2);
out4=bin2dec(out3);
opt=char(out4');
end