function classvisual2d(testOut, testClasses, trueClasses, prototypes, ...
		       trainOut, trainClasses, trainTargetClasses, ...
		       classnames)
% Visualizes an MLP classifier output. Assumes current graphic handle;
% earlier content will be erased. (Old function; likely to be replaced
% with something more universally usable.).
%
% testOut - the MLP output
%
% testClasses - integer coded class estimates
%
% trueClasses - integer coded true classes
%
% prototypes - the class prototypes corresponding to the integer.
%
% (and the same for training data; to be optional)

clf;
pause(0.15);   % for some mystical reason, real time updated
               % animations don't show the picture at all if a pause
               % is not present..
axis square;

hold on;

legstr = '';

nclasses = size(prototypes,2);

% find subsets of interest. The indices shall point to tx for
% training and subx for verification datas:

% trainInclass{ic}: indices of training pairs whose target was
% class ic
for ic = 1:nclasses
  testInClass{ic} = find(testClasses==ic);
  trueInClass{ic} = find(trueClasses==ic);
  trainInClass{ic} = find(trainClasses==ic);
  trainTargetInClass{ic} = find(trainTargetClasses==ic);

%  testFailedForClass{ic} = find(testClasses ~= trueClasses);
%  conglom = [conglom test_failed{ic}];
end
conglom = find(testClasses ~= trueClasses);

% Plot the outputs for both train and test data:
mstr={'g+','r+','b+','k+','c+'};
for ic = 1:nclasses
  plot([trainOut(1,trainInClass{ic}), testOut(1,trueInClass{ic})], ...
       [trainOut(2,trainInClass{ic}), testOut(2,trueInClass{ic})], ...
       mstr{ic}, 'markersize', 8);
  legstr{length(legstr)+1} = classnames{ic};
end

% Re-plot differently the outputs for test data:
mstr={'g^ ','r^','b^','k^','c^'};
for ic = 1:nclasses
  plot(testOut(1,testInClass{ic}), ...
        testOut(2,testInClass{ic}), ...
        mstr{ic}, 'markersize', 6);
  if length(testInClass{ic})>0
      legstr{length(legstr)+1} = ['predict ' classnames{ic}];
  end
end

% Hilight wrong classifications of the test data:
plot(testOut(1,conglom), ...
      testOut(2,conglom), ...
      'kx', 'markersize', 14);
if length(conglom)>0
    legstr{length(legstr)+1} = 'Wrong';
end

% Plot and annotate the "pure" class centers:

%for ic = 1:nclasses
  plot(prototypes(1,:), prototypes(2,:), ...
        'ko', 'markersize', 12);
legstr{length(legstr)+1} = 'Class Coding';

% Legend box as collected above:
legend(legstr);
