function cat = TestNeocog( varargin )
%
% TestNeocog -- Test response using 'PatTest.dat'
%
% Usage:
%    cat = TestNeocog( num )
%
%    cat: answer by the Neocognitron
%    num: Pattern number
%
num = 1;
[ dummy argc ] = size( varargin );
if( argc >= 1 )
  num = varargin{1};
end
if( ( num <= 0 ) || ( num > 400 ) )
  num = 1;
end

%
% Setup Initial parametes
%
InitParams;

%
% Load Input Pattern
%
P = PatLoad( 'PatTest.dat' );


%
% Connections from Uc ---> Us
% Connection named A, B, C
%
for l=1:LH
    [ A{l}, B{l} ] = ReadConnect( 'connect.dat', l-1 );
end
CAT_MAP = ReadCategory( 'connect.dat' );   % Category map in recognition layer


%
% Example for Simulation for pattern P(:,:,num)
% 

Ug = OnOff( P(:,:,num) );

display_layer( Ug, 2, 1 );

for l=1:LH
  if( l == 1 )
    UcPrev = Ug;
  else
    UcPrev = Uc{l-1};
  end
  Us{l} =  Sres( UsSize(l), UcPrev, A{l}, B{l}, C{l}, Thr(l) );
  if( l ~= LH )
    Uc{l} = Cres( UcSize(l), Us{l}, D{l} );
  end
end

display_layer( Uc{1}, 8, 2 );
display_layer( Uc{2}, 13, 3 );
display_layer( Uc{3}, 22, 4 );
display_layer( Us{4}, 20, 5 );

[Ans Uc{LH}] = CresL( Us{LH}, CAT_MAP );

cat = Ans;