
pattern = 'eye';
%pattern = 'checker';



% generate some data
if (strcmp(pattern,'checker'))
  n = 100;
  alpha = 0.4;
  X = [ 
      alpha*randn(n,1)-1 alpha*randn(n,1)+1;
      alpha*randn(n,1)+0 alpha*randn(n,1)+1;
      alpha*randn(n,1)+1 alpha*randn(n,1)+1;
      alpha*randn(n,1)-1 alpha*randn(n,1)+0;
      alpha*randn(n,1)+0 alpha*randn(n,1)+0;
      alpha*randn(n,1)+1 alpha*randn(n,1)+0;
      alpha*randn(n,1)-1 alpha*randn(n,1)-1;
      alpha*randn(n,1)+0 alpha*randn(n,1)-1;
      alpha*randn(n,1)+1 alpha*randn(n,1)-1;
      ];
  X = [X ones(9*n,1)];
  X = (X + 1.5) / 3;

  a = [ones(n,1) zeros(n,1) zeros(n,1)];
  b = [zeros(n,1) ones(n,1) zeros(n,1)];
  c = [zeros(n,1) zeros(n,1) ones(n,1)];
  Yvec = [a;b;c;b;c;a;c;a;b];
  %Yvec = [a;b;a;b;c;b;c;a;c];
end

if (strcmp(pattern,'eye'))

  alpha = 0.25;
  xx1 = 0.0625*randn(1,200);
  yy1 = 0.0625*randn(1,200);
  xx2 = 0.5*randn(1,4000);
  yy2 = 0.5*randn(1,4000);
  xx3 = 2.5*randn(1,20000);
  yy3 = 2.5*randn(1,20000);
  ind1 = find(xx1.^2 + yy1.^2 < 0.0625);
  ind2 = find( (xx2.^2 + yy2.^2 > 0.5) & (xx2.^2 + yy2.^2 < 0.875));
  ind3 = find( (xx3.^2 + yy3.^2 > 1.875) & (xx3.^2 + yy3.^2 < 3.75));

  xx = [xx1(ind1)+0.25 xx2(ind2) xx3(ind3)+0.25];
  yy = [yy1(ind1) yy2(ind2) yy3(ind3)];
  X = [xx(:) yy(:)] + alpha*randn(length(xx(:)),2);
  X = [X ones(size(X,1),1)];
  
  X = (X + 2) / 4;

  a = [ones(length(ind1),1) zeros(length(ind1),1) zeros(length(ind1),1)];
  b = [zeros(length(ind2),1) ones(length(ind2),1) zeros(length(ind2),1)];
  c = [zeros(length(ind3),1) zeros(length(ind3),1) ones(length(ind3),1)];
  Yvec = [a;b;c];
end


[v,Y] = max(Yvec,[],2);

kolor = ['r' 'b' 'k' 'g'];

figure(1); clf;
hold on;
for i = 4:-1:1
  ind = find(Y == i);
  plot(X(ind,1),X(ind,2),[kolor(i) '.']);
end;
axis([0 1 0 1]); axis square;



nexperts = 9;
hme = hmeCreate(1,nexperts,3,3);

%expert = hmeCreateExpert(3,3);
%mix2 = hmeCreateMixture({expert expert},3);
%mix3 = hmeCreateMixture({expert expert expert},3);
%hme = hmeCreateMixture({mix2 mix3},3);

hme_fit = hmeFit(hme,X',Yvec',2);


