Hi Caio ,
To address your query regarding, “However, due to the nature of the for loop, training is performed at the same rate as the number of epochs defined. I would therefore like to know if there is a function that allows me, for example, to obtain the array of execution data.The motivation is that I would like to use this data for another project.”
Please see my response to your comments below.
I enhanced your existing code which involves modifying the training process to capture RMSE values at each epoch and then use MATLAB's built-in functions to export the data to an Excel file. So, first adjust the training loop so that RMSE values are calculated after each epoch which can be done by utilizing the trainNetwork function's output, which provides information about the training process. Then, define a function to calculate RMSE, which will be called after each epoch. Finally, use the writetable function to export the RMSE values to an Excel file. Here is example code snippet that incorporated all these steps.
% Sample Data
numEpochs = 10; % Define the number of epochs
XTrain = rand(100, 10); % Example training data (100 samples, 10 features)
YTrain = rand(100, 1); % Example target data (100 samples)
% Define your neural network layers and training options
layers = [ ...
featureInputLayer(10)
fullyConnectedLayer(1)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs', numEpochs, ...
'Verbose', 0, ...
'Plots', 'none');
% Initialize RMSE values array
rmseValues = zeros(numEpochs, 1);
% Training loop
for epoch = 1:numEpochs
% Train the network
[net, info] = trainNetwork(XTrain, YTrain, layers, options);
% Predict using the trained network
YPred = predict(net, XTrain);
% Calculate RMSE
rmseValues(epoch) = calculateRMSE(YTrain, YPred);
end
% Create a table for RMSE values
rmseTable = array2table(rmseValues, 'VariableNames', {'RMSE'});
% Display the RMSE table
disp(rmseTable);
% Export RMSE values to an Excel file
writetable(rmseTable, 'RMSE_Values.xlsx');
% Function to calculate RMSE
function rmse = calculateRMSE(actual, predicted)
rmse = sqrt(mean((actual - predicted).^2));
end
Please see attached results.
So, as you can see in the example code, I created random sample data for training. You should replace this with your actual dataset.The neural network is defined with a simple architecture suitable for regression tasks and the training options are set, including the optimizer and the maximum number of epochs. After each epoch, the predicted values are compared to the actual values to compute the RMSE using the calculateRMSE function and stored in a table. Afterwards, they are exported to an Excel file named RMSE_Values.xlsx. By following the provided code and explanations, you should be able to adapt it to your specific project needs. If you have any further questions or require additional modifications, feel free to ask!