function resc = visualize_action_2d_internal(net, contour_line_style)
% Plot decision boundaries in [-2:2]^2, (subset of) the input space of
% a 2D classification task (two inputs, any number of classes; expect
% number of output neurons to match the number of classes; predicted
% class is the output neuron with the highest output value).
%
% Use the provided line style for separating lines. A similar boundary
% will be shown around each class. Call repeatedly with different
% lines to illustrate functional differences between two different
% classifier models.

indim = net.nneur(1);
nclasses = net.nneur(end);
assert ( (indim==2) && (nclasses>1), ...
    ['Can only be used for classification with 2D inputs']);

[x1,x2] = meshgrid(-2:.01:2,-2:.01:2);
d = [ reshape(x1,1,numel(x1)) ; ...
      reshape(x2,1,numel(x2))   ];
d=d';

outp = simple_mlp_evalMSEr(net, d', 'feed');

[dummy, predicted] = max(outp);
for ic=1:nclasses

%  if (nclasses==2)
%    decision = outp(1,:)-outp(2,:); % binary decision variable; smoother.
%  end
  decision = repmat(-1,size(outp,2), 1);
  decision(predicted==ic) = 1;

  dec2d = reshape(decision, size(x1));
  k = [ .1 .1 .1 ; .1 .2 .1; .1 .1 .1 ];
  decision=reshape(conv2(dec2d, k, 'same'), size(decision));

%  decision = outp(1,:)-outp(2,:); % binary decision variable.

  % Quite possibly the decision boundary is outside of the figure area.
  % We'll handle that by inserting a minimal "boundary" in a corner.
  % Not very elegant, but works here.
  if (sum(decision>0)==0 || sum(decision<0)==0)
    decision(1)=1;
    decision(2)=-1;
  end
  
  z =  reshape(decision,size(x1));
  [dummyC, resc] = contour(x1,x2,z,[0.0,0.0], contour_line_style, ...
			   'LineWidth', 2);
  
  [px,py] = gradient(z);
  sel = (abs(z-0.5)<0.02);
  %quiver(x1(sel),x2(sel),px(sel),py(sel), contour_line_style);
end
