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