Berdakh Abibullaev Guest
|
Posted: Mon Oct 27, 2008 1:12 am Post subject: NN training using simple perceotron rule |
|
|
Hello ,
I am learning Neural Networks and very new in this area. Thus, I want
to train one neuron perceptron with simple perceptron rule. There are
four inputs p(1, ,p(2, ,p(3, ,p(4, and two target outputs as
t[1,1,0,0] . I am using hardlim transfer function. Can you please
check my matlab code below and correct my mistakes.
Thanks!
---------------------------------------
clear all; close all;
% set input vectors
p = [-1,1; -1,-1; 0,0; 1,0];
% define target values
t = [1,1,0,0];
% set initial weights and bias
w = [0,0]; b = 0;
ii = 0; jj = 0; nn = 1;
aa = rand(1,4);
% start training the network
while jj == 0
fprintf('\nProcessing...\n')
if nn > 4
nn = 1;
end
pp = nn;
n = w*p(nn,1:2)' + b;
% here we threshold using transfer function in our case a =
harlim(n)
if n >= 0
a = 1;
elseif n < 0
a = 0;
end
% now calculate the error e = (t-a)
if pp == 1
e = t(1,1)-a;
aa(1,pp) = e;
elseif pp ==2
e = t(1,2)-a;
aa(1,pp) = e;
elseif pp == 3
e = t(1,3)-a;
aa(1,pp) = e;
elseif pp == 4
e = t(1,4)-a;
aa(1,pp) = e;
end
% following the step we update weight and bias
w = w+e*p(nn,1:2)+b;
b = b + e;
if aa(1, == t(1,
disp('Completed')
jj = 1;
end
nn = nn + 1;
end |
|