function [net,accuracy] = IAS_zero(num_samps)
%

digitDatasetPath = fullfile(matlabroot,"toolbox","nnet","nndemos", ...
    "nndatasets","DigitDataset");
imds = imageDatastore(digitDatasetPath, ...
    IncludeSubfolders=true,LabelSource="foldernames");

% divide into training and validation sets
numTrainFiles = num_samps;
[imdsTrain,imdsTest] = splitEachLabel(imds,...
    0.9,"randomize");

% Augment Data
inputSize = [28 28 1];
pixelRange = [-5 5];

imageAugmenter = imageDataAugmenter(RandXTranslation=pixelRange,...
    RandYTranslation=pixelRange);

augimdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain,...
    DataAugmentation=imageAugmenter);

augimdsTest = augmentedImageDatastore(inputSize(1:2),imdsTest);

% Determine number of classes
classes = categories(imdsTrain.Labels);
numClasses = numel(classes);

% Define the network (wothout output layer)

layers = [
    imageInputLayer(inputSize,Normalization="none")
    convolution2dLayer(5,4,Padding="same")
    batchNormalizationLayer
    reluLayer
    convolution2dLayer(3,4,Padding="same")
    batchNormalizationLayer
    reluLayer
    % convolution2dLayer(3,20,Padding="same")
    % batchNormalizationLayer
    % reluLayer
    fullyConnectedLayer(numClasses)
    softmaxLayer];

% Create network

net = dlnetwork(layers);

% Specify training options

numEpochs = 20;
miniBatchSize = 128;
learnRate = 0.01;

% Train model

mbq = minibatchqueue(augimdsTrain,...
    MiniBatchSize=miniBatchSize,...
    MiniBatchFcn=@preprocessMiniBatch,...
    MiniBatchFormat=["SSCB" ""], ...
    PartialMiniBatch="discard");

numObservationsTrain = numel(imdsTrain.Files);
numIterationsPerEpoch = floor(numObservationsTrain / miniBatchSize);
numIterations = numEpochs * numIterationsPerEpoch;

monitor = trainingProgressMonitor( ...
    Metrics="Loss", ...
    Info="Epoch", ...
    XLabel="Iteration");

epoch = 0;
iteration = 0;

% Loop over epochs.
while epoch < numEpochs && ~monitor.Stop
    
    epoch = epoch + 1;

    % Shuffle data.
    shuffle(mbq);
    
    % Loop over mini-batches.
    while hasdata(mbq) && ~monitor.Stop

        iteration = iteration + 1;
        
        % Read mini-batch of data.
        [X,T] = next(mbq);
        
        % Evaluate the model gradients, state, and loss using dlfeval and the
        % modelLoss function and update the network state.
        [loss,gradients,state] = dlfeval(@modelLoss,net,X,T);
        net.State = state;
        
        % Update the network parameters using SGD.
        updateFcn = @(parameters,gradients) sgdStep(parameters,gradients,learnRate);
        net = dlupdate(updateFcn,net,gradients);
        W = net.Layers(2).Weights;
        W_new = W;
        for k = 1:4
            Wk = IAS_W2K(W,k);
            Wk = Wk - mean(mean(Wk));
            W_new = IAS_K2W(Wk,W_new,k);
        end
        
        % Update the training progress monitor.
        recordMetrics(monitor,iteration,Loss=loss);
        updateInfo(monitor,Epoch=epoch);
        monitor.Progress = 100 * iteration/numIterations;
    end
end

% Test model
imdsValidation = imdsTest;
[Y,L,accuracy] = IAS_predict(net,imdsValidation);
%accuracy = testnet(net,augimdsTest,"accuracy")

% Visualize results

scores = minibatchpredict(net,augimdsTest);
YTest = scores2label(scores,classes);

TTest = imdsTest.Labels;
figure
confusionchart(TTest,YTest)

tch = 0;
