Im not sure with the pereptron code i made

i created a code based on Perceptron Training Algorithm and i need a program to run any set of target and and set of input. For example it will work with a 4x2 input and 4x1 target, and it will also solve nxn input and nxn target. now my problem is if my perceptron training code is correct can anyone point out my mistakes?
==============================================================================
%Perceptron Training Single Layer
%Initialize the variables
x =[0 0; 0 1; 1 0; 1 1]; %Input
t =[0 0; 0 0; 0 0; 0 1]; %Target Output
n = nrows(x); %Number of rows for input
g = nrows(t); %Number of rows for target
p = ncols(x); %Number or columns for input
a = ncols(t); %Number of columns for target
b = -1; %Bias
c = 0.1; %Learning rate
j = ncols(x)*ncols(t); %Number of weights
u = ncols(t); %Number of Neurons
w = unifrnd(-1,1,[j,a]); %Weights
epoch = 100; %Training Time
[rows,columns] = size(x);
%Perceptron Training
for i = 1:epoch
for s = 1:rows;
for o = 1:u
y(u)=( ( (x(s,p) * w(j,a)) + (x(s,p) * w(j,a)) ) );
end
l = sum(y);% Summation of y
if(l~=t(s,p))
e = t(s,p)-l;
w(j,a) = w(j,a) + (c*e*x(s,p));
w(j,a) = w(j,a) + (c*e*x(s,p));
else
if(l>t(s,p))
e = t(s,p)+l;
w(j,a) = w(j,a) - (c*e*x(s,1));
w(j,a) = w(j,a) - (c*e*x(s,2));
end
end
end
end
%Print output
fprintf('Number of Weights:\n');
disp(j);
fprintf('Number of Neurons:\n');
disp(u);
fprintf('Bias:\n');
disp(b)
fprintf('Weights:\n');
disp(w); ==============================================================================
function [nr] = nrows(A)
% NROWS Number of rows in an array.
%
% [nr] = NROWS(A) returns number of rows in A.
nr = size(A, 1);
===============================================================================
function [nc] = ncols(A)
% NCOLS Number of columns in an array.
%
% [nr] = NCOLS(A) returns number of columns in A.
nc = size(A, 2);

Tags

Asked:

on 21 Aug 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!