Data handling in LSTM custom loops

6 views (last 30 days)
I have written a custom loop to train an LSTM model for sequence-to-sequence regression. I am passing the training data as a cell array where each cell contains a time history observation from the process I am trying to model. So, the training variable is a cell array with size nObservations x 1. Each cell variable has a size of nFeatures x nTimeSteps where, nFeatures refer to the total number of input features and nTimeSteps is the time duration over which the data is recorded. For this data, how should I format the variables in dlarray?
I am formatting each time history as "CT" but I am not sure if that is correct for using the "mse" function.

Accepted Answer

Sai Pavan
Sai Pavan on 27 Nov 2023
Hi Shubham,
I understand that you want to know the way to format variables in dlarray for training an LSTM model for sequence-to-sequence regression.
To format the cell array data for use with dlarray, you initialize a dlarray with the correct size and then loop through each cell in the cell array to populate the dlarray. Please refer to the below code snippet that illustrates the workflow to format data compatible with dlarray:
% Assuming your cell array is named 'trainingData'
nObservations = size(trainingData, 1);
nFeatures = size(trainingData{1}, 1);
nTimeSteps = size(trainingData{1}, 2);
% Initialize a dlarray
dlTrainingData = dlarray(zeros(nFeatures, nTimeSteps, nObservations));
% Convert the cell array to a dlarray
for i = 1:nObservations
dlTrainingData(:,:,i) = dlarray(trainingData{i});
end
The "CT" format is appropriate for modelling sequence data. However, when using the "mse" function, we need to make sure that the model's output and the ground truth are in the correct format.
Hope it helps.
Regards,
Sai Pavan

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!