0001
0002
0003
0004
0005
0006 numPoints = 300;
0007 r1 = 10;
0008 r2 = 5;
0009 noiseRatio = 0.3;
0010
0011 nc1x1 = r1 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
0012 nc1x2 = r1 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
0013
0014 nc2x1 = r2 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
0015 nc2x2 = r2 * (2 * noiseRatio * rand(numPoints/2,1) - noiseRatio);
0016
0017
0018 angs1 = 2*pi*rand(numPoints/2, 1);
0019 angs2 = 2*pi*rand(numPoints/2, 1);
0020
0021 x1 = [r1 * cos(angs1) + nc1x1; r2 * cos(angs2) + nc2x1];
0022 x2 = [r1 * sin(angs1) + nc1x2; r2 * sin(angs2) + nc2x2];
0023 x = [x1 x2];
0024 y = [ones(numPoints/2,1) ; 2*ones(numPoints/2,1)];
0025 c1 = y == 1;
0026 c2 = y == 2;
0027
0028 figure(1);
0029 clf;
0030 hold on;
0031 scatter(x1(c1), x2(c1),'b','o' ,'markerfacecolor','blue');
0032 scatter(x1(c2), x2(c2),'b','+','markerfacecolor','blue');
0033 title('Original');
0034
0035 numClasses = 2;
0036
0037
0038
0039
0040 hFig = figure(2);
0041 clf;
0042 set(hFig, 'Position', [100 100 900 900])
0043
0044 stump = BestDecisionStumpClassifier(numClasses);
0045 radacl = RealAdaBooster(stump);
0046
0047 for i=1:6
0048 [radacl, learnErr] = learn(radacl, x, y, i);
0049 fprintf('Error %f\n', learnErr);
0050 outs = computeOutputs(radacl, x);
0051 fprintf('Miss classified %d / %d\n', sum(y~=outs) , numPoints);
0052
0053 c1c = y == 1 & y == outs;
0054 c1w = y == 1 & y ~= outs;
0055 c2c = y == 2 & y == outs;
0056 c2w = y == 2 & y ~= outs;
0057
0058 subplot(2, 3, i);
0059 hold on;
0060
0061 S = getWeights(radacl) * 5000;
0062
0063 scatter(x1(c1c), x2(c1c),S(c1c),'g','o', 'markerfacecolor','g');
0064 scatter(x1(c1w), x2(c1w),S(c1w),'r','o', 'markerfacecolor','r');
0065
0066 scatter(x1(c2c), x2(c2c),S(c2c),'g','+', 'markerfacecolor', 'g');
0067 scatter(x1(c2w), x2(c2w),S(c2w),'r','+', 'markerfacecolor' ,'r');
0068 title(['Iteration ' num2str(i)]);
0069
0070 weakCls = getWeakCls(radacl);
0071 for j=1:length(weakCls)
0072 featureInfo = getFeaturesInfo(weakCls{j});
0073 feature = featureInfo.id;
0074 splitVal = featureInfo.splitVal;
0075 limit = r1 + noiseRatio*r1;
0076 if feature == 1
0077 line([splitVal splitVal], [-limit, limit]);
0078 else
0079 line([-limit, limit], [splitVal splitVal]);
0080 end
0081 end
0082
0083 fprintf('miss Class 1 : %d / %d\n', sum(c1w), sum(c1c+c1w));
0084 fprintf('miss Class 2 : %d / %d\n', sum(c2w), sum(c2c+c2w));
0085 fprintf('-----\n');
0086 end