clear

%% load training data set
% load('NLD_4training_polar_01_log_mvm_c1_05.mat');
% load('NLD_4training_minmax_c1_05.mat');
% load('NLD_4training_polar_01_c1_05.mat');
% load('NLD_4training_polar_01_mvm_c1_05.mat');
load('NLD_4training_polar_01_log_c1_05.mat');
      
%% Setup layers
inputSize = 1;
numClasses = numel(unique(target));
miniBatchSize = 32;

filterSize = 20;
numFilters = 32;

layers = [ ...
    sequenceInputLayer(inputSize)
    convolution1dLayer(filterSize, numFilters, Padding="causal")
    reluLayer
    layerNormalizationLayer
    convolution1dLayer(filterSize, 2*numFilters, Padding="causal")
    reluLayer
    layerNormalizationLayer
    globalAveragePooling1dLayer
    fullyConnectedLayer(numClasses)
    softmaxLayer
    classificationLayer];

maxEpochs = 50;
initialLearnRate = 0.001;

options = trainingOptions("adam", ...
    MiniBatchSize = miniBatchSize, ...
    MaxEpochs = maxEpochs, ...
    SequencePaddingDirection = "left", ...
    InitialLearnRate = initialLearnRate, ...
    Plots="training-progress", ...
    Verbose=0);

%% train network
net = trainNetwork(rho, target, layers, options);

%% save the network
clear("rho");
% save NLD_network_polar_01_log_mvm_c1_05.mat
% save NLD_network_minmax_c1_05.mat
% save NLD_network_polar_01_c1_05.mat
% save NLD_network_polar_01_mvm_c1_05.mat
save NLD_network_polar_01_log_c1_05.mat


