% hom3a.m
%
% file used to run the winner take all network
%
% created by:
%       Steven E. Lamberson, Jr.
%
% created on:
%       October 08, 2004

close all;
clear;
clc;

y = linspace(0,2*pi,100);
w = [1 -2/sqrt(5) -1/sqrt(5); 0 1/sqrt(5) 2/sqrt(5)];
x = [-1 0 1/sqrt(2); 0 1 1/sqrt(2)];
alphak = 0.5;

x1 = x;
rho = 0.90;

figure(1);
hold on;
h = plot(cos(y),sin(y),':k');
set(h,'LineWidth',2);
axis equal;
axis off;
for i = 1:size(x,2)
    h = plot(x(1,i),x(2,i),'sb');
    set(h,'MarkerFaceColor','b');
    phi(i) = acos([1 0]*x(:,i));
    if x(2,i) < 0
        phi(i) = phi(i) + pi;
    end
    h = text(rho*cos(phi(i)),rho*sin(phi(i)),sprintf('%d',i));
    set(h,'Color','b');
    set(h,'FontSize',12);
    h = plot(w(1,i),w(2,i),'dr');
    set(h,'MarkerFaceColor','r');
    theta(i) = acos([1 0]*w(:,i));
    if w(2,i) < 0
        theta(i) = theta(i) + pi;
    end
    h = text(rho*cos(theta(i)),rho*sin(theta(i)),sprintf('%d',i));
    set(h,'Color','r');
    set(h,'FontSize',12);
end

w1 = WTA(x1,w,alphak,20)

figure(2);
hold on;
h = plot(cos(y),sin(y),':k');
set(h,'LineWidth',2);
axis equal;
axis off;
for i = 1:size(x,2)
    h = plot(x(1,i),x(2,i),'sb');
    set(h,'MarkerFaceColor','b');
    phi(i) = acos([1 0]*x(:,i));
    if x(2,i) < 0
        phi(i) = phi(i) + pi;
    end
    h = text(rho*cos(phi(i)),rho*sin(phi(i)),sprintf('%d',i));
    set(h,'Color','b');
    set(h,'FontSize',12);
end
rho = 1.1
for i = 1:size(x,2)
    h = plot(w1(1,i),w1(2,i),'dr');
    set(h,'MarkerFaceColor','r');
    theta1(i) = acos([1 0]*w1(:,i));
    if w1(2,i) < 0
        theta1(i) = theta1(i) + pi;
    end
    h = text(rho*cos(theta1(i)),rho*sin(theta1(i)),sprintf('%d',i));
    set(h,'Color','r');
    set(h,'FontSize',12);
end