function C = classifyfixpt(fS,P,fP);
% C = classifyfixpt(fS,P,fP);
%
%  Classify a fixed point as either correct, confused, or
%  spurious. 
%
%  C is the category of the fixed point, which can be
%  any of
%           C(1) = 1:  fixed point is correct
%           C(2) = 1:  fixed point is confused
%           C(3) = 1:  fixed point is spurious
%  with all other values zero.
%
%  fS = f(S)
%  P is the matrix of stored patterns P(:,k)=P_k
%  fP is the matrix of f(P(:,k))=f(P_k)
  
  C = zeros(1,3);
  
  % Make sure that the vector is actually -1's or 1's.
  fS = round(fS);
  fP = round(fP);
  
  % What we want to do is subtract f(S) from all of P and
  % f(P). To make our life easier, we make a matrix the
  % size of P whose columns are f(S).
  fS = repmat(fS,[1 length(P(1,:))]);
  
  % Since sign is not preserved, when we do the
  % subtraction, we need to look for either a zero sum or
  % the maximum possible sum.
  maxsum = 2*length(fS);
  
  % Summing gives us a row vector with the sums of the
  % individual f(S)-P_k; take abs value to get rid of
  % sign.  Then find all places where the sum was either
  % zero or the maxsum.
  isCorrect = sum(abs(fS-P));
  isCorrect = find((isCorrect == 0) | (isCorrect == maxsum));
  isConfused = sum(abs(fS-fP));
  isConfused = find((isConfused == 0) | (isConfused == ...
					 maxsum));
  
  
  if ~isempty(isCorrect);
    C(1) = 1;
  elseif ~isempty(isConfused)
    % Make sure this is a unique match.
    if (length(isConfused) == 1)
      C(2) = 1;
    else
      % More than one f(P) matched f(S), so this is a
      % spurious state
      C(3) = 1;
    end
  else
    C(3) = 1;
  end
  

