function cl_pattern(pattern, i, fig)
% cl_patt.m: symbolic graphical visualisation of classification pattern
%
% pattern: classification pattern
% i: counter
% fig: no. of figure

figure(fig);
clf; % clear figure
cla; % clear axis

% pattern x- and y- sizes
[m,n]= size(pattern);

% frame definition
fx= [0.5 0.5 n+0.5 n+0.5 0.5];
fy= [0.5 m+0.5 m+0.5 0.5 0.5];

% symbol definition step 1
x1= [-0.25 -0.25 +0.25 +0.25 -0.25];
y1= [-0.25 +0.25 +0.25 -0.25 -0.25];

% symbol definition step 2
x2= [x1 +0.25 +0.25 -0.25];
y2= [y1 +0.25 -0.25 +0.25];

% scale classification pattern values to (-2,2)
max_p1= max(max(pattern)); 
max_p2= max(abs(min(pattern))); 
max_p= max(max_p1,max_p2);
clear max_p1; clear max_p2;

pattern= 2/max_p* pattern;

% draw frame in yellow
plot(fx,fy,'y');
title(['classification pattern, epoch= ', num2str(i)]);

axis([0 n+1 0 m+1]);
axis('square'); 
axis('off');
hold;

% plot pattern as scaled symbols in green or red color 
for col= 1:n
    for row= 1:m
        if pattern(row,col)< 0
           plot(x2*pattern(row,col)+col,y2*pattern(row,col)+(m+1-row),'r');
        else
           plot(x2*pattern(row,col)+col,y2*pattern(row,col)+(m+1-row),'g');
        end
	end
end

