Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/HME/hme_class_plot.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function fh=hme_class_plot(net, nodes_info, train_data, test_data) | |
2 % | |
3 % Use this function ONLY when the input dimension is 2 | |
4 % and the problem is a classification one. | |
5 % We assume that each row of 'train_data' & 'test_data' is an example. | |
6 % | |
7 %------Line Spec------------------------------------------------------------------------ | |
8 % | |
9 % LineWidth - specifies the width (in points) of the line | |
10 % MarkerEdgeColor - specifies the color of the marker or the edge color | |
11 % forfilled markers (circle, square, diamond, pentagram, hexagram, and the | |
12 % four triangles). | |
13 % MarkerFaceColor - specifies the color of the face of filled markers. | |
14 % MarkerSize - specifies the size of the marker in points. | |
15 % | |
16 % Example | |
17 % ------- | |
18 % plot(t,sin(2*t),'-mo',... | |
19 % 'LineWidth',2,... | |
20 % 'MarkerEdgeColor','k',... % 'k'=black | |
21 % 'MarkerFaceColor',[.49 1 .63],... % RGB color | |
22 % 'MarkerSize',12) | |
23 %---------------------------------------------------------------------------------------- | |
24 | |
25 class_num=nodes_info(2,end); | |
26 mn_x = round(min(train_data(:,1))); mx_x = round(max(train_data(:,1))); | |
27 mn_y = round(min(train_data(:,2))); mx_y = round(max(train_data(:,2))); | |
28 if nargin==4, | |
29 mn_x = round(min([train_data(:,1); test_data(:,1)])); | |
30 mx_x = round(max([train_data(:,1); test_data(:,1)])); | |
31 mn_y = round(min([train_data(:,2); test_data(:,2)])); | |
32 mx_y = round(max([train_data(:,1); test_data(:,2)])); | |
33 end | |
34 x = mn_x(1)-1:0.2:mx_x(1)+1; | |
35 y = mn_y(1)-1:0.2:mx_y(1)+1; | |
36 [X, Y] = meshgrid(x,y); | |
37 X = X(:); | |
38 Y = Y(:); | |
39 num_g=size(X,1); | |
40 griglia = [X Y]; | |
41 rand('state',1); | |
42 if class_num<=6, | |
43 colors=['r'; 'g'; 'b'; 'c'; 'm'; 'y']; | |
44 else | |
45 colors=rand(class_num, 3); % each row is an RGB color | |
46 end | |
47 fh = figure('Name','Data & decision boundaries', 'MenuBar', 'none', 'NumberTitle', 'off'); | |
48 ms=5; % Marker Size | |
49 if nargin==4, | |
50 % ms=4; % Marker Size | |
51 subplot(1,2,1); | |
52 end | |
53 % Plot of train_set ------------------------------------------------------------------------- | |
54 axis([mn_x-1 mx_x+1 mn_y-1 mx_y+1]); | |
55 set(gca, 'Box', 'on'); | |
56 c_max_train = max(train_data(:,3)); | |
57 hold on | |
58 for m=1:c_max_train, | |
59 app_x=train_data(:,1); | |
60 app_y=train_data(:,2); | |
61 thisX=app_x(train_data(:,3)==m); | |
62 thisY=app_y(train_data(:,3)==m); | |
63 if class_num<=6, | |
64 str_col=[]; | |
65 str_col=['o', colors(m,:)]; | |
66 plot(thisX, thisY, str_col, 'MarkerSize', ms); | |
67 else | |
68 plot(thisX, thisY, 'o',... | |
69 'LineWidth', 1,... | |
70 'MarkerEdgeColor', colors(m,:), 'MarkerSize', ms) | |
71 end | |
72 end | |
73 %---hmefwd_generale(net,data,ndata)----------------------------------------------------------- | |
74 Z=fhme(net, nodes_info, griglia, num_g); % forward propagation trougth the HME | |
75 %--------------------------------------------------------------------------------------------- | |
76 [foo , class] = max(Z'); % 0/1 loss function => we assume that the true class is the one with the | |
77 % maximum posterior prob. | |
78 class = class'; | |
79 for m = 1:class_num, | |
80 thisX=[]; thisY=[]; | |
81 thisX = X(class == m); | |
82 thisY = Y(class == m); | |
83 if class_num<=6, | |
84 str_col=[]; | |
85 str_col=['d', colors(m,:)]; | |
86 h=plot(thisX, thisY, str_col); | |
87 else | |
88 h = plot(thisX, thisY, 'd',... | |
89 'MarkerEdgeColor',colors(m,:),... | |
90 'MarkerFaceColor','w'); | |
91 end | |
92 set(h, 'MarkerSize', 4); | |
93 end | |
94 title('Training set and Decision Boundaries (0/1 loss)') | |
95 hold off | |
96 | |
97 % Plot of test_set -------------------------------------------------------------------------- | |
98 if nargin==4, | |
99 subplot(1,2,2); | |
100 axis([mn_x-1 mx_x+1 mn_y-1 mx_y+1]); | |
101 set(gca, 'Box', 'on'); | |
102 hold on | |
103 if size(test_data,2)==3, % we know the classification of the test set examples | |
104 c_max_test = max(test_data(:,3)); | |
105 for m=1:c_max_test, | |
106 app_x=test_data(:,1); | |
107 app_y=test_data(:,2); | |
108 thisX=app_x(test_data(:,3)==m); | |
109 thisY=app_y(test_data(:,3)==m); | |
110 if class_num<=6, | |
111 str_col=[]; | |
112 str_col=['o', colors(m,:)]; | |
113 plot(thisX, thisY, str_col, 'MarkerSize', ms); | |
114 else | |
115 plot(thisX, thisY, 'o',... | |
116 'LineWidth', 1,... | |
117 'MarkerEdgeColor', colors(m,:),... | |
118 'MarkerSize',ms); | |
119 end | |
120 end | |
121 else | |
122 plot(test_data(:,1), test_data(:,2), 'ko',... | |
123 'MarkerSize', ms); | |
124 end | |
125 for m = 1:class_num, | |
126 thisX=[]; thisY=[]; | |
127 thisX = X(class == m); | |
128 thisY = Y(class == m); | |
129 if class_num<=6, | |
130 str_col=[]; | |
131 str_col=['d', colors(m,:)]; | |
132 h=plot(thisX, thisY, str_col); | |
133 else | |
134 h = plot(thisX, thisY, 'd',... | |
135 'MarkerEdgeColor', colors(m,:),... | |
136 'MarkerFaceColor','w'); | |
137 end | |
138 set(h, 'MarkerSize', 4); | |
139 end | |
140 title('Test set and Decision Boundaries (0/1 loss)') | |
141 hold off | |
142 end |