compute_lf=1;
if(compute_lf),
   nstates=6;
   nmodes=3;
   mstd=.3;
  [cm,L1a]=esc_class('ESC8a','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L2a]=esc_class('ESC8a','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L3a]=esc_class('ESC8a','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L1b]=esc_class('ESC8b','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L2b]=esc_class('ESC8b','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L3b]=esc_class('ESC8b','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L1c]=esc_class('ESC8c','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L2c]=esc_class('ESC8c','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L3c]=esc_class('ESC8c','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L1d]=esc_class('ESC8d','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L2d]=esc_class('ESC8d','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
  [cm,L3d]=esc_class('ESC8d','esc4f','mel4',16,2,1,1,nstates,nmodes,mstd);
end;
as=exp([log(1):.1:log(2e6)]); na=length(as);
%pk=load('cnn_scores.mat');
%pk = load('cnn_scores_no-aug+dropout.mat');
pk = load('cnn_scores_with_aug.mat');
parts={'a','b','c','d'};
model='esc4f';
nerr_all=0;
npart=4;
for ipart=1:npart,
  nerr=zeros(na,1);
  for itrial=1:3,
    eval(['lp1=L',num2str(itrial),parts{ipart},';']);
    eval(['lp2=squeeze(pk.ESC8',parts{ipart},'(itrial,:,:));']);
    classes=['ESC8',parts{ipart}];
    fn=[model,'_',classes,'_c1_',classes,'_out2.mat'];
    pfwd=load(fn,'y');
    tch=pfwd.y';
    lp = lp1+1100*lp2';
    ne0=count_err(lp,tch);
    nerr_PBN=count_err(lp1,tch);
    nerr_CNN=count_err(lp2',tch);
    fprintf('Partition %s, trial %d, CNN %d, PBN %d, best comb: %d\n',parts{ipart},itrial,nerr_CNN,nerr_PBN, ne0);
    for ia=1:na, 
        lp=lp1+as(ia)*lp2'; 
        nerr(ia)=nerr(ia)+count_err(lp,tch);
    end;
  end;
  nerr_all=nerr_all+nerr;
  subplot(2,2,ipart);
  set(gca,'fontsize',16);
  semilogx(as,nerr/3,'bo-','linewidth',2); 
  title classes
  grid on
end;
figure
set(gca,'fontsize',16);
semilogx(as,nerr_all/3/npart,'bo-','linewidth',2); 
xlabel('combining factor');
ylabel('Total Errors');
%>> pk
%pk = 
%    ESC8a: [3x80x8 double]
%    ESC8b: [3x80x8 double]
%    ESC8c: [3x80x8 double]
%    ESC8d: [3x80x8 double]
%>> whos L1a
%  Name      Size            Bytes  Class     Attributes
%
%  L1a       8x80             5120  double              
%
%>> 
%
