% DecBoundData   decision boundaries experiments
%                Statistical data creation
%


test.N = 100;

%%%
% Statistical data generation
%%%
data(1).corrcoef = 0.2;
data(1).sigmax	 = 1;
data(1).sigmay	 = 0.8;
data(1).mean	 = [3,3];
data(1).N		 = 2*test.N;
data(1).color	 = 'b';

data(2).corrcoef = 0.4;
data(2).sigmax	 = 1.1;
data(2).sigmay	 = 0.7;
data(2).mean	 = [4.5,5.5];
data(2).N		 = test.N;
data(2).color	 = 'r';

for i = 1:2,
  data(i).C = [data(i).sigmax^2, data(i).corrcoef*data(i).sigmax*data(i).sigmay; data(i).corrcoef*data(i).sigmax*data(i).sigmay, data(i).sigmay^2];
  X  = randn(data(i).N,2);
  Cx = cov(X);
  T  = inv(Cx^0.5)*data(i).C^0.5;
  X	 = X*T;
  Xmean     = mean(X);
  Drift		= repmat(Xmean-data(i).mean,data(i).N,1);
  data(i).X = X-Drift;
end

if 0
  for i =1:2,
	mean(data(i).X)
	cov(data(i).X)
  end
end


figure(1)
clf
hold on
for i = 1:2,
  plot(data(i).X(:,1),data(i).X(:,2),sprintf('%s+',data(i).color));
end

%%%
% save training and test set
%%%

for i=1:2,
  trset(i).X = data(i).X(1:data(i).N/2,:);
end
testset = [data(1).X(data(1).N/2+1:data(1).N,:); data(2).X(data(2).N/2+1:data(2).N,:)];
clasidx = [ones(size(data(1).N/2+1:data(1).N)),2*ones(size(data(2).N/2+1:data(2).N))]';
newidx	= randperm(size(clasidx,1));

testset = testset(newidx,:);
clasidx = clasidx(newidx);

save data trset testset
save clasidx clasidx