% exp on noise data 

%1nn
ite = 5;
noise = 0:0.1:1;
nnerr = zeros(1, size(noise,2));
adaerr = zeros(1, size(noise,2));

for i=1:size(noise,2)
    [noise_fea] = addnoise(nfea_tr, noise(i), 6);
    [I, hypo] = knn(noise_fea, lab_tr, nfea_ts, lab_ts);
    nnerr(i) = sum(I)/size(nfea_ts, 2);
    [trerr, adaerr(i)] = adaboostM1('nearest',noise_fea, lab_tr, nfea_ts, lab_ts, ite, 6);
end

% draw
figure;
plot(noise, nnerr, '-ob', noise, adaerr, '-xr');
axis([0 1 0 1]);
title('AdaBoost vs. 1NN under noisy data');
xlabel('noise percentage');
ylabel('error rate');
legend('1NN testing error', 'adaboost testing error', 4);

%nb
ite = 5;
noise = 0:0.1:1;
nnerr = zeros(1, size(noise,2));
adaerr = zeros(1, size(noise,2));

for i=1:size(noise,2)
    [noise_fea] = addnoise(nfea_tr, noise(i), 6);
    [mean, var, pri] = nb_tr(noise_fea, lab_tr, 6);
    [I, hypo] = nb_ts(nfea_ts, lab_ts, mean, var, pri, 6);
    nnerr(i) = sum(I)/size(nfea_ts, 2);
    [trerr, adaerr(i)] = adaboostM1('naivebayes',noise_fea, lab_tr, nfea_ts, lab_ts, ite, 6);
end

% draw
figure;
plot(noise, nnerr, '-ob', noise, adaerr, '-xr');
axis([0 1 0 1]);
title('AdaBoost vs. NaiveBayes under noisy data');
xlabel('noise percentage');
ylabel('error rate');
legend('NaiveBayes testing error', 'adaboost testing error',4);

%lda
ite = 5;
noise = 0:0.1:1;
nnerr = zeros(1, size(noise,2));
adaerr = zeros(1, size(noise,2));

for i=1:size(noise,2)
    [noise_fea] = addnoise(nfea_tr, noise(i), 6);
    [w, w0] = lda_tr(noise_fea, lab_tr, 6);
    [I, hypo] = lda_ts(nfea_ts, lab_ts, w, w0, 6);
    nnerr(i) = sum(I)/size(nfea_ts, 2);
    [trerr, adaerr(i)] = adaboostM1('lda',noise_fea, lab_tr, nfea_ts, lab_ts, ite, 6);
end

% draw
figure;
plot(noise, nnerr, '-ob', noise, adaerr, '-xr');
axis([0 1 0 1]);
title('AdaBoost vs. LDA under noisy data');
xlabel('noise percentage');
ylabel('error rate');
legend('LDA testing error', 'adaboost testing error',4);
