0

I want to write my own perceptron network with matlab. I tried to run this code

input = [0 0; 0 1; 1 0; 1 1];
 bias = [1 1 1];

coeff = 0.7;
iterations = 10000;

rand('state',sum(100*clock));
weights = -1 +2.*rand(3,3);

for i = 1:iterations
out = zeros(4,1);
numIn = length (input(:,1));
for j = 1:numIn

  H1 = bias(1,1)*weights(1,1)      
      + input(j,1)*weights(1,2)
      + input(j,2)*weights(1,3);

  for k = 1:3
     if k == 1 
        weights(1,k) = weights(1,k) + coeff*bias(1,1)*delta2_1;
        weights(2,k) = weights(2,k) + coeff*bias(1,2)*delta2_2;
        weights(3,k) = weights(3,k) + coeff*bias(1,3)*delta3_1;
     else 
        weights(1,k) = weights(1,k) + coeff*input(j,1)*delta2_1;
        weights(2,k) = weights(2,k) + coeff*input(j,2)*delta2_2;
        weights(3,k) = weights(3,k) + coeff*x2(k-1)*delta3_1;
     end
  end
 end   
end

but it gives me wrong results (0.499524196804705,0.477684866785518,0.500475803195295,0.522315133214482). Could you help me to find my mistake?

neir45
  • 33
  • 2
  • 7
  • Where does this deltas come from? How are you updating the weights whitout calculating the error and backpropagating it? – Vinicius Zaramella Apr 07 '16 at 13:11
  • This code can't run on its own. What is `x2` defined as? A lot of things are missing for this to work. This also doesn't look like you're training properly... that main set of `for` loops doesn't look like forward nor backward propagation. – rayryeng Apr 07 '16 at 13:34

0 Answers0