
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Define Network Architecture 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
layers = [ ...
    imageInputLayer([8 8 1])
    convolution2dLayer(5,20)
    batchNormalizationLayer
    reluLayer % examplePreluLayer(20)  % instead of: reluLayer
    fullyConnectedLayer(10)
    softmaxLayer
    classificationLayer];

%% Specify training/validation options
options = trainingOptions('adam','MaxEpochs',10, ...
    'ValidationData',{va_data,va_lbls}, ... % imds_valid, ...
    'ValidationFrequency',30, ...
    'Verbose',false, ...
    'Plots','training-progress');

%% Train the network
%net = trainNetwork(imds_train,layers,options);
net = trainNetwork(tr_data,tr_lbls,layers,options);

%% Predict the labels of new data and calculate the classification accuracy.
YPred = classify(net,te_data); % imds_test);
Ytest = te_lbls;  % imds_test.Labels;
accuracy = sum(YPred == Ytest)/numel(Ytest)
