%
% Setup Initial parameters
%
InitParams;

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

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


%
% Test for SorgL for pattern P(:,:,1:100)
% 
Aref = A{LH};
Bref = B{LH};
A{LH} = {};
B{LH} = [];
Newmap = [];

for t=1:100
  cat = int32( mod( t-1, 10 ) );
  Ug = OnOff( P(:,:,t) );

  display_layer( Ug, 2, 1 );

  for l=1:LH-1
    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
  [ A{LH} B{LH} Newmap ] = SorgL( UsSize(LH), Uc{LH-1}, A{LH}, B{LH}, C{LH}, cat, Newmap, Thl(LH) );

  Us{LH} = Sres( UsSize( LH ), Uc{LH-1}, A{LH}, B{LH}, C{LH}, Thr(LH) );
  display_layer( Us{LH}, 8, 2 );
end


