% experiment 3: show the distribution of weights

iterationNum = 20;

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

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

subplot(2,3,2);
hist(weight(1,:), 10);
title('Weight distribution after 1 iteration');
xlabel('weight value');
ylabel('instance number');

subplot(2,3,3);
hist(weight(2,:), 10);
title('Weight distribution after 2 iterations');
xlabel('weight value');
ylabel('instance number');

subplot(2,3,4);
hist(weight(5,:), 10);
title('Weight distribution after 5 iteration');
xlabel('weight value');
ylabel('instance number');

subplot(2,3,5);
hist(weight(10,:), 10);
title('Weight distribution after 10 iteration');
xlabel('weight value');
ylabel('instance number');

subplot(2,3,6);
hist(weight(20,:), 10);
title('Weight distribution after 20 iteration');
xlabel('weight value');
ylabel('instance number');

