The following is an implementation of a simple Perceptron supplied in a blog.
input = [0 0; 0 1; 1 0; 1 1];
numIn = 4;
desired_out = [0;1;1;1];
bias = -1;
coeff = 0.7;
rand('state',sum(100*clock));
weights = -1*2.*rand(3,1);
iterations = 10;
for i = 1:iterations
out = zeros(4,1);
for j = 1:numIn
y = bias*weights(1,1)+...
input(j,1)*weights(2,1)+input(j,2)*weights(3,1);
out(j) = 1/(1+exp(-y));
delta = desired_out(j)-out(j);
weights(1,1) = weights(1,1)+coeff*bias*delta;
weights(2,1) = weights(2,1)+coeff*input(j,1)*delta;
weights(3,1) = weights(3,1)+coeff*input(j,2)*delta;
end
end
I have the following questions,
(1) which one is training data here?
(2) which one is test data here?
(3) which are the labels here?
training data is [0 0; 0 1; 1 0; 1 1] in the other view every row is one set of training data as follow
and target is
please think about desired_out this is your labels .. every row in training data(input) have a specific output(label) in binary set{0,1}(because this example for implementation of OR logic circuit.
in matlab you can use or function as below for further understanding:
Note that your code has not any training test and this code just trying to get weights and other parameters of perceptron but you can add training test to your code by just little program
so test data will be similar to below
for test this data you can use your own program by below code:
and finally:
output is
Code section:
I hope this helps and sorry for my English if it's bad