Je dois implémenter un perceptron monocouche en utilisant Matlab. Le problème auquel je suis confronté est que quand j'ai couru mon programme il m'a donné la sortie pour chaque entrée (il montre des résultats 4 fois), mais je veux revenir au premier index de la matrice, après quand il a atteint le quatrième, et je ne peux pas savoir comment je retourne au premier indice de la matrice.comment revenir au premier index des matrices
Je veux former mon programme afin qu'il produise le même résultat que dans b
en itérant la matrice dans chaque boucle.
Ceci est mon code actuel:
a = [ 1 1
1 -1
-1 1
-1 -1 ];
b = [1
-1
-1
-1];
disp(a);
disp(b);
x = a(:,1);
disp(x);
y = a(:,2);
disp(y)
learningrate = 0.1;
maxiteration = 10;
weight(1)=0.1;
weight(2)=0.1;
weight(3)=0.1;
count = length(x);
for p = 1:count
s = (x(p) * weight(1))+ (y(p) * weight(2))+ weight(3);
if s >= 0
result = 1;
if result ~= b(p)
weight(1) = weight(1)+learningrate*(b(p)-result)*x(p);
weight(2) = weight(2)+learningrate*(b(p)-result)*y(p);
weight(3) = weight(3)+learningrate*(b(p)-result);
disp(result);
disp(x(p));
disp(y(p));
disp(weight(1));
disp(weight(2));
disp(weight(3));
end
else
if s <= 0
result = -1;
disp(result);
if result ~= b(p)
weight(1)=weight(1)+learningrate*(b(p)-result)*x(p);
weight(2)=weight(2)+learningrate*(b(p)-result)*y(p);
weight(3)=weight(3)+learningrate*(b(p)-result);
disp(x(p));
disp(y(p));
disp(weight(1));
disp(weight(2));
disp(weight(3));
end
end
end
end
Jetez un coup d'œil à http://stackoverflow.com/questions/3455660/matlab-single-layer-neural-network – zellus