% Simple script demonstrating "curse of dimensionality".
%
% Note: Requires the PRTools package; downloadable from http://www.37steps.com/software/

prwaitbar off

maxTrainingSetSize = 99;
errs = zeros(maxTrainingSetSize,1);

n = 100;
nTest = 1e3;

delta = 0.5;

for k=1:maxTrainingSetSize
    
    % Create training and test data
    A = dataset([randn(n,k)-delta; randn(n,k)+delta], [ones(n,1); 2*ones(n,1)]);  % Alternatively: A = gauss([n n], [ -delta*ones(1,k); delta*ones(1,k) ], eye(k));
    A = setprior(A,0);
    T = dataset([randn(nTest,k)-delta; randn(nTest,k)+delta], [ones(nTest,1); 2*ones(nTest,1)]);
    T = setprior(T,0);

    % Build a quadratic classifier and compute error rate
    W = qdc(A);
    errs(k) = testc(T*W);

end

% Now, plot the resulting classification error-rates
plot(errs);
xlabel('# dimensions')
ylabel('error rate')
title(sprintf(' Quadratic classifier, training set size: %d samples', n))


