wolffd@0: function fh=hme_class_plot(net, nodes_info, train_data, test_data) wolffd@0: % wolffd@0: % Use this function ONLY when the input dimension is 2 wolffd@0: % and the problem is a classification one. wolffd@0: % We assume that each row of 'train_data' & 'test_data' is an example. wolffd@0: % wolffd@0: %------Line Spec------------------------------------------------------------------------ wolffd@0: % wolffd@0: % LineWidth - specifies the width (in points) of the line wolffd@0: % MarkerEdgeColor - specifies the color of the marker or the edge color wolffd@0: % forfilled markers (circle, square, diamond, pentagram, hexagram, and the wolffd@0: % four triangles). wolffd@0: % MarkerFaceColor - specifies the color of the face of filled markers. wolffd@0: % MarkerSize - specifies the size of the marker in points. wolffd@0: % wolffd@0: % Example wolffd@0: % ------- wolffd@0: % plot(t,sin(2*t),'-mo',... wolffd@0: % 'LineWidth',2,... wolffd@0: % 'MarkerEdgeColor','k',... % 'k'=black wolffd@0: % 'MarkerFaceColor',[.49 1 .63],... % RGB color wolffd@0: % 'MarkerSize',12) wolffd@0: %---------------------------------------------------------------------------------------- wolffd@0: wolffd@0: class_num=nodes_info(2,end); wolffd@0: mn_x = round(min(train_data(:,1))); mx_x = round(max(train_data(:,1))); wolffd@0: mn_y = round(min(train_data(:,2))); mx_y = round(max(train_data(:,2))); wolffd@0: if nargin==4, wolffd@0: mn_x = round(min([train_data(:,1); test_data(:,1)])); wolffd@0: mx_x = round(max([train_data(:,1); test_data(:,1)])); wolffd@0: mn_y = round(min([train_data(:,2); test_data(:,2)])); wolffd@0: mx_y = round(max([train_data(:,1); test_data(:,2)])); wolffd@0: end wolffd@0: x = mn_x(1)-1:0.2:mx_x(1)+1; wolffd@0: y = mn_y(1)-1:0.2:mx_y(1)+1; wolffd@0: [X, Y] = meshgrid(x,y); wolffd@0: X = X(:); wolffd@0: Y = Y(:); wolffd@0: num_g=size(X,1); wolffd@0: griglia = [X Y]; wolffd@0: rand('state',1); wolffd@0: if class_num<=6, wolffd@0: colors=['r'; 'g'; 'b'; 'c'; 'm'; 'y']; wolffd@0: else wolffd@0: colors=rand(class_num, 3); % each row is an RGB color wolffd@0: end wolffd@0: fh = figure('Name','Data & decision boundaries', 'MenuBar', 'none', 'NumberTitle', 'off'); wolffd@0: ms=5; % Marker Size wolffd@0: if nargin==4, wolffd@0: % ms=4; % Marker Size wolffd@0: subplot(1,2,1); wolffd@0: end wolffd@0: % Plot of train_set ------------------------------------------------------------------------- wolffd@0: axis([mn_x-1 mx_x+1 mn_y-1 mx_y+1]); wolffd@0: set(gca, 'Box', 'on'); wolffd@0: c_max_train = max(train_data(:,3)); wolffd@0: hold on wolffd@0: for m=1:c_max_train, wolffd@0: app_x=train_data(:,1); wolffd@0: app_y=train_data(:,2); wolffd@0: thisX=app_x(train_data(:,3)==m); wolffd@0: thisY=app_y(train_data(:,3)==m); wolffd@0: if class_num<=6, wolffd@0: str_col=[]; wolffd@0: str_col=['o', colors(m,:)]; wolffd@0: plot(thisX, thisY, str_col, 'MarkerSize', ms); wolffd@0: else wolffd@0: plot(thisX, thisY, 'o',... wolffd@0: 'LineWidth', 1,... wolffd@0: 'MarkerEdgeColor', colors(m,:), 'MarkerSize', ms) wolffd@0: end wolffd@0: end wolffd@0: %---hmefwd_generale(net,data,ndata)----------------------------------------------------------- wolffd@0: Z=fhme(net, nodes_info, griglia, num_g); % forward propagation trougth the HME wolffd@0: %--------------------------------------------------------------------------------------------- wolffd@0: [foo , class] = max(Z'); % 0/1 loss function => we assume that the true class is the one with the wolffd@0: % maximum posterior prob. wolffd@0: class = class'; wolffd@0: for m = 1:class_num, wolffd@0: thisX=[]; thisY=[]; wolffd@0: thisX = X(class == m); wolffd@0: thisY = Y(class == m); wolffd@0: if class_num<=6, wolffd@0: str_col=[]; wolffd@0: str_col=['d', colors(m,:)]; wolffd@0: h=plot(thisX, thisY, str_col); wolffd@0: else wolffd@0: h = plot(thisX, thisY, 'd',... wolffd@0: 'MarkerEdgeColor',colors(m,:),... wolffd@0: 'MarkerFaceColor','w'); wolffd@0: end wolffd@0: set(h, 'MarkerSize', 4); wolffd@0: end wolffd@0: title('Training set and Decision Boundaries (0/1 loss)') wolffd@0: hold off wolffd@0: wolffd@0: % Plot of test_set -------------------------------------------------------------------------- wolffd@0: if nargin==4, wolffd@0: subplot(1,2,2); wolffd@0: axis([mn_x-1 mx_x+1 mn_y-1 mx_y+1]); wolffd@0: set(gca, 'Box', 'on'); wolffd@0: hold on wolffd@0: if size(test_data,2)==3, % we know the classification of the test set examples wolffd@0: c_max_test = max(test_data(:,3)); wolffd@0: for m=1:c_max_test, wolffd@0: app_x=test_data(:,1); wolffd@0: app_y=test_data(:,2); wolffd@0: thisX=app_x(test_data(:,3)==m); wolffd@0: thisY=app_y(test_data(:,3)==m); wolffd@0: if class_num<=6, wolffd@0: str_col=[]; wolffd@0: str_col=['o', colors(m,:)]; wolffd@0: plot(thisX, thisY, str_col, 'MarkerSize', ms); wolffd@0: else wolffd@0: plot(thisX, thisY, 'o',... wolffd@0: 'LineWidth', 1,... wolffd@0: 'MarkerEdgeColor', colors(m,:),... wolffd@0: 'MarkerSize',ms); wolffd@0: end wolffd@0: end wolffd@0: else wolffd@0: plot(test_data(:,1), test_data(:,2), 'ko',... wolffd@0: 'MarkerSize', ms); wolffd@0: end wolffd@0: for m = 1:class_num, wolffd@0: thisX=[]; thisY=[]; wolffd@0: thisX = X(class == m); wolffd@0: thisY = Y(class == m); wolffd@0: if class_num<=6, wolffd@0: str_col=[]; wolffd@0: str_col=['d', colors(m,:)]; wolffd@0: h=plot(thisX, thisY, str_col); wolffd@0: else wolffd@0: h = plot(thisX, thisY, 'd',... wolffd@0: 'MarkerEdgeColor', colors(m,:),... wolffd@0: 'MarkerFaceColor','w'); wolffd@0: end wolffd@0: set(h, 'MarkerSize', 4); wolffd@0: end wolffd@0: title('Test set and Decision Boundaries (0/1 loss)') wolffd@0: hold off wolffd@0: end