% exp on original data

iterationNum = 5;

%1NN
[I, hypo] = knn(nfea_tr, lab_tr, nfea_tr, lab_tr);
nntrerr = sum(I)/size(nfea_tr, 2);
nntrerr = repmat(nntrerr, 1, iterationNum);
[I, hypo] = knn(nfea_tr, lab_tr, nfea_ts, lab_ts);
nntserr = sum(I)/size(nfea_ts, 2);
nntserr = repmat(nntserr, 1, iterationNum);

nnadatrerr = zeros(1, iterationNum);
nnadatserr = zeros(1, iterationNum);
for t = 1:iterationNum
    [nnadatrerr(t), nnadatserr(t)] = adaboostM1('nearest', nfea_tr, lab_tr, nfea_ts, lab_ts, t, 6);
end

figure;
x = 1:iterationNum;
plot(x, nnadatrerr, '-ob', x, nnadatserr, '-xr', x, nntrerr, ':k', x, nntserr, '-.k');
axis([1 iterationNum -0.05 0.6]);
title('AdaBoost with 1NN');
xlabel('iteration number');
ylabel('error rate');
legend('adaboost train error', 'adaboost test error', '1NN train err', '1NN test error');

%nb
[mean, var, pri] = nb_tr(nfea_tr, lab_tr, 6);
[I, hypo] = nb_ts(nfea_tr, lab_tr, mean, var, pri, 6);
nntrerr = sum(I)/size(nfea_tr, 2);
nntrerr = repmat(nntrerr, 1, iterationNum);
[I, hypo] = nb_ts(nfea_ts, lab_ts, mean, var, pri, 6);
nntserr = sum(I)/size(nfea_ts, 2);
nntserr = repmat(nntserr, 1, iterationNum);

nnadatrerr = zeros(1, iterationNum);
nnadatserr = zeros(1, iterationNum);
for t = 1:iterationNum
    [nnadatrerr(t), nnadatserr(t)] = adaboostM1('naivebayes', nfea_tr, lab_tr, nfea_ts, lab_ts, t, 6);
end

figure;
x = 1:iterationNum;
plot(x, nnadatrerr, '-ob', x, nnadatserr, '-xr', x, nntrerr, ':k', x, nntserr, '-.k');
axis([1 iterationNum -0.05 0.6]);
title('AdaBoost with Naive Bayes');
xlabel('iteration number');
ylabel('error rate');
legend('adaboost train error', 'adaboost test error', 'NaiveBayes train err', 'NaiveBayes test error');

%lda
[w, w0] = lda_tr(nfea_tr, lab_tr, 6);
[I, hypo] = lda_ts(nfea_tr, lab_tr, w, w0, 6);
nntrerr = sum(I)/size(nfea_tr, 2);
nntrerr = repmat(nntrerr, 1, iterationNum);
[I, hypo] = lda_ts(nfea_ts, lab_ts, w, w0, 6);
nntserr = sum(I)/size(nfea_ts, 2);
nntserr = repmat(nntserr, 1, iterationNum);

nnadatrerr = zeros(1, iterationNum);
nnadatserr = zeros(1, iterationNum);
for t = 1:iterationNum
    [nnadatrerr(t), nnadatserr(t)] = adaboostM1('lda', nfea_tr, lab_tr, nfea_ts, lab_ts, t, 6);
end

figure;
x = 1:iterationNum;
plot(x, nnadatrerr, '-ob', x, nnadatserr, '-xr', x, nntrerr, ':k', x, nntserr, '-.k');
axis([1 iterationNum -0.05 0.6]);
title('AdaBoost with LDA');
xlabel('iteration number');
ylabel('error rate');
legend('adaboost train error', 'adaboost test error', 'LDA train err', 'LDA test error');
