function resl = visualize_hidden_2d_internal(net, line_style)
% Plot the direction of each logsig function that takes place on
% the hidden layer of a 2-m-n neural network. The visualization
% takes place in input space.


%% Verify we got a compatible network from the population:
assert((numel(net.nneur) == 3) && (net.nneur(1) == 2), ...
       'This visualization only works for 2-m-n MLPs.');

for ineur = 1:size(net.W{1},1)
  bias = net.W{1}(ineur,1);
  pdir = net.W{1}(ineur,2:3);
  pdirn = pdir / (pdir * pdir');
  loc = pdirn * (-bias);

  % Length as line width:
  hidl = pdir * pdir';

  % How much effect does this neuron have on the output layer:
  oact = net.W{2}(:,1+ineur); % column of W_2 corresp. to this neuron
  outl = norm(oact);        % just take the norm.

  lw = sqrt(hidl + outl);

  % Direction along the straight decision boundary:
  bd = cross([pdir, 0],[0,0,1]);
  bd = bd / norm(bd) / 4;
  
  % Plot part of the boundary line starting from "loc"
  plot([loc(1),loc(1)+bd(1)],[loc(2),loc(2)+bd(2)],line_style, ...
       'LineWidth',1);
  resl = plot([loc(1),loc(1)-bd(1)],[loc(2),loc(2)-bd(2)],line_style, ...
       'LineWidth',1);

  % Direction plot with length 0.125:
  pdir = pdir / sqrt((pdir * pdir')) / 8;

  dpls = [line_style(1) '-'];
  
  % use single-point quiver:
  quiver(loc(1), loc(2), pdir(1), pdir(2), dpls, 'LineWidth', lw);

%  plot([loc(1),loc(1)+pdir(1)],[loc(2),loc(2)+pdir(2)],dpls, ...
%       'LineWidth',lw);
end
