if 1
m = 100;
rho = [.3 .7];
mu = [0 0; 5 5];
Psi = cat(3,[1 0; 0 1],[3 -2; -2 3]);
y = zeros(m,1);
x = zeros(m,2);
for i=1:m
  y(i) = sum(rand(1)>cumsum(rho))+1; % pick a cluster
  fprintf(1,'Cluster %d.\n',y(i));
  x(i,:) = mvnrnd(mu(y(i),:),Psi(:,:,y(i)));
  plot(x(1:i,1),x(1:i,2),'.','markersize',10);
  axis([-2 10 -2 10]);
  pause
end
col = colormap;
col = col(ceil([.5 1.5]/2*length(col)),:);
hold on
for c=1:2
  plotellipse(mu(c,:),Psi(:,:,c),'color',col(c,:),'linewidth',3);
end
hold off
end


if 0
mu = [0 0; 1 1];
Psi = [.3 .3; .3 .3].^2;

n = 2;
m = 200;
c = 1+(rand(1,m)>.5);
X = mu(c,:) + randn(m,n).*sqrt(Psi(c,:));
plot(X(:,1),X(:,2),'.','markersize',10);
% save 2dmog1.dat X -ascii
end

if 0
mu = [0 0; 2 1];
Psi = [.2 .2; 1 .2].^2;

n = 2;
m = 400;
c = 1+(rand(1,m)>.3);
X = mu(c,:) + randn(m,n).*sqrt(Psi(c,:));
plot(X(:,1),X(:,2),'.');
% save 2dmog2.dat X -ascii
end

if 0
mu = [0 0; 1 1];
Psi = [.2 .2; .4 .4].^2;

n = 2;
m = 100;
c = 1+(rand(1,m)>.5);
X = mu(c,:) + randn(m,n).*sqrt(Psi(c,:));
plot(X(:,1),X(:,2),'.');
% save 2dmog3.dat X -ascii
end

