Can I train my Narxnet with the different Dimensions size data inside cell arrays?
1 view (last 30 days)
Show older comments
I have 3 Different data set with different dimension. For example Data1 size - (15440x4 double), Data2-(2131x4 double), Data3-(14319x4 double). I have use IDdata object and merge IDdata object to combine 3 data set as a Train_ID. I am extracting the Input data and Output data using this from Train_ID. I have 3 Input and 1 output to train my model.
X_Train = Train_ID.u;
X_Train size (1x3 cell) as i mention with different dimension inside as a (15440x3 double 2131x3 double 14319x3 double)
Y_Train = Train_ID.y;
Y_Train size (1x3 cell) as i mention with different dimension inside as a (15440x1 double 2131x1 double 14319x1 double)
I want to train my network using X_Train and Y_Train for my NarxModel.
trainFcn = 'trainbr'
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 5;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
[x,xi,ai,t] = preparets(net,X_Train,{},Y_Train);
It is showing error in preparets function as follow:
Inputs{1,2} and Inputs{1,1} have different numbers of rows.
How can i train my model with different dimention data as a input ?
If this approch is not correct. i would be also happy to get any other way and suggestion.
0 Comments
Accepted Answer
Neha
on 10 Apr 2024
Hi Hemant,
I understand that you want to train a NARX network with data of different dimensions.
The error you're encountering with the 'preparets' function is due to the fact that 'preparets' expects the input and target data to have the same sequence length when they are presented as cell arrays. Each cell in the input and target arrays should correspond to a separate sequence (or time series), but all sequences within each array must have the same length. This is not the case with your data, as you have sequences of different lengths.
Instead of trying to train on all data at once, you can loop through each sequence, prepare it using 'preparets', and then perform training on that sequence. This method allows you to accommodate the varying lengths of your sequences by preparing and training them one at a time. Please refer to the following code snippet to implement this approach:
for i = 1:length(X_Train)
% Convert data format for preparets
inputs = con2seq(X_Train{i}');
targets = con2seq(Y_Train{i}');
% Prepare the data for the i-th sequence
[x, xi, ai, t] = preparets(net, inputs, {}, targets);
[net, tr] = train(net, x, t, xi, ai);
end
You can refer to the following documentation link for more information on the 'con2seq' function used in the above code snippet:
Hope this helps!
More Answers (0)
See Also
Categories
Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!