RealAda Classifier Demo 2

Graphical representation of boosting iterations using Decision stumps

Contents

Create synthetic data

numPoints = 300;
r1 = 10;
r2 = 5;
noiseRatio = 0.3;

nc1x1 =  r1 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
nc1x2 =  r1 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);

nc2x1 =  r2 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
nc2x2 =  r2 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);


angs1 = 2*pi*rand(numPoints/2, 1);
angs2 = 2*pi*rand(numPoints/2, 1);

x1 = [r1 * cos(angs1) +  nc1x1; r2 * cos(angs2) +  nc2x1];
x2 = [r1 * sin(angs1) +  nc1x2; r2 * sin(angs2) +  nc2x2];
x = [x1 x2];
y = [ones(numPoints/2,1) ; 2*ones(numPoints/2,1)];
c1 = y == 1;
c2 = y == 2;

figure(1);
clf;
hold on;
scatter(x1(c1), x2(c1),'b','o' ,'markerfacecolor','blue');
scatter(x1(c2), x2(c2),'b','+','markerfacecolor','blue');
title('Original');

numClasses = 2;

Run RealAdaBoost on Data

hFig = figure(2);
clf;
set(hFig, 'Position', [100 100 900 900])

stump = BestDecisionStumpClassifier(numClasses);
radacl = RealAdaBooster(stump);

for i=1:6
    [radacl, learnErr] = learn(radacl, x, y, i);
    fprintf('Error %f\n', learnErr);
    outs = computeOutputs(radacl, x);
    fprintf('Miss classified %d / %d\n', sum(y~=outs) , numPoints);

    c1c = y == 1 & y == outs;
    c1w = y == 1 & y ~= outs;
    c2c = y == 2 & y == outs;
    c2w = y == 2 & y ~= outs;

    subplot(2, 3, i);
    hold on;

    S = getWeights(radacl) * 5000;

    scatter(x1(c1c), x2(c1c),S(c1c),'g','o', 'markerfacecolor','g');
    scatter(x1(c1w), x2(c1w),S(c1w),'r','o', 'markerfacecolor','r');

    scatter(x1(c2c), x2(c2c),S(c2c),'g','+', 'markerfacecolor', 'g');
    scatter(x1(c2w), x2(c2w),S(c2w),'r','+', 'markerfacecolor' ,'r');
    title(['Iteration ' num2str(i)]);

    weakCls = getWeakCls(radacl);
    for j=1:length(weakCls)
        featureInfo = getFeaturesInfo(weakCls{j});
        feature = featureInfo.id;
        splitVal = featureInfo.splitVal;
        limit = r1 + noiseRatio*r1;
        if feature == 1
            line([splitVal splitVal], [-limit, limit]);
        else
            line([-limit, limit], [splitVal splitVal]);
        end
    end

    fprintf('miss Class 1 : %d / %d\n', sum(c1w), sum(c1c+c1w));
    fprintf('miss Class 2 : %d / %d\n', sum(c2w), sum(c2c+c2w));
    fprintf('-----\n');
end
Decision tree for classification
1  if x2<-6.04569 then node 2 elseif x2>=-6.04569 then node 3 else 1
2  class = 1
3  class = 2

Error 0.336667
Miss classified 101 / 300
miss Class 1 : 101 / 150
miss Class 2 : 0 / 150
-----

Decision tree for classification
1  if x2<6.40362 then node 2 elseif x2>=6.40362 then node 3 else 1
2  class = 2
3  class = 1

Error 0.190000
Miss classified 57 / 300
miss Class 1 : 57 / 150
miss Class 2 : 0 / 150
-----

Decision tree for classification
1  if x1<-6.14235 then node 2 elseif x1>=-6.14235 then node 3 else 1
2  class = 1
3  class = 2

Error 0.093333
Miss classified 28 / 300
miss Class 1 : 27 / 150
miss Class 2 : 1 / 150
-----

Decision tree for classification
1  if x1<6.2157 then node 2 elseif x1>=6.2157 then node 3 else 1
2  class = 2
3  class = 1

Error 0.013333
Miss classified 4 / 300
miss Class 1 : 3 / 150
miss Class 2 : 1 / 150
-----

Decision tree for classification
1  if x1<-3.96712 then node 2 elseif x1>=-3.96712 then node 3 else 1
2  class = 1
3  class = 2

Error 0.013333
Miss classified 4 / 300
miss Class 1 : 3 / 150
miss Class 2 : 1 / 150
-----

Decision tree for classification
1  if x2<4.54589 then node 2 elseif x2>=4.54589 then node 3 else 1
2  class = 2
3  class = 1

Error 0.006667
Miss classified 2 / 300
miss Class 1 : 1 / 150
miss Class 2 : 1 / 150
-----