Data handling in LSTM custom loops

5 ビュー (過去 30 日間)
Shubham Baisthakur
Shubham Baisthakur 2023 年 11 月 16 日
回答済み: Sai Pavan 2023 年 11 月 27 日
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.

採用された回答

Sai Pavan
Sai Pavan 2023 年 11 月 27 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCustom Training Loops についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by