about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/examples/static/HME/hme_class_plot.m
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/BNT/examples/static/HME/hme_class_plot.m
parent7cc31810d53176e805532b2789955f4eedbce6bb (diff)
downloadBNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning.

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