% % Written by: % -- % John L. Weatherwax 2005-08-04 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % % Epage > 106 % %----- close all; clc; clear; rand('seed',0); randn('seed',0); % the required data: % var_scale = 0.01; nPts = 100; X1 = mvnrnd( [0,1], var_scale*eye(2), nPts ); % blue points X2 = mvnrnd( [-1,-1], var_scale*eye(2), nPts ); % red points X3 = mvnrnd( [+1,-1], var_scale*eye(2), nPts ); % green points h1 = plot( X1(:,1), X1(:,2), '.b' ); hold on; h2 = plot( X2(:,1), X2(:,2), '.r' ); h3 = plot( X3(:,1), X3(:,2), '.g' ); legend( [h1,h2,h3], {'class 1', 'class 2','class 3'} ); axis( 4*[-1,+1,-1,+1] ); % draw the three decision lines w^T x = 0 % title(''); % separate out blue class correctly % x1_grid = linspace( -4, +4, 50 ); w_i = [ -.1, 1, -0.25 ]; x2_db = ( -w_i(3) - w_i(1) * x1_grid ) / w_i(2); plot( x1_grid, x2_db, '-b' ); text( -3.5, 0.25, 'g_1(x)=0' ); text( 3.7, .8, '+' ); text( 3.7, 0.5, '-' ); % separate out red class correctly % w_i = [ 1, 1, 1 ]; x2_db = ( -w_i(3) - w_i(1) * x1_grid ) / w_i(2); plot( x1_grid, x2_db, '-r' ); text( -3.5, 2.75, 'g_2(x)=0' ); text( 2.4, -3.6, '+' ); text( 2.8, -3.6, '-' ); % separate out green class correctly % w_i = [ -20.0, 1., 10 ]; x2_db = ( -w_i(3) - w_i(1) * x1_grid ) / w_i(2); plot( x1_grid, x2_db, '-g' ); text( -0.5, -3.75, 'g_3(x)=0' ); text( 0.75, 3.6, '+' ); text( 0.45, 3.6, '-' ); text( -3.5, 1.5, '(+,+,-)' ); text( -1.5, 3, '(+,-,-)' ); text( 2.5, 2, '(+,-,+)' ); text( -3.5, -3, '(-,+,-)' ); text( -.35, -.3, '(-,-,-)' ); text( 3, -2, '(-,-,+)' ); text( 1, -3.5, '(-,+,+)' ); fn = ['chap_3_prob_15_class_regions.eps']; saveas(gcf,['../../WriteUp/Graphics/Chapter3/',fn],'epsc');