% WTA.m
%
% winner take all network algorithm
%
% created by:
%       Steven E. Lamberson, Jr.
%
% created on:
%       October 08, 2004
function w = WTA(x,w,alphak,maxiter);

N = size(x,2);
p = size(w,2);

count = 0;
while(true)
    count = count + 1;
	for i = 1:N
        for j = 1:p
            d(j) = w(:,j)'*x(:,i);
        end
        [md,mi] = max(d);
        w(:,mi) = w(:,mi) + alphak*(x(:,i) - w(:,mi));
        for j = 1:p
            w(:,j) = w(:,j)/norm(w(:,j));
        end
	end
    if count >= maxiter
        break;
    end
end