allTrainData = cell(1, 5);
allTrainLabels = cell(1, 5);
allValidationData = cell(1, 5);
allValidationLabels = cell(1, 5);
allTestData = cell(1, 5);
allTestLabels = cell(1, 5);
trainDataFiles = ["activetrain.csv", "ambienttrain.csv", "generatedtrain.csv", "moduletrain.csv", "radiationtrain.csv"];
trainLabelFiles = ["labeltrainactive.csv", "labeltrainambient.csv", "labeltraingenerated.csv", "labeltrainmodule.csv", "labeltrainradiation.csv"];
for i = 1:5
trainData = load(trainDataFiles(i));
trainLabels = load(trainLabelFiles(i));
allTrainData{i} = trainData;
allTrainLabels{i} = trainLabels;
end
validationDataFiles = ["activevalid.csv", "ambientvalid.csv", "generatedvalid.csv", "modulevalid.csv", "radiationvalid.csv"];
validationLabelFiles = ["labelvalidactive.csv", "labelvalidambient.csv", "labelvalidgenerated.csv", "labelvalidmodule.csv", "labelvalidradiation.csv"];
for i = 1:5
validationData = load(validationDataFiles(i));
validationLabels = load(validationLabelFiles(i));
allValidationData{i} = validationData;
allValidationLabels{i} = validationLabels;
end
testDataFiles = ["activetest.csv", "ambienttest.csv", "generatedtest.csv", "moduletest.csv", "radiationtest.csv"];
testLabelFiles = ["labeltestactive.csv", "labeltestambient.csv", "labeltestgenerated.csv", "labeltestmodule.csv", "labeltestradiation.csv"];
for i = 1:5
testData = load(testDataFiles(i));
testLabels = load(testLabelFiles(i));
allTestData{i} = testData;
allTestLabels{i} = testLabels;
end
inputHeight = 1;
inputWidth = 5;
numChannels = 5;
numTrainSamples = size(allTrainData{i}, 2);
numTestSamples = size(allTestData{i}, 2);
numValidationSamples = size( allValidationData{i}, 2);
XTrain = reshape( allTrainData{i}, inputHeight, inputWidth, numChannels, numTrainSamples);
XTest = reshape( allTestData{i}, inputHeight, inputWidth, numChannels, numTestSamples);
XValidation = reshape( allValidationData{i}, inputHeight, inputWidth, numChannels, numValidationSamples);
XTrain = normalize(XTrain);
XTest = normalize(XTest);
XValidation = normalize(XValidation);
YTrain = categorical(cell2mat(allTrainLabels));
YTest = categorical(cell2mat(allTestLabels));
YValidation = categorical(cell2mat(allValidationLabels));
layers = [
imageInputLayer([1 5 5],"Name","Input","Normalization","zscore")
convolution1dLayer(3,8,"Name","Conv_1","Padding","same")
batchNormalizationLayer("Name","Bnorm")
reluLayer("Name","relu_1")
maxPooling1dLayer(2, "Padding", "same", "Stride", 2)
convolution1dLayer(3,16,"Name","Conv_2","Padding","same")
batchNormalizationLayer("Name","Bnorm_2")
reluLayer("Name","relu_2")
maxPooling1dLayer(2,"Padding","same","Stride",2)
convolution1dLayer(3,32,"Name","Conv_3","Padding","same")
batchNormalizationLayer("Name","Bnorn_3")
reluLayer("Name","relu_3")
maxPooling1dLayer(2,"Padding","same","Stride",2)
convolution2dLayer(3,64,"Name","Conv_4","Padding","same")
batchNormalizationLayer("Name","BNorm_4")
reluLayer("Name","relu_4")
fullyConnectedLayer(8,"Name","FC_1","WeightLearnRateFactor",0.01)
reluLayer("Name","relu_5")
fullyConnectedLayer(2,"Name","FC_2","WeightLearnRateFactor",0.01)
softmaxLayer("Name","Softmax_layer")
classificationLayer("Classes","auto")];
plot(layerGraph(layers));
options = trainingOptions('adam', ...
'InitialLearnRate', 0.01, ...
'MaxEpochs', 5, ...
'MiniBatchSize', 32, ...
'ValidationData', {XValidation, YValidation}, ...
'ValidationFrequency', 10, ...
'Verbose', true, ...
'Plots', 'training-progress');
net = trainNetwork(XTrain, categorical(YTrain), layers, options);
YTestPred = classify(net, XTest);
accuracy = sum(YTestPred == YTest) / numel(YTest);
disp(['Test Accuracy: ', num2str(accuracy)]);