function plotcut(neurons,nid, CID)
%	example usage
% 		plotcut(neurons,7,Class_index_training)
%	CID class id
%	neuron id
global ...
   unary_kernels ...
   binary_kernels ...
   operand_size ...
%	CID class ID
%	nid neuron ID
th=neurons{nid}.threshold;
b=cat(1,neurons{nid}.features{:});
lset=[];
for i=1:size(b,1)
   lset=[lset; neurons{b(i)}.out{:}];
end;
len=size(lset,2)
ck=neurons{nid}.tci;
sz=size(lset);
len=sz(2);
dep=['.b';'.r';'.g';'.y';'*b';'*g';'*r';'ob';'og';'or'];
figure;hold on;
features = neurons{nid}.features;
if length(features)>1 
cc=cat(1,ck{:});
for i=1:len
   if cc(i)>0
      s=dep(CID(i),:);
      if size(lset,1)==2
         plot(lset(1,i),lset(2,i),s);
      elseif size(lset,1)==1
         plot(lset(i),s);
      end;
   end;
end;

xmin=min(lset(1,:));
xmax=max(lset(1,:));
x=[xmin:(xmax-xmin)/250:xmax];

ymin=min(lset(2,:));
ymax=max(lset(2,:));
y=[ymin:(ymax-ymin)/250:ymax];

[X,Y]=meshgrid(x,y);
arg = { X Y };
func = neurons{nid}.func;
%features = neurons{nid}.features;
      for i=1:length(features),
			w=strcat(strcat('arg{',num2str(i)),'}');
         v='cat(2,w)';
         func = strrep(func,strcat('@',num2str(i)),w);
      end
   z = eval(func);
   contour(X,Y,z,[th th]);
   
   
else
   cc=cat(1,ck{:});
   otput_cl_values=cell(1,max(CID));
for i=1:len
   if cc(i)>0
      cidd=CID(i);
      s=dep(cidd,:);
      otput_cl_values{cidd}=[otput_cl_values{cidd} lset(i)]; 
   end;
end;
max(CID);
for i= 1:max(CID)
      cidd=CID(i);
      s=dep(i,:);
      aa=otput_cl_values(1,i);
		bb=cat(1,aa{:});
      if isempty(bb)
         else
         plot(bb,s);
      end;
hold on
end;
plot(th,'gp');

end;


disp('the end');
%	example usage
% plotcut(neurons,7,Class_index_training)

function z = ident(x)
z = x;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% The log_2(x) function works like the conventional log to base 2, but also
%% implicitly contains the additonal rectification nonlinearity - the function
%% is turned on only when the signal x (acting both as an input and a control
%% signal) is larger than the threshold value 1, and turned off otherwise.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function z = log_2(x)
z = log2(max(1,x));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% The exp_2(x) function works like the function 2^x, however it is designed to
%% work within the range of input data, and its output is also confined to
%% within the same range.  If output exceeds the range the most significant
%% bits will be dropped.  The exp_2 function also implicitly assumes
%% rectification nonlinearity so that when input signal falls below certain
%% reference level, inhibition occurs.  Signal above the reference level,
%% on the other hand, excites the function.  The Matlab code below emulates
%% the behavior we just described.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function z = exp_2(x)
global operand_size;
negative_x_mask = x>=0;
z = 2.^x;
z = z.*negative_x_mask;
frac_z = z - floor(z);
z = bitshift(floor(z),0,operand_size);
z = z + frac_z;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% The add(x,y) function works like the conventional function '+', which is
%% linear, except that it's scaled by a factor 1/2 so that the sum of the two
%% input signals is within the dynamic range of B bits (provided inputs are).
%% This function is behaviorally equivalent to linear bidirectional devices of
%% finite gain.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function z = add(x,y)
z = 0.5*(x+y);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% The sub(x,y) function works like the conventional function '-' which is
%% linearly, but implicitly contains the rectification nonlinearity so it
%% behaviorally resembles physical devices like diodes or MOS transistors in
%% diode-connected mode in the linear region.  Conceptually, the sign of (x-y)
%% is a binary control signal which turns off the function when the sign is -ve,
%% on otherwise.  Note that 'sub' is distinct from 'add' we defined above,
%% since they model different devices, the former being nonlinear and the latter
%% linear.  This is clearly not the case for the conventional '-' and '+'
%% functions - one can obtain '-' from '+', or vice versa.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function z = sub(x,y)
z = max(0,x-y);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Various functions that use 'add' and 'sub'
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function z = f1(x,y)
z = add(x,y);

function z = f2(x,y)
z = sub(x,y);

function z = f3(x,y)
z = sub(y,x);

function z = f4(x,y)
z = add(x,y/2);

function z = f5(x,y)
z = add(y,x/2);

function z = f6(x,y)
z = sub(x,y/2);

function z = f7(x,y)
z = sub(y,x/2);




