function [net,ac,res,am] = CENN_driver(num_trials,show,num_samps,scaled)
% CENN_driver - compares performance of matched kernels to learned weights
% On input:
%     num_trials (int): number of times to learn new classifier with
%                       matched kernels
%     show (Boolean): 1 show plots of net training; else not
%     num_samps (int): number of sample images to train with
% On output:
%     net (Matlab net struct): base line digit classifier
%     ac (float): accurcy of baseline classifier
%     res (result struct):
%       (k).netb (Matlab net struct): new classifier using matched kernels
%       (k).ab (float): accuracy of new classifier
%       (k).indexes (4x1 vector): indexes of matched kernels
%       (k).errs (4x1 vector): match error for each kernel
% Call:
%     [net100,ac100,res100,am100] = CENN_driver(10,0,100);
% Author:
%     T. Henderson
%     UU
%     Spring 2025
%

acc = zeros(num_trials,1);
am = 0;

% Get kernels
kernels = IAS_create_kernels(5);

% Get baseline net for digit recognition
rng('default');
[net,ac,Val] = IAS_CNN_digits(5,show,num_samps);

% Run trials matching kernel
rng('default');
for t = 1:num_trials
    [t num_trials]
    [netb,ab,vb,indexes,errs] = IAS_CNN_digits_best_kernel(net,5,...
        kernels,show,num_samps,scaled);
    res(t).netb = net;
    res(t).ab = ab;
    res(t).indexes = indexes;
    res(t).errs = errs;
    acc(t) = ab;
end

am = mean(acc);
