function [X, y] = toydata(p, n, verbose)
% X = toydata(p, verbose)
% 
% generates n toy data points of p clusters

if nargin < 1
	p = 2;
end
if nargin < 2
	n = 200;
end
if nargin < 3
	verbose = 0;
end

X = randn(n, 2);
y = zeros(n, 1);

mu = rand(p, 2)*20 - 10;
sigma = rand(p, 2) + 0.1;

if verbose
    figure;
    hold all
end

k = [0 round((sort(rand(1, p-1))*(p-1) + (1:p-1))/(2*p)*n) n];
i = randperm(n);
for j = 1:p
    z = i(k(j)+1:k(j+1));
    X(z,1) = X(z,1)*sigma(j,1) + mu(j,1);
    X(z,2) = X(z,2)*sigma(j,2) + mu(j,2);
    y(z)   = j;
    if verbose
        plot(X(z,1), X(z,2), '+');
    end
end
