Azzera filtri
Azzera filtri

Can I train my Narxnet with the different Dimensions size data inside cell arrays?

3 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Neha
Neha il 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!
  1 Commento
Hemant
Hemant il 12 Apr 2024
Hi Neha,
Thanks for help. i am able to train with this method , but during training it would update the net in every loop and weight , bias respectively and getting the worse result. i have updated my data and have a same sequence as you above mension that '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. i want to train my model at once without any loop. still i am encoutering another error in preparets function.
X_Train = Train_ID.u;
Y_Train = Train_ID.y;
inputs = con2seq(X_Train');
targets = con2seq(Y_Train');
trainFcn = 'trainbr';
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 5;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
[x,xi,ai,t] = preparets(net,inputs,{},targets);
Error using preparets (line 129)
Feedback and inputs have different numbers of timesteps.
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
% Test the Network
[y,Xf,Af] = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
It would be very helpful for me if you could help me with this Problem. i want to train my network at once without any loop.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Sequence and Numeric Feature Data Workflows in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by