% Simple script demonstrating the "curse of dimensionality"
%
% Note: Requires the PRTools package.
% Note II: PRTools5 requires a bit different syntax; please use PRTools4 to
% run this script as is.

prwaitbar off

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

n = 100;      % Number of per-class training samples ..
nTest = 1e3;  % .. and the number of corresponding samples used for testing

delta = 1;  % Class-mean separation per feature

for k=1:maxTrainingSetSize
    
    % Create two-class normally-distributed training and test data; one class shifted delta per feature
    A = dataset([randn(n,k); randn(n,k)+delta], [ones(n,1); 2*ones(n,1)]);
    A = setprior(A,0);
    T = dataset([randn(nTest,k); 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))
grid

