% CmpLrn.m % A.P. Paplinski 27 August 2004 % A simple competitive learning figure(1), clf reset CmpInit W = Win ; Whist = zeros( N, m, p); % to store all weights Whist(1,:,:) = W ; wnm = ones(m,1) ; eta = 0.1 ; % learning gain % deta = 1-1/N ; % learning gain decaying factor for n = 1:N xn = X(:,n)' ; % the current vector is compared with all weight vectors xmw = xn(wnm,:)-W ; [win kwin] = min(sum((xmw.^2),2)) ; % the weights of the winning neurons are update W(kwin,:) = W(kwin,:) + eta*xmw(kwin,:) ; Whist(n,:,:) = W ; % eta = eta*deta ; % end plot(X(1,:),X(2,:),'g.',clst(1,:),clst(2,:),'ro', ... Win(:,1),Win(:,2),'b^' , ... Whist(1:n,:,1), Whist(1:n,:,2), 'b', W(:,1),W(:,2) , 'r*'), title(['Simple Competitive Learning n = ', num2str(n)]) xlabel('x_1'), ylabel('x_2'), grid on % pause(1) end % myfigA(1, 10,9) plot(X(1,:),X(2,:),'g.',clst(1,:),clst(2,:),'ro', ... Win(:,1),Win(:,2),'b^' , ... Whist(1:n,:,1), Whist(1:n,:,2), 'b', W(:,1),W(:,2) , 'r*'), grid title(['Simple Competitive Learning n = ', num2str(n)]) xlabel('x_1'), ylabel('x_2') % print -f1 -depsc2 CmpLrn