% Authors: Hamidreza Sharifi 880849289
% Hosein Paknia 880849283
input = load('2d-2c-norm.dat');
[m,n] = size(input);
% # of output cluster
output_node_no = 2;
% generate weight matrix
w = rand(n,output_node_no);
r = 0;
% learning rate
rate=0.6;
d=[];
s=0;
epoch = 100;
for e=1:epoch
for t=1:m
in = input(t,:);
for k=1:output_node_no
temp = 0;
s=0;
for i=1:n
temp = w(i,k)-in(1,i);
s = s + temp*temp;
end
d(1,k)= s;
end
m = min(d);
for i=1:output_node_no
if (m == d(1,i))
index = i;
break;
end
end
% update weight matrix
for i=1:n
w(i,index) = w(i,index) + rate*(in(1,i)-w(i,index)) ;
end
end
rate = rate * 0.5;
w = w;
input = input;
[m,n] = size(input);
end
disp('Final Weight Matrix is:');
disp(w);