Using LSTM for non-linear system identification

조회 수: 5 (최근 30일)
David Vatavu
David Vatavu 2023년 11월 12일
답변: Gagan Agarwal 2023년 11월 24일
Hello, i need some steps and information to build a neural network lstm for nonlinear system identification. I have already the data set, training set and test set. This is my code, what i need to do more?Please tell me
clear all
clc
load('twotankdata.mat');
output=y;
input=u;
%normalizarea datelor de intrare
min_input = min(input);
max_input = max(input);
x_normalized=(input-min_input)/(max_input-min_input);
min_output=min(output);
max_output=max(output);
y_normalized=(output-min_output)/(max_output-min_output);
x_train=x_normalized(1:2250,:);
x_test=x_normalized(2251:3000,:);
y_train=y_normalized(1:2250,:);
y_test=y_normalized(2251:3000,:);
%Define LSTM Network Arhitecture
model=lstmLayer(100,'OutputMode','sequence','StateActivationFunction','tanh','GateActivationFunction','sigmoid');
numFeatures=size(x_train',2);
inputSize=1;
numHiddenUnits=70;
numClasses=1;
layer=[...
sequenceInputLayer(inputSize)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(numClasses)
%softmaxLayer
regressionLayer
];
options=trainingOptions('adam',...
'ExecutionEnvironment','cpu',...
'MaxEpochs',250,...
'MiniBatchSize',27,...
'GradientThreshold',1,...
'Verbose',false,...
'Plots','training-progress');
net=trainNetwork(x_train',y_train',layer,options);
i have this error: Invalid training data. The output size (1) of the last layer does not match the response size (2250).
  댓글 수: 2
KSSV
KSSV 2023년 11월 13일
You need to attach your input data. Attach the mat file.
David Vatavu
David Vatavu 2023년 11월 13일
Are you sure? What do you think about creating the neural network?

댓글을 달려면 로그인하십시오.

채택된 답변

Gagan Agarwal
Gagan Agarwal 2023년 11월 24일
Hi David,
I understand that you are encountering an error that the output size of last layer does not match with the response size.
To address this issue, it is important to ensure that the output size of the last layer matches the size of your training output data. Please refer to the following approaches to resolve the issue:
  1. Review the dimensions of your training data and the expected output size. There might be inconsistency in dimensions between training data and the expected output size
  2. Verify the architecture of your neural network and the dimensions of each layer, especially the last layer. Ensure that the output size of the last layer matches the expected response size.
I hope it helps!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by