It is a prog about linear vector quantisation neural network. while updating weight when negative value comes as a result it is showing an error.we can make those negative values to zero and can proceed iteratrations. iam umable to do it.plz help me.
Afficher commentaires plus anciens
clc;
clear all;
st=[1 2 2 1 2];
alpha=0.6;
w=[0.2 0.8; 0.6 0.4; 0.5 0.7; 0.9 0.3];
disp('initial weight matrix');
disp(w);
x=[1 1 0 0; 0 0 0 1; 1 0 0 0; 0 0 1 1];
disp(x);
t=[st(2);st(3);st(4);st(5)];
e=1;
while (e<=3)
i=1;
j=1;
k=1;
disp('epoch=');
e
while(i<=4)
for j=1:2
temp=0;
for k=1:4
temp=temp+(w(k,j)-x(i,k))^2;
end
D(j)=temp;
end
if (D(1)<D(2))
J=1;
else
J=2;
end
disp('The winning unit is');
J
disp('weight updation');
if J==t(i)
w(:,J)=w(:,J)+alpha*(x(i,:)'-w(:,J));
else
w(:,J)=w(:,J)-alpha*(x(i,:)'-w(:,J));
end
w
i=i+1
end
temp=alpha(e);
e=e+1;
alpha(e)=0.5*temp;
disp('first epoch completed');
disp('learning rate updated for second epoch');
alpha(e)
end
1 commentaire
Walter Roberson
le 4 Déc 2013
Learn to use the debugger to figure out where the negative value is coming from.
After one loop iteration your alpha becomes a vector, and then your line
w(:,J)=w(:,J)+alpha*(x(i,:)'-w(:,J))
starts involving matrix multiplication where the "*" is. Are you sure that is what you want, not element-by-element multiplication, the .* operator ?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Deep Learning Code Generation Fundamentals dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!